stm32: can: fd: Properties: rm &mut refs; make !Sync; rename getters

This commit is contained in:
Torin Cooper-Bennun 2024-04-19 14:41:49 +01:00
parent 7f55a28a50
commit 263071d016

View File

@ -209,11 +209,6 @@ impl<'d, T: Instance> CanConfigurator<'d, T> {
&self.properties &self.properties
} }
/// Get mutable driver properties
pub fn properties_mut(&mut self) -> &mut Properties<T> {
&mut self.properties
}
/// Get configuration /// Get configuration
pub fn config(&self) -> crate::can::fd::config::FdCanConfig { pub fn config(&self) -> crate::can::fd::config::FdCanConfig {
return self.config; return self.config;
@ -299,11 +294,6 @@ impl<'d, T: Instance> Can<'d, T> {
&self.properties &self.properties
} }
/// Get mutable driver properties
pub fn properties_mut(&mut self) -> &mut Properties<T> {
&mut self.properties
}
/// Flush one of the TX mailboxes. /// Flush one of the TX mailboxes.
pub async fn flush(&self, idx: usize) { pub async fn flush(&self, idx: usize) {
poll_fn(|cx| { poll_fn(|cx| {
@ -437,11 +427,6 @@ impl<'c, 'd, T: Instance, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize>
&self.properties &self.properties
} }
/// Get mutable driver properties
pub fn properties_mut(&mut self) -> &mut Properties<T> {
&mut self.properties
}
fn setup(self) -> Self { fn setup(self) -> Self {
// We don't want interrupts being processed while we change modes. // We don't want interrupts being processed while we change modes.
critical_section::with(|_| unsafe { critical_section::with(|_| unsafe {
@ -565,11 +550,6 @@ impl<'c, 'd, T: Instance, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize>
&self.properties &self.properties
} }
/// Get mutable driver properties
pub fn properties_mut(&mut self) -> &mut Properties<T> {
&mut self.properties
}
fn setup(self) -> Self { fn setup(self) -> Self {
// We don't want interrupts being processed while we change modes. // We don't want interrupts being processed while we change modes.
critical_section::with(|_| unsafe { critical_section::with(|_| unsafe {
@ -830,7 +810,8 @@ impl TxMode {
/// Common driver properties, including filters and error counters /// Common driver properties, including filters and error counters
pub struct Properties<T> { pub struct Properties<T> {
instance: PhantomData<T>, // phantom pointer to ensure !Sync
instance: PhantomData<*const T>,
} }
impl<T: Instance> Properties<T> { impl<T: Instance> Properties<T> {
@ -840,44 +821,46 @@ impl<T: Instance> Properties<T> {
} }
} }
/// Set an Standard Address CAN filter into slot 'id' /// Set a standard address CAN filter in the specified slot in FDCAN memory.
#[inline] #[inline]
pub fn set_standard_filter(&mut self, slot: StandardFilterSlot, filter: StandardFilter) { pub fn set_standard_filter(&self, slot: StandardFilterSlot, filter: StandardFilter) {
T::registers().msg_ram_mut().filters.flssa[slot as usize].activate(filter); T::registers().msg_ram_mut().filters.flssa[slot as usize].activate(filter);
} }
/// Set an array of Standard Address CAN filters and overwrite the current set /// Set the full array of standard address CAN filters in FDCAN memory.
pub fn set_standard_filters(&mut self, filters: &[StandardFilter; STANDARD_FILTER_MAX as usize]) { /// Overwrites all standard address filters in memory.
pub fn set_standard_filters(&self, filters: &[StandardFilter; STANDARD_FILTER_MAX as usize]) {
for (i, f) in filters.iter().enumerate() { for (i, f) in filters.iter().enumerate() {
T::registers().msg_ram_mut().filters.flssa[i].activate(*f); T::registers().msg_ram_mut().filters.flssa[i].activate(*f);
} }
} }
/// Set an Extended Address CAN filter into slot 'id' /// Set an extended address CAN filter in the specified slot in FDCAN memory.
#[inline] #[inline]
pub fn set_extended_filter(&mut self, slot: ExtendedFilterSlot, filter: ExtendedFilter) { pub fn set_extended_filter(&self, slot: ExtendedFilterSlot, filter: ExtendedFilter) {
T::registers().msg_ram_mut().filters.flesa[slot as usize].activate(filter); T::registers().msg_ram_mut().filters.flesa[slot as usize].activate(filter);
} }
/// Set an array of Extended Address CAN filters and overwrite the current set /// Set the full array of extended address CAN filters in FDCAN memory.
pub fn set_extended_filters(&mut self, filters: &[ExtendedFilter; EXTENDED_FILTER_MAX as usize]) { /// Overwrites all extended address filters in memory.
pub fn set_extended_filters(&self, filters: &[ExtendedFilter; EXTENDED_FILTER_MAX as usize]) {
for (i, f) in filters.iter().enumerate() { for (i, f) in filters.iter().enumerate() {
T::registers().msg_ram_mut().filters.flesa[i].activate(*f); T::registers().msg_ram_mut().filters.flesa[i].activate(*f);
} }
} }
/// Get the CAN RX error counter /// Get the CAN RX error counter
pub fn get_rx_error_count(&self) -> u8 { pub fn rx_error_count(&self) -> u8 {
T::registers().regs.ecr().read().rec() T::registers().regs.ecr().read().rec()
} }
/// Get the CAN TX error counter /// Get the CAN TX error counter
pub fn get_tx_error_count(&self) -> u8 { pub fn tx_error_count(&self) -> u8 {
T::registers().regs.ecr().read().tec() T::registers().regs.ecr().read().tec()
} }
/// Get the current Bus-Off state /// Get the current Bus-Off state
pub fn get_bus_off(&self) -> bool { pub fn bus_off(&self) -> bool {
T::registers().regs.psr().read().bo() T::registers().regs.psr().read().bo()
} }
} }