Skip to content

Commit

Permalink
fix bug where we still try to SPI with no targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron-Hartwig committed Mar 21, 2024
1 parent 7efd082 commit 42661e8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 63 deletions.
77 changes: 36 additions & 41 deletions drv/transceivers-server/src/main.rs
Expand Up @@ -665,63 +665,58 @@ fn main() -> ! {

let mut buffer = [0; idl::INCOMING_SIZE];
loop {
if server.front_io_board_present.is_none() {
server.front_io_board_present = match seq.front_io_board_ready()
{
Ok(true) => {
ringbuf_entry!(Trace::FrontIOBoardReady(true));
Some(true)
}
Err(SeqError::NoFrontIOBoard) => {
ringbuf_entry!(Trace::FrontIOSeqErr(
SeqError::NoFrontIOBoard
));
Some(false)
}
_ => {
ringbuf_entry!(Trace::FrontIOBoardReady(false));
None
}
};

// If a board is present, attempt to initialize its
// LED drivers
if server.front_io_board_present.unwrap_or(false) {
ringbuf_entry!(Trace::LEDInit);
match server.transceivers.enable_led_controllers() {
Ok(_) => server.led_init(),
Err(e) => {
ringbuf_entry!(Trace::LEDEnableError(e))
}
};
}
}

multitimer.poll_now();
for t in multitimer.iter_fired() {
match t {
Timers::I2C => {
// Handle the Front IO status checking as part of this
// loop because the frequency is what we had before and
// the server itself has no knowledge of the sequencer.
if server.front_io_board_present.is_none() {
server.front_io_board_present =
match seq.front_io_board_ready() {
Ok(true) => {
ringbuf_entry!(
Trace::FrontIOBoardReady(true)
);
Some(true)
}
Err(SeqError::NoFrontIOBoard) => {
ringbuf_entry!(Trace::FrontIOSeqErr(
SeqError::NoFrontIOBoard
));
Some(false)
}
_ => {
ringbuf_entry!(
Trace::FrontIOBoardReady(false)
);
None
}
};

// If a board is present, attempt to initialize its
// LED drivers
if server.front_io_board_present.unwrap_or_default()
{
ringbuf_entry!(Trace::LEDInit);
match server
.transceivers
.enable_led_controllers()
{
Ok(_) => server.led_init(),
Err(e) => {
ringbuf_entry!(Trace::LEDEnableError(e))
}
};
}
}

server.handle_i2c_loop();
}
Timers::SPI => {
server.handle_spi_loop();
if server.front_io_board_present.unwrap_or(false) {
server.handle_spi_loop();
}
}
Timers::Blink => {
server.blink_on = !server.blink_on;
}
}
}

server.check_net(
tx_data_buf.as_mut_slice(),
rx_data_buf.as_mut_slice(),
Expand Down
35 changes: 13 additions & 22 deletions drv/transceivers-server/src/udp.rs
Expand Up @@ -307,7 +307,7 @@ impl ServerImpl {
let mask = LogicalPortMask::from(modules);
let (data_len, result) = if self
.front_io_board_present
.unwrap_or_default()
.unwrap_or(false)
{
self.get_status(mask, out)
} else {
Expand Down Expand Up @@ -337,7 +337,7 @@ impl ServerImpl {
let mask = LogicalPortMask::from(modules);
let (data_len, result) = if self
.front_io_board_present
.unwrap_or_default()
.unwrap_or(false)
{
self.get_extended_status(mask, out)
} else {
Expand Down Expand Up @@ -387,7 +387,7 @@ impl ServerImpl {
}

let (data_len, result) =
if self.front_io_board_present.unwrap_or_default() {
if self.front_io_board_present.unwrap_or(false) {
let r = self.read(read, mask & !self.disabled, out);
let len = r.success().count() * read.len() as usize;
(len, r)
Expand Down Expand Up @@ -436,8 +436,7 @@ impl ServerImpl {
}

let mask = LogicalPortMask::from(modules);
let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.write(write, mask & !self.disabled, data)
} else {
ModuleResult::new(
Expand Down Expand Up @@ -469,8 +468,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::AssertReset(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.assert_reset(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -494,8 +492,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::DeassertReset(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.deassert_reset(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -519,8 +516,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::AssertLpMode(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.assert_lpmode(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -544,8 +540,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::DeassertLpMode(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.deassert_lpmode(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -569,8 +564,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::EnablePower(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.enable_power(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -594,8 +588,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::DisablePower(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.disable_power(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand Down Expand Up @@ -645,8 +638,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::ClearPowerFault(modules));
let mask = LogicalPortMask::from(modules) & !self.disabled;

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.transceivers.clear_power_fault(mask)
} else {
ModuleResultNoFailure::new(LogicalPortMask(0), mask)
Expand All @@ -671,7 +663,7 @@ impl ServerImpl {
let mask = LogicalPortMask::from(modules);
let (data_len, result) = if self
.front_io_board_present
.unwrap_or_default()
.unwrap_or(false)
{
self.get_led_state_response(mask, out)
} else {
Expand Down Expand Up @@ -700,8 +692,7 @@ impl ServerImpl {
ringbuf_entry!(Trace::SetLedState(modules, state));
let mask = LogicalPortMask::from(modules);

let result = if self.front_io_board_present.unwrap_or_default()
{
let result = if self.front_io_board_present.unwrap_or(false) {
self.set_led_state(mask, state);
ModuleResultNoFailure::new(mask, LogicalPortMask(0))
.unwrap()
Expand Down

0 comments on commit 42661e8

Please sign in to comment.