@@ -61,7 +61,7 @@ impl Id {
61
61
const EXTENDED_SHIFT : u32 = 3 ;
62
62
const EXTENDED_MASK : u32 = 0x1FFF_FFFF << Self :: EXTENDED_SHIFT ;
63
63
64
- const EID_MASK : u32 = 0x0000_0004 ;
64
+ const IDE_MASK : u32 = 0x0000_0004 ;
65
65
66
66
const RTR_MASK : u32 = 0x0000_0002 ;
67
67
@@ -78,7 +78,7 @@ impl Id {
78
78
/// Ids outside the allowed range are silently truncated.
79
79
pub fn new_extended ( id : u32 ) -> Id {
80
80
assert ! ( id < 0x1FFF_FFFF ) ;
81
- Self ( id << Self :: EXTENDED_SHIFT | Self :: EID_MASK )
81
+ Self ( id << Self :: EXTENDED_SHIFT | Self :: IDE_MASK )
82
82
}
83
83
84
84
fn from_register ( reg : u32 ) -> Id {
@@ -108,7 +108,7 @@ impl Id {
108
108
109
109
/// Returns `true` if the identifier is an extended identifier.
110
110
pub fn is_extended ( self ) -> bool {
111
- self . 0 & Self :: EID_MASK != 0
111
+ self . 0 & Self :: IDE_MASK != 0
112
112
}
113
113
114
114
/// Returns `true` if the identifier is a standard identifier.
@@ -526,56 +526,59 @@ pub struct Filter {
526
526
mask : u32 ,
527
527
}
528
528
529
- /// bxCAN filters have some quirks:
530
- /// https://github.com/UAVCAN/libcanard/blob/8ee343c4edae0e0e4e1c040852aa3d8430f7bf76/drivers/stm32/canard_stm32.c#L471-L513
531
529
impl Filter {
532
530
/// Creates a filter that accepts all messages.
533
531
pub fn accept_all ( ) -> Self {
534
- Self {
535
- id : Id :: EID_MASK | Id :: RTR_MASK ,
536
- mask : 0 ,
537
- }
532
+ Self { id : 0 , mask : 0 }
538
533
}
539
534
540
535
/// Creates a filter that accepts frames with the specified standard identifier.
541
536
pub fn new_standard ( id : u32 ) -> Self {
542
537
Self {
543
- id : id << Id :: STANDARD_SHIFT | Id :: RTR_MASK ,
544
- mask : Id :: STANDARD_MASK | Id :: EID_MASK ,
538
+ id : id << Id :: STANDARD_SHIFT ,
539
+ mask : Id :: STANDARD_MASK | Id :: IDE_MASK | Id :: RTR_MASK ,
545
540
}
546
541
}
547
542
548
543
/// Creates a filter that accepts frames with the extended standard identifier.
549
544
pub fn new_extended ( id : u32 ) -> Self {
550
545
Self {
551
- id : id << Id :: EXTENDED_SHIFT | Id :: RTR_MASK | Id :: EID_MASK ,
552
- mask : Id :: EXTENDED_MASK | Id :: EID_MASK ,
546
+ id : id << Id :: EXTENDED_SHIFT | Id :: IDE_MASK ,
547
+ mask : Id :: EXTENDED_MASK | Id :: IDE_MASK | Id :: RTR_MASK ,
553
548
}
554
549
}
555
550
556
551
/// Only look at the bits of the indentifier which are set to 1 in the mask.
557
552
///
558
553
/// A mask of 0 accepts all identifiers.
559
- pub fn with_mask ( mut self , mask : u32 ) -> Self {
560
- if self . id & Id :: EID_MASK != 0 {
554
+ pub fn with_mask ( & mut self , mask : u32 ) -> & mut Self {
555
+ if self . is_extended ( ) {
561
556
self . mask = ( self . mask & !Id :: EXTENDED_MASK ) | ( mask << Id :: EXTENDED_SHIFT ) ;
562
557
} else {
563
558
self . mask = ( self . mask & !Id :: STANDARD_MASK ) | ( mask << Id :: STANDARD_SHIFT ) ;
564
559
}
565
560
self
566
561
}
567
562
568
- /// Select if only remote (`rtr = true`) frames or only data (`rtr = false`)
569
- /// shall be received.
570
- pub fn with_rtr ( mut self , rtr : bool ) -> Self {
571
- if rtr {
572
- self . id |= Id :: RTR_MASK ;
573
- } else {
574
- self . id &= !Id :: RTR_MASK ;
575
- }
563
+ /// Makes this filter accept both data and remote frames.
564
+ pub fn allow_remote ( & mut self ) -> & mut Self {
565
+ self . mask &= !Id :: RTR_MASK ;
566
+ self
567
+ }
568
+
569
+ /// Makes this filter accept only remote frames.
570
+ pub fn only_remote ( & mut self ) -> & mut Self {
571
+ self . id |= Id :: RTR_MASK ;
576
572
self . mask |= Id :: RTR_MASK ;
577
573
self
578
574
}
575
+
576
+ fn is_extended ( & self ) -> bool {
577
+ self . id & Id :: IDE_MASK != 0
578
+ }
579
+
580
+ fn matches_single_id ( & self ) -> bool {
581
+ }
579
582
}
580
583
581
584
/// Interface to the filter banks of a CAN peripheral.
@@ -604,11 +607,17 @@ where
604
607
}
605
608
606
609
/// Adds a filter. Returns `Err` if the maximum number of filters was reached.
607
- pub fn add ( & mut self , filter : Filter ) -> Result < ( ) , ( ) > {
610
+ pub fn add ( & mut self , filter : & Filter ) -> Result < ( ) , ( ) > {
608
611
let can = unsafe { & * CAN1 :: ptr ( ) } ;
609
612
610
613
let idx = self . start_idx + self . count ;
611
- if idx < self . stop_idx {
614
+ if idx >= self . stop_idx {
615
+ return Err ( ( ) ) ;
616
+ }
617
+
618
+ let list_mode = ( can. fm1r . read ( ) . bits ( ) & ( 1 << idx) ) != 0 ;
619
+ let scale_32bit = ( can. fs1r . read ( ) . bits ( ) & ( 1 << idx) ) != 0 ;
620
+ if !list_mode && scale_32bit {
612
621
let filter_bank = & can. fb [ idx] ;
613
622
filter_bank. fr1 . write ( |w| unsafe { w. bits ( filter. id ) } ) ;
614
623
filter_bank. fr2 . write ( |w| unsafe { w. bits ( filter. mask ) } ) ;
0 commit comments