Skip to content

Commit

Permalink
#29 optimize tx/rx fifo check
Browse files Browse the repository at this point in the history
  • Loading branch information
HusseinAbdelhamid committed Oct 14, 2024
1 parent 2f32f5c commit fb42590
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ impl<B: Transfer<u8>, CS: OutputPin, CLK: Clock> CanController for MCP2517<B, CS
let fifo_status_reg = Self::fifo_status_register(FIFO_TX_INDEX);

// Check if TX fifo is full
if blocking {
while !self.fifo_not_full(fifo_status_reg)? {}
} else if !self.fifo_not_full(fifo_status_reg)? {
return Err(Error::TxFifoFullErr);
while !self.fifo_not_full(fifo_status_reg)? {
if !blocking {
return Err(Error::TxFifoFullErr);
}
}

// make sure length of payload is consistent with CAN operation mode
Expand Down Expand Up @@ -165,10 +165,10 @@ impl<B: Transfer<u8>, CS: OutputPin, CLK: Clock> CanController for MCP2517<B, CS
let fifo_status_reg = Self::fifo_status_register(FIFO_RX_INDEX);

// Make sure RX fifo is not empty
if blocking {
while !self.fifo_not_empty(fifo_status_reg)? {}
} else if !self.fifo_not_empty(fifo_status_reg)? {
return Err(Error::RxFifoEmptyErr);
while !self.fifo_not_empty(fifo_status_reg)? {
if !blocking {
return Err(Error::RxFifoEmptyErr);
}
}

let user_address = self.read32(Self::fifo_user_address_register(FIFO_RX_INDEX))?;
Expand Down

0 comments on commit fb42590

Please sign in to comment.