fixes to mbox test cases (cramium)

This commit is contained in:
bunnie 2023-08-08 18:18:32 +08:00
parent fb9866291a
commit 895afbac7c
2 changed files with 65 additions and 22 deletions

View file

@ -60,7 +60,7 @@ impl Mailbox {
*r = self.csr.rf(utra::mailbox::RDATA_RDATA);
}
// throw away any excess words to avoid breaking the protocol
for _ in 0..(rx_words_checked - rx_words as usize) {
for _ in 0..(rx_words as usize - rx_words_checked) {
let _ = self.csr.rf(utra::mailbox::RDATA_RDATA);
}
// re-enable aborts
@ -91,9 +91,13 @@ 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);
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, 0, 0, 0)
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 {
@ -112,9 +116,6 @@ fn handle_irq(_irq_no: usize, arg: *mut usize) {
Opcode::Incoming.to_usize().unwrap(), pending as usize, 0, 0, 0)
).ok();
}
mbox.csr
.wo(utra::mailbox::EV_PENDING, pending);
}
fn main() {
@ -174,7 +175,7 @@ fn main() {
// 8. write 4 words, transmit. receiver should abort
// 9. 3-word test
core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_c0de);
log::info!("starting mbox test");
let mut msg_opt = None;
let mut return_type = 0;
xous::send_message(mailbox.cid, xous::Message::new_scalar(
@ -186,6 +187,7 @@ fn main() {
let mut generator: u32 = 0x1317_0000;
let mut abort_init_seen = false;
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();
@ -195,7 +197,8 @@ fn main() {
{
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
// core_csr.wfo(utra::main::REPORT_REPORT, scalar.arg1 as u32); // indicate the test start
log::info!("test case {}", scalar.arg1);
match scalar.arg1 {
1 => {
// format of test is:
@ -222,9 +225,11 @@ fn main() {
*t = generator;
generator += 1;
}
expect_error = true;
unsafe{mailbox.send_unguarded(&test_array[0..1024])};
}
5 => {
expect_error = false;
test_array[0] = 0x1_0005; // 1 word sent, test sequence 5
unsafe{mailbox.send_unguarded(&test_array[0..1])};
}
@ -277,6 +282,13 @@ fn main() {
unsafe{mailbox.send_unguarded(&test_array[0..3])};
}
10 => {
for (i, d) in test_array.iter_mut().enumerate() {
*d = i as u32;
}
test_array[0] = 0x0400_000A; // 1024 words sent, test sequence 10
unsafe{mailbox.send_unguarded(&test_array)};
}
11 => {
log::info!("Last test done");
core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_000a);
break;
@ -299,6 +311,7 @@ fn main() {
let count = mailbox.get(&mut ret_array);
if check_results(&mut core_csr, &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();
@ -333,8 +346,12 @@ fn main() {
}
Opcode::ProtocolError => {
if let Some(scalar) = msg.body.scalar_message() {
log::error!("Protocol error received: {:x}, aborting test", scalar.arg1);
break;
if !expect_error {
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);
}
} else {
log::error!("Wrong message type for ProtocolError; aborting test");
break;
@ -354,11 +371,11 @@ fn main() {
}
fn check_results(core_csr: &mut CSR::<u32>, test_array: &[u32], ret_array: &[u32], count: usize) -> bool {
fn check_results(_core_csr: &mut CSR::<u32>, 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 {
log::error!("Test length is incorrect: expected {:x}, got {:x}", test_len, count);
core_csr.wfo(utra::main::REPORT_REPORT, 0xdead_c0de);
// core_csr.wfo(utra::main::REPORT_REPORT, 0xdead_c0de);
return false;
}
let mut errcnt = 0;
@ -371,10 +388,12 @@ fn check_results(core_csr: &mut CSR::<u32>, test_array: &[u32], ret_array: &[u32
}
}
if errcnt == 0 {
core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_0000 | test_len as u32);
// core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_0000 | test_len as u32);
log::info!("Test passed with length {}", test_len);
true
} else {
core_csr.wfo(utra::main::REPORT_REPORT, 0xdead_0000 | test_len as u32);
// core_csr.wfo(utra::main::REPORT_REPORT, 0xdead_0000 | test_len as u32);
log::error!("Test failed with length {}", test_len);
false
}
}

View file

@ -12,7 +12,7 @@ pub struct MailboxClient {
}
impl MailboxClient {
pub fn send(&mut self, data: &[u32]) {
pub fn send(&mut self, data: &[u32], force_overflow: bool) {
// defer aborts until this interaction is done
self.csr_irq.wo(utra::mb_client::EV_ENABLE,
self.csr_irq.r(utra::mb_client::EV_ENABLE) &
@ -25,6 +25,18 @@ impl MailboxClient {
}
self.csr.wfo(utra::mb_client::WDATA_WDATA, d);
}
if data.len() == 1024 && force_overflow {
// check that the free slot indicator stays low on a max-sized transfer
// you have to shove *two* extra pieces of data in because the first word falls through to the
// read register, effectively expanding the FIFO size by 1, and the last word hangs out in
// the pending write register.
self.csr.wfo(utra::mb_client::WDATA_WDATA, 0xfeed_face);
self.csr.wfo(utra::mb_client::WDATA_WDATA, 0xdead_beef);
log::info!("max-length write overflow test result: {}", self.csr.rf(utra::mb_client::STATUS_TX_FREE));
} else {
// this should indicate free at this point
assert!(self.csr.rf(utra::mb_client::STATUS_TX_FREE) == 1);
}
self.csr.wfo(utra::mb_client::DONE_DONE, 1);
// re-enable aborts
self.csr_irq.wo(utra::mb_client::EV_ENABLE,
@ -85,9 +97,13 @@ fn handle_irq(_irq_no: usize, arg: *mut usize) {
let mb_client = unsafe { &mut *(arg as *mut MailboxClient) };
let pending = mb_client.csr_irq.r(utra::mb_client::EV_PENDING);
mb_client.csr_irq
.wo(utra::mb_client::EV_PENDING, mb_client.csr_irq.r(utra::mb_client::EV_PENDING));
if pending & mb_client.csr_irq.ms(utra::mb_client::EV_PENDING_ERROR, 1) != 0 {
let status = mb_client.csr.r(utra::mb_client::STATUS); // this clears the error
xous::try_send_message(mb_client.cid, xous::Message::new_scalar(
Opcode::ProtocolError.to_usize().unwrap(), pending as usize, 0, 0, 0)
Opcode::ProtocolError.to_usize().unwrap(), pending as usize, status as usize, 0, 0)
).ok();
}
if pending & mb_client.csr_irq.ms(utra::mb_client::EV_PENDING_ABORT_INIT, 1) != 0 {
@ -106,9 +122,6 @@ fn handle_irq(_irq_no: usize, arg: *mut usize) {
Opcode::Incoming.to_usize().unwrap(), pending as usize, 0, 0, 0)
).ok();
}
mb_client.csr_irq
.wo(utra::mb_client::EV_PENDING, mb_client.csr_irq.r(utra::mb_client::EV_PENDING));
}
fn main() {
@ -123,7 +136,7 @@ fn main() {
#[cfg(not(feature="ext"))]
xous::MemoryAddress::new(utra::mb_client::HW_MB_CLIENT_BASE),
#[cfg(feature="ext")]
xous::MemoryAddress::new(utra::mb_ext::HW_MB_EXT_BASE),
xous::MemoryAddress::new(utralib::HW_MBOX_EXT_MEM), // replace with utra::mb_ext::HW_MB_EXT_BASE after final integration
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
@ -167,6 +180,7 @@ fn main() {
let mut msg_opt = None;
let mut return_type = 0;
let mut test_data = [0u32; 1024];
let mut expect_error = false;
loop {
xous::reply_and_receive_next_legacy(client_sid, &mut msg_opt, &mut return_type)
@ -193,7 +207,13 @@ fn main() {
if test_seq == 8 { // abort on case #8
mb_client.abort();
} else {
mb_client.send(&test_data[..len]);
if test_seq == 4 {
// on case #4 force an overflow to check overflow mechanisms are working
expect_error = true;
mb_client.send(&test_data[..len], true);
} else {
mb_client.send(&test_data[..len], false);
}
}
} else {
log::error!("Wrong message type for RunTest");
@ -210,8 +230,12 @@ fn main() {
}
Opcode::ProtocolError => {
if let Some(scalar) = msg.body.scalar_message() {
log::error!("Protocol error received: {:x}, aborting test", scalar.arg1);
break;
if !expect_error {
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);
}
} else {
log::error!("Wrong message type for ProtocolError; aborting test");
break;