Skip to content

Commit

Permalink
earlgrey: fix SPI test
Browse files Browse the repository at this point in the history
  • Loading branch information
alevy committed Sep 13, 2024
1 parent 81d0436 commit 696dd29
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions boards/opentitan/src/tests/spi_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ use core::cell::Cell;
use kernel::hil::spi::{ClockPhase, ClockPolarity};
use kernel::hil::spi::{SpiMaster, SpiMasterClient};
use kernel::static_init;
use kernel::utilities::cells::TakeCell;
use kernel::utilities::cells::MapCell;
use kernel::utilities::leasable_buffer::SubSliceMut;
use kernel::{debug, ErrorCode};

struct SpiHostCallback {
transfer_done: Cell<bool>,
tx_len: Cell<usize>,
tx_data: TakeCell<'static, [u8]>,
rx_data: TakeCell<'static, [u8]>,
tx_data: MapCell<SubSliceMut<'static, u8>>,
rx_data: MapCell<SubSliceMut<'static, u8>>,
}

impl<'a> SpiHostCallback {
fn new(tx_data: &'static mut [u8], rx_data: &'static mut [u8]) -> Self {
SpiHostCallback {
transfer_done: Cell::new(false),
tx_len: Cell::new(0),
tx_data: TakeCell::new(tx_data),
rx_data: TakeCell::new(rx_data),
tx_data: MapCell::new(tx_data.into()),
rx_data: MapCell::new(rx_data.into()),
}
}

Expand All @@ -38,13 +39,13 @@ impl<'a> SpiHostCallback {
impl<'a> SpiMasterClient for SpiHostCallback {
fn read_write_done(
&self,
tx_data: &'static mut [u8],
rx_done: Option<&'static mut [u8]>,
tx_len: usize,
rc: Result<(), ErrorCode>,
tx_data: SubSliceMut<'static, u8>,
rx_done: Option<SubSliceMut<'static, u8>>,
rc: Result<usize, ErrorCode>,
) {
//Transfer Complete
assert_eq!(rc, Ok(()));
assert!(rc.is_ok());
let tx_len = rc.unwrap();
assert_eq!(tx_len, self.tx_len.get());

//Capture Buffers
Expand Down Expand Up @@ -155,7 +156,7 @@ fn spi_host_transfer_partial() {
spi_host.set_phase(ClockPhase::SampleLeading).ok();

assert_eq!(
spi_host.read_write_bytes(tx, Some(rx), cb.tx_len.get()),
spi_host.read_write_bytes(tx, Some(rx)),
Ok(())
);
run_kernel_op(5000);
Expand Down Expand Up @@ -193,7 +194,7 @@ fn spi_host_transfer_single() {
spi_host.set_phase(ClockPhase::SampleLeading).ok();

assert_eq!(
spi_host.read_write_bytes(tx, Some(rx), cb.tx_len.get()),
spi_host.read_write_bytes(tx, Some(rx)),
Ok(())
);
run_kernel_op(5000);
Expand All @@ -214,7 +215,7 @@ fn spi_host_transfer_single() {
cb.tx_len.set(tx2.len());

assert_eq!(
spi_host.read_write_bytes(tx2, Some(rx2), cb.tx_len.get()),
spi_host.read_write_bytes(tx2, Some(rx2)),
Ok(())
);
run_kernel_op(5000);
Expand Down

0 comments on commit 696dd29

Please sign in to comment.