9 Commits

Author SHA1 Message Date
dbc527f759 async example works as well 2025-05-13 16:33:50 +02:00
d661c940fe added RTR example 2025-05-13 14:45:49 +02:00
37ec9114b3 some cleaning 2025-05-13 12:36:01 +02:00
172e319720 first CAN test works 2025-05-13 12:30:20 +02:00
d4163c5021 this should fix the bitrate error 2025-05-12 13:33:47 +02:00
ec954fcb16 something worng with can clk calc? 2025-05-12 12:09:49 +02:00
629ba4f8f2 add CAN example app 2025-04-29 11:24:48 +02:00
997e0502ab finished first impl 2025-04-28 18:51:37 +02:00
d9d6e11642 manually transfer can support 2025-04-28 09:49:58 +02:00
2 changed files with 2 additions and 25 deletions

View File

@@ -1,22 +1,6 @@
//! # CAN peripheral driver.
//! CAN driver.
//!
//! The VA416xx CAN module is based on the CP3UB26 module.
//!
//! Using the CAN bus generally involves the following steps:
//!
//! 1. Create a [Can] instance
//! 2. The [CanChannels] resource management singleton can be retrieved by using
//! [Can::take_channels].
//! 3. Individual [CanRx] and [CanTx] channels can be created using the [CanChannels::take]
//! function. These allow to send or receive CAN frames on individual channels.
//! 4. The [asynch::CanTxAsync] structure can be created to transmit frames asynchronously.
//! The [asynch::on_interrupt_can] function should be called in the user interrupt handler
//! for CAN0 and CAN1 for this to work properly. The interrupt handler can also take care of
//! receiving frames on [CanRx] channels with enabled interrupts.
//!
//! # Example
//!
//! - [CAN example](https://egit.irs.uni-stuttgart.de/rust/va416xx-rs/src/branch/main/examples/embassy/src/bin/can.rs)
use core::sync::atomic::AtomicBool;
use arbitrary_int::{u11, u15, u2, u3, u4, u7, Number};
@@ -335,7 +319,6 @@ pub enum ClockConfigError {
CanNotFindPrescaler,
}
/// The main CAN peripheral driver.
pub struct Can {
regs: regs::MmioCan<'static>,
id: CanId,
@@ -375,7 +358,6 @@ impl Can {
self.regs.write_gmskb(BaseId::new_with_raw_value(0));
}
/// Retrieve a resource management singleton for the 15 CAN channels.
pub fn take_channels(&self) -> Option<CanChannels> {
if CHANNELS_TAKEN[self.id() as usize].swap(true, core::sync::atomic::Ordering::SeqCst) {
return None;
@@ -430,13 +412,11 @@ impl Can {
&mut self.regs
}
/// Clear all interrupts.
#[inline]
pub fn clear_interrupts(&mut self) {
self.regs
.write_iclr(regs::InterruptClear::new_with_raw_value(0xFFFF_FFFF));
}
/// This function only enable the CAN interrupt vector in the NVIC.
///
/// The interrupts for the individual channels or errors still need to be enabled
@@ -538,7 +518,6 @@ pub enum RxState {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct InvalidRxStateError(pub RxState);
/// Driver instance to use an individual CAN channel as a transmission channel.
#[derive(Debug)]
pub struct CanTx {
ll: CanChannelLowLevel,
@@ -667,7 +646,6 @@ impl CanTx {
}
}
/// Driver instance to use an individual CAN channel as a reception channel.
pub struct CanRx {
ll: CanChannelLowLevel,
mode: RxState,
@@ -782,7 +760,6 @@ impl CanChannels {
self.id
}
/// Take the indidivual CAN channel low level driver instance.
pub fn take(&mut self, idx: usize) -> Option<CanChannelLowLevel> {
if idx > 14 {
return None;

View File

@@ -261,7 +261,7 @@ pub struct ExtendedId {
#[bitbybit::bitfield(u32, default = 0x0)]
#[derive(Debug)]
pub struct BaseId {
/// This will contain ID\[10:0\] for standard frames and bits \[28:18\] for extended frames.
/// This will contain ID\[10:0\] for standard frames and bits [28:18] for extended frames.
#[bits(5..=15, rw)]
mask_28_18: u11,
/// This is the RTR bit for standard frames, and the SRR bit for extended frames.