Skip to content

Commit 48e48f6

Browse files
committed
Add some more status bit checks and pretty defmt print for Mac
1 parent 518f374 commit 48e48f6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/mac/frame_filtering/mod.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub struct FrameFiltering {
9090
impl FrameFiltering {
9191
/// Create a new basic [`FrameFiltering`] that:
9292
/// * Does not filter out frames destined for `station_addr` or an address
93-
/// contained in `extra_address.
93+
/// contained in `extra_address`.
9494
/// * Does not filter out multicast frames.
9595
/// * Does not filter out broadcast frames.
9696
/// * Filters out all control frames.
@@ -244,6 +244,25 @@ impl Mac {
244244
Self(address)
245245
}
246246

247+
/// Get the raw bytes of this MAC address.
248+
pub fn raw(&self) -> &[u8; 6] {
249+
&self.0
250+
}
251+
/// Returns `true` if this MAC is locally administred, i.e. it has the I/G bit set.
252+
pub fn is_multicast(&self) -> bool {
253+
(self.0[0] & 0b1) == 0b1
254+
}
255+
256+
/// Returns `true` if this MAC is locally administred, i.e. it has the U/L bit set.
257+
pub fn is_locally_administred(&self) -> bool {
258+
(self.0[0] & 0b10) == 0b10
259+
}
260+
261+
/// Returns `true` if this MAC is the broadcast address.
262+
pub fn is_broadcast(&self) -> bool {
263+
self.0.iter().all(|v| v == &0xFF)
264+
}
265+
247266
/// Return bytes in a form that can be put into the high portion
248267
/// of a MAC address register by converting them to little-endian
249268
fn high(&self) -> u16 {
@@ -265,6 +284,23 @@ impl From<[u8; 6]> for Mac {
265284
}
266285
}
267286

287+
#[cfg(feature = "defmt")]
288+
impl defmt::Format for Mac {
289+
fn format(&self, fmt: defmt::Formatter) {
290+
let addr = self.0;
291+
defmt::write!(
292+
fmt,
293+
"{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}",
294+
addr[0],
295+
addr[1],
296+
addr[2],
297+
addr[3],
298+
addr[4],
299+
addr[5]
300+
)
301+
}
302+
}
303+
268304
/// A MAC address filter
269305
#[derive(Debug, Clone)]
270306

src/rx.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const RXDESC_0_ES: u32 = 1 << 15;
3434
const RXDESC_0_FL_MASK: u32 = 0x3FFF;
3535
const RXDESC_0_FL_SHIFT: usize = 16;
3636

37+
const RXDESC_0_SAF: u32 = 1 << 13;
38+
3739
const RXDESC_1_RBS_SHIFT: usize = 0;
3840
const RXDESC_1_RBS_MASK: u32 = 0x0fff << RXDESC_1_RBS_SHIFT;
3941
/// Second address chained
@@ -123,6 +125,10 @@ impl RxDescriptor {
123125
fn get_frame_len(&self) -> usize {
124126
((self.desc.read(0) >> RXDESC_0_FL_SHIFT) & RXDESC_0_FL_MASK) as usize
125127
}
128+
129+
fn failed_saf(&self) -> bool {
130+
(self.desc.read(0) & RXDESC_0_SAF) == RXDESC_0_SAF
131+
}
126132
}
127133

128134
/// An RX DMA Ring Descriptor entry
@@ -203,6 +209,11 @@ impl<'a> RxPacket<'a> {
203209
pub fn free(self) {
204210
drop(self)
205211
}
212+
213+
// Whether or not the packet failed the source address filter.
214+
pub fn failed_source_address_filter(&self) -> bool {
215+
self.entry.desc().failed_saf()
216+
}
206217
}
207218

208219
/// Rx DMA state

0 commit comments

Comments
 (0)