-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
whitequark
committed
Sep 30, 2016
1 parent
55b2535
commit c6a57d2
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ mod sched; | |
mod config; | ||
mod clock; | ||
mod rtio_crg; | ||
mod mailbox; | ||
|
||
mod logger; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use core::ptr::{read_volatile, write_volatile}; | ||
use board; | ||
|
||
const MAILBOX: *mut u32 = board::mem::MAILBOX_BASE as *mut u32; | ||
static mut last: u32 = 0; | ||
|
||
pub fn send(data: u32) { | ||
unsafe { | ||
last = data; | ||
write_volatile(MAILBOX, data) | ||
} | ||
} | ||
|
||
pub fn acknowledged() -> bool { | ||
unsafe { | ||
let data = read_volatile(MAILBOX); | ||
data == 0 || data != last | ||
} | ||
} | ||
|
||
pub fn send_and_wait(data: u32) { | ||
send(data); | ||
while !acknowledged() {} | ||
} | ||
|
||
pub fn receive() -> u32 { | ||
unsafe { | ||
let data = read_volatile(MAILBOX); | ||
if data == last { | ||
0 | ||
} else { | ||
if data != 0 { | ||
board::flush_cpu_dcache() | ||
} | ||
data | ||
} | ||
} | ||
} | ||
|
||
pub fn wait_and_receive() -> u32 { | ||
loop { | ||
let data = receive(); | ||
if data != 0 { | ||
return data | ||
} | ||
} | ||
} | ||
|
||
pub fn acknowledge() { | ||
unsafe { write_volatile(MAILBOX, 0) } | ||
} |