Skip to content

Commit

Permalink
feat: add MboxChannel enum and use it in mboxCall
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Aug 31, 2024
1 parent 7f49663 commit 4aec962
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions Sources/Kernel/mbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ let mboxResponse: UInt32 = 0x8000_0000
let mboxFull: UInt32 = 0x8000_0000
let mboxEmpty: UInt32 = 0x4000_0000

enum MboxChannel: UInt8 {
case power = 0
case framebuffer
case virtualUART
case vchiq
case leds
case buttons
case touchScreen
case count // TODO: Understand what this is.
case property // ARM -> VC
// case property // VC -> ARM
}

enum MboxTag {
static let end: UInt32 = 0
static let setClockRate: UInt32 = 0x0003_8002
Expand All @@ -26,10 +39,10 @@ private func receiveMboxEmpty() -> Bool {
mmioLoad(mboxStatus) & mboxEmpty > 0
}

func mboxCall(ch: UInt8) -> Bool {
func mboxCall(ch: MboxChannel) -> Bool {
withUnsafePointer(to: &mbox) { ptr in
let addr = UInt32(UInt(bitPattern: ptr))
let r = addr & ~0xF | UInt32(ch & 0xF)
let r = addr & ~0xF | UInt32(ch.rawValue & 0xF)
while transmitMboxFull() {}
mmioStore(r, to: mboxWrite)
repeat {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Kernel/uart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func initUART() {
mbox.6 = 3_000_000 // 3 Mhz
mbox.7 = 0 // clear turbo
mbox.8 = MboxTag.end
guard mboxCall(ch: 8) else { fatalError() }
guard mboxCall(ch: .property) else { fatalError() }
#endif

// map UART0 to GPIO pins
Expand Down

0 comments on commit 4aec962

Please sign in to comment.