mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-22 09:23:16 +00:00
format services/cram-mbox1
This commit is contained in:
parent
774c897a96
commit
7d0552052a
1 changed files with 115 additions and 74 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use utralib::generated::*;
|
||||
use num_traits::*;
|
||||
use utralib::generated::*;
|
||||
|
||||
pub struct Mailbox {
|
||||
csr: utralib::CSR<u32>,
|
||||
|
|
@ -14,16 +14,17 @@ impl Mailbox {
|
|||
pub unsafe fn send_unguarded(&mut self, data: &[u32]) {
|
||||
let status = self.csr.r(utra::mailbox::STATUS);
|
||||
if status & self.csr.ms(utra::mailbox::STATUS_RX_ERR, 1) != 0
|
||||
|| status & self.csr.ms(utra::mailbox::STATUS_TX_ERR, 1) != 0 {
|
||||
|| status & self.csr.ms(utra::mailbox::STATUS_TX_ERR, 1) != 0
|
||||
{
|
||||
log::warn!("Rx/Tx err was encountered: {:x}", status);
|
||||
}
|
||||
if status & self.csr.ms(utra::mailbox::STATUS_TX_WORDS, !0) != 0 {
|
||||
log::warn!("Tx register is not empty: {:x}", status);
|
||||
}
|
||||
// defer aborts until this interaction is done
|
||||
self.csr.wo(utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) &
|
||||
!self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1)
|
||||
self.csr.wo(
|
||||
utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) & !self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1),
|
||||
);
|
||||
// interact with the FIFO
|
||||
for &d in data {
|
||||
|
|
@ -31,24 +32,27 @@ impl Mailbox {
|
|||
}
|
||||
self.csr.wfo(utra::mailbox::DONE_DONE, 1);
|
||||
// re-enable aborts
|
||||
self.csr.wo(utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) |
|
||||
self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1)
|
||||
self.csr.wo(
|
||||
utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) | self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn get(&mut self, ret: &mut [u32]) -> usize {
|
||||
let status = self.csr.r(utra::mailbox::STATUS);
|
||||
if status & self.csr.ms(utra::mailbox::STATUS_RX_ERR, 1) != 0
|
||||
|| status & self.csr.ms(utra::mailbox::STATUS_TX_ERR, 1) != 0 {
|
||||
|| status & self.csr.ms(utra::mailbox::STATUS_TX_ERR, 1) != 0
|
||||
{
|
||||
log::warn!("Rx/Tx err was encountered: {:x}", status);
|
||||
}
|
||||
// defer aborts until this interaction is done
|
||||
self.csr.wo(utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) &
|
||||
!self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1)
|
||||
self.csr.wo(
|
||||
utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) & !self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1),
|
||||
);
|
||||
// interact with the FIFO
|
||||
// note: this only works because rx_words is the LSB of the register. We don't have to shift the MS'd value.
|
||||
// note: this only works because rx_words is the LSB of the register. We don't have to shift the MS'd
|
||||
// value.
|
||||
let rx_words = status & self.csr.ms(utra::mailbox::STATUS_RX_WORDS, !0);
|
||||
let rx_words_checked = if rx_words as usize > ret.len() {
|
||||
log::warn!("rx_words {} is more than ret.len() {}", rx_words, ret.len());
|
||||
|
|
@ -64,12 +68,13 @@ impl Mailbox {
|
|||
let _ = self.csr.rf(utra::mailbox::RDATA_RDATA);
|
||||
}
|
||||
// re-enable aborts
|
||||
self.csr.wo(utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) |
|
||||
self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1)
|
||||
self.csr.wo(
|
||||
utra::mailbox::EV_ENABLE,
|
||||
self.csr.r(utra::mailbox::EV_ENABLE) | self.csr.ms(utra::mailbox::EV_ENABLE_ABORT_INIT, 1),
|
||||
);
|
||||
rx_words_checked
|
||||
}
|
||||
|
||||
pub fn abort(&mut self) {
|
||||
log::warn!("abort initiated");
|
||||
self.csr.wfo(utra::mailbox::CONTROL_ABORT, 1);
|
||||
|
|
@ -91,30 +96,43 @@ fn handle_irq(_irq_no: usize, arg: *mut usize) {
|
|||
let mbox = unsafe { &mut *(arg as *mut Mailbox) };
|
||||
|
||||
let pending = mbox.csr.r(utra::mailbox::EV_PENDING);
|
||||
mbox.csr
|
||||
.wo(utra::mailbox::EV_PENDING, pending);
|
||||
mbox.csr.wo(utra::mailbox::EV_PENDING, pending);
|
||||
|
||||
if pending & mbox.csr.ms(utra::mailbox::EV_PENDING_ERROR, 1) != 0 {
|
||||
let status = mbox.csr.r(utra::mb_client::STATUS); // this clears the error
|
||||
xous::try_send_message(mbox.cid, xous::Message::new_scalar(
|
||||
Opcode::ProtocolError.to_usize().unwrap(), pending as usize, status as usize, 0, 0)
|
||||
).ok();
|
||||
xous::try_send_message(
|
||||
mbox.cid,
|
||||
xous::Message::new_scalar(
|
||||
Opcode::ProtocolError.to_usize().unwrap(),
|
||||
pending as usize,
|
||||
status as usize,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
if pending & mbox.csr.ms(utra::mailbox::EV_PENDING_ABORT_INIT, 1) != 0 {
|
||||
mbox.abort_pending = true;
|
||||
xous::try_send_message(mbox.cid, xous::Message::new_scalar(
|
||||
Opcode::AbortInit.to_usize().unwrap(), pending as usize, 0, 0, 0)
|
||||
).ok();
|
||||
xous::try_send_message(
|
||||
mbox.cid,
|
||||
xous::Message::new_scalar(Opcode::AbortInit.to_usize().unwrap(), pending as usize, 0, 0, 0),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
if pending & mbox.csr.ms(utra::mailbox::EV_PENDING_ABORT_DONE, 1) != 0 {
|
||||
xous::try_send_message(mbox.cid, xous::Message::new_scalar(
|
||||
Opcode::AbortDone.to_usize().unwrap(), pending as usize, 0, 0, 0)
|
||||
).ok();
|
||||
xous::try_send_message(
|
||||
mbox.cid,
|
||||
xous::Message::new_scalar(Opcode::AbortDone.to_usize().unwrap(), pending as usize, 0, 0, 0),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
if pending & mbox.csr.ms(utra::mailbox::EV_PENDING_AVAILABLE, 1) != 0 {
|
||||
xous::try_send_message(mbox.cid, xous::Message::new_scalar(
|
||||
Opcode::Incoming.to_usize().unwrap(), pending as usize, 0, 0, 0)
|
||||
).ok();
|
||||
xous::try_send_message(
|
||||
mbox.cid,
|
||||
xous::Message::new_scalar(Opcode::Incoming.to_usize().unwrap(), pending as usize, 0, 0, 0),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,11 +167,7 @@ fn main() {
|
|||
.expect("couldn't map Core User CSR range");
|
||||
let mbox = CSR::new(mbox_csr.as_mut_ptr() as *mut u32);
|
||||
|
||||
let mut mailbox = Mailbox {
|
||||
csr: mbox,
|
||||
cid: mbox_cid,
|
||||
abort_pending: false,
|
||||
};
|
||||
let mut mailbox = Mailbox { csr: mbox, cid: mbox_cid, abort_pending: false };
|
||||
#[cfg(not(feature = "ext"))]
|
||||
mailbox.csr.wfo(utra::mailbox::LOOPBACK_LOOPBACK, 1);
|
||||
xous::claim_interrupt(
|
||||
|
|
@ -181,9 +195,11 @@ fn main() {
|
|||
log::info!("starting mbox test");
|
||||
let mut msg_opt = None;
|
||||
let mut return_type = 0;
|
||||
xous::send_message(mailbox.cid, xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(), 1, 0, 0, 0)
|
||||
).ok();
|
||||
xous::send_message(
|
||||
mailbox.cid,
|
||||
xous::Message::new_scalar(Opcode::RunTest.to_usize().unwrap(), 1, 0, 0, 0),
|
||||
)
|
||||
.ok();
|
||||
|
||||
let mut test_array = [0u32; 1024];
|
||||
let mut ret_array = [0u32; 1024];
|
||||
|
|
@ -192,12 +208,9 @@ fn main() {
|
|||
let mut abort_done_seen = false;
|
||||
let mut expect_error = false; // when testing overflows explicitly
|
||||
loop {
|
||||
xous::reply_and_receive_next_legacy(mbox_sid, &mut msg_opt, &mut return_type)
|
||||
.unwrap();
|
||||
xous::reply_and_receive_next_legacy(mbox_sid, &mut msg_opt, &mut return_type).unwrap();
|
||||
let msg = msg_opt.as_mut().unwrap();
|
||||
match num_traits::FromPrimitive::from_usize(msg.body.id())
|
||||
.unwrap_or(Opcode::InvalidCall)
|
||||
{
|
||||
match num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(Opcode::InvalidCall) {
|
||||
Opcode::RunTest => {
|
||||
if let Some(scalar) = msg.body.scalar_message() {
|
||||
// core_csr.wfo(utra::main::REPORT_REPORT, scalar.arg1 as u32); // indicate the test start
|
||||
|
|
@ -314,9 +327,17 @@ fn main() {
|
|||
if check_results(&test_array, &ret_array, count) {
|
||||
let last_seq_no = test_array[0] & 0xffff;
|
||||
log::info!("Test {} passed", last_seq_no);
|
||||
xous::send_message(mailbox.cid, xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(), last_seq_no as usize + 1, 0, 0, 0)
|
||||
).ok();
|
||||
xous::send_message(
|
||||
mailbox.cid,
|
||||
xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(),
|
||||
last_seq_no as usize + 1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.ok();
|
||||
} else {
|
||||
log::error!("Aborting test, errors encountered");
|
||||
break;
|
||||
|
|
@ -333,9 +354,17 @@ fn main() {
|
|||
mailbox.csr.wfo(utra::mailbox::CONTROL_ABORT, 1);
|
||||
// initiate the next test in the sequence
|
||||
let last_seq_no = test_array[0] & 0xffff;
|
||||
xous::send_message(mailbox.cid, xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(), last_seq_no as usize + 1, 0, 0, 0)
|
||||
).ok();
|
||||
xous::send_message(
|
||||
mailbox.cid,
|
||||
xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(),
|
||||
last_seq_no as usize + 1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
Opcode::AbortDone => {
|
||||
abort_done_seen = true;
|
||||
|
|
@ -343,14 +372,26 @@ fn main() {
|
|||
log::info!("abort protocol done");
|
||||
// initiate the next test in the sequence
|
||||
let last_seq_no = test_array[0] & 0xffff;
|
||||
xous::send_message(mailbox.cid, xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(), last_seq_no as usize + 1, 0, 0, 0)
|
||||
).ok();
|
||||
xous::send_message(
|
||||
mailbox.cid,
|
||||
xous::Message::new_scalar(
|
||||
Opcode::RunTest.to_usize().unwrap(),
|
||||
last_seq_no as usize + 1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
Opcode::ProtocolError => {
|
||||
if let Some(scalar) = msg.body.scalar_message() {
|
||||
if !expect_error {
|
||||
log::error!("Protocol error received: {:x}, {:x}, aborting test", scalar.arg1, scalar.arg2);
|
||||
log::error!(
|
||||
"Protocol error received: {:x}, {:x}, aborting test",
|
||||
scalar.arg1,
|
||||
scalar.arg2
|
||||
);
|
||||
break;
|
||||
} else {
|
||||
log::info!("Expected protocol error received: {:x}, {:x}", scalar.arg1, scalar.arg2);
|
||||
|
|
@ -375,7 +416,6 @@ fn main() {
|
|||
core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation
|
||||
}
|
||||
|
||||
|
||||
fn check_results(test_array: &[u32], ret_array: &[u32], count: usize) -> bool {
|
||||
let test_len = (test_array[0] >> 16) as usize;
|
||||
if test_len > test_array.len() || test_len > ret_array.len() || test_len != count {
|
||||
|
|
@ -385,7 +425,8 @@ fn check_results(test_array: &[u32], ret_array: &[u32], count: usize) -> bool {
|
|||
let mut errcnt = 0;
|
||||
for (index, (&tx, &rx)) in test_array[0..test_len].iter().zip(&ret_array[0..test_len]).enumerate() {
|
||||
if rx != tx ^ 0xAAAA_0000 {
|
||||
if errcnt < 16 { // limit log spew
|
||||
if errcnt < 16 {
|
||||
// limit log spew
|
||||
log::error!("Test failure at {}: {:x}->{:x}", index, tx ^ 0xAAAA_0000, rx);
|
||||
}
|
||||
errcnt += 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue