Skip to content

Commit

Permalink
Fix issues with watermark sizes
Browse files Browse the repository at this point in the history
The M_CAN users manual v330 states that Rx FIFO Watermarks, FnWM, can
take values 1-64 inclusive. Any value greater than 64 is interpreted as
"Watermark interrupt disabled", p.31 and p.34.

It also states that the Tx Event FIFO Watermark, EFWM, can take values
1-32 inclusive, Any value greated than 32 is interpreted as "Watermark
interrupt disabled", p.44.

This change makes the implementation consistent with the users manual on
those specifics.
  • Loading branch information
evading committed Oct 24, 2023
1 parent 53bee3f commit 3b0e81e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions mcan/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Tagging in git follows a pattern: `mcan/<version>`.

## [Unreleased]
- Fix some issues with watermark sizes for Rx FIFOs and Tx Event FIFO.
- Add Can::aux::initialization_mode

## [0.3.0] - 2023-04-24
Expand Down
21 changes: 12 additions & 9 deletions mcan/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>, C: Capacities>
reg.rxf0.c.modify(|_, w| {
let w = w.fom().bit(config.rx_fifo_0.mode.into());
let mut watermark = config.rx_fifo_0.watermark;
// According to the spec, any value >= 64 is interpreted as watermark disabled
if watermark >= 64 {
watermark = 64;
// According to the spec, any value > 64 is interpreted as watermark interrupt
// disabled, as is 0.
if watermark > 64 {
watermark = 0;
}
// Safety: The value is sanitized before the write
unsafe { w.fwm().bits(watermark) }
Expand All @@ -351,9 +352,10 @@ impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>, C: Capacities>
reg.rxf1.c.modify(|_, w| {
let w = w.fom().bit(config.rx_fifo_1.mode.into());
let mut watermark = config.rx_fifo_1.watermark;
// According to the spec, any value >= 64 is interpreted as watermark disabled
if watermark >= 64 {
watermark = 64;
// According to the spec, any value > 64 is interpreted as watermark interrupt
// disabled, as is 0.
if watermark > 64 {
watermark = 0;
}
// Safety: The value is sanitized before the write
unsafe { w.fwm().bits(watermark) }
Expand All @@ -366,9 +368,10 @@ impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>, C: Capacities>
// Configure Tx Event Fifo
reg.txefc.modify(|_, w| {
let mut watermark = config.tx.tx_event_fifo_watermark;
// According to the spec, any value >= 32 is interpreted as watermark disabled
if watermark >= 32 {
watermark = 32;
// According to the spec, any value > 32 is interpreted as watermark interrupt
// disabled, as is 0.
if watermark > 32 {
watermark = 0;
}
// Safety: The value is sanitized before the write
unsafe { w.efwm().bits(watermark) }
Expand Down

0 comments on commit 3b0e81e

Please sign in to comment.