forked from M-Labs/artiq
Rust: port mailbox routines.
This commit is contained in:
parent
55b2535477
commit
c6a57d2043
@ -3,6 +3,10 @@ use core::{cmp, ptr, str};
|
||||
include!(concat!(env!("BUILDINC_DIRECTORY"), "/generated/mem.rs"));
|
||||
include!(concat!(env!("BUILDINC_DIRECTORY"), "/generated/csr.rs"));
|
||||
|
||||
extern {
|
||||
pub fn flush_cpu_dcache();
|
||||
}
|
||||
|
||||
pub fn ident(buf: &mut [u8]) -> &str {
|
||||
unsafe {
|
||||
let len = ptr::read_volatile(csr::IDENTIFIER_MEM_BASE);
|
||||
|
@ -16,6 +16,7 @@ mod sched;
|
||||
mod config;
|
||||
mod clock;
|
||||
mod rtio_crg;
|
||||
mod mailbox;
|
||||
|
||||
mod logger;
|
||||
|
||||
|
51
artiq/runtime.rs/src/mailbox.rs
Normal file
51
artiq/runtime.rs/src/mailbox.rs
Normal file
@ -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) }
|
||||
}
|
Loading…
Reference in New Issue
Block a user