From 8f6e9bc6b01e05c67d3259e76fea0096277973f0 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Tue, 3 Jan 2023 21:34:57 +0100 Subject: [PATCH] Shorten D(estination)A(ddress) and S(ource)A(ddress), Filtering -> Filter --- examples/arp.rs | 6 +- .../control.rs | 8 +-- .../destination.rs | 26 ++++---- .../hash_table.rs | 0 .../{frame_filtering => frame_filter}/mod.rs | 64 +++++++++---------- .../multicast.rs | 6 +- .../source.rs | 12 ++-- src/mac/mod.rs | 10 +-- 8 files changed, 66 insertions(+), 66 deletions(-) rename src/mac/{frame_filtering => frame_filter}/control.rs (80%) rename src/mac/{frame_filtering => frame_filter}/destination.rs (62%) rename src/mac/{frame_filtering => frame_filter}/hash_table.rs (100%) rename src/mac/{frame_filtering => frame_filter}/mod.rs (84%) rename src/mac/{frame_filtering => frame_filter}/multicast.rs (85%) rename src/mac/{frame_filtering => frame_filter}/source.rs (73%) diff --git a/examples/arp.rs b/examples/arp.rs index 424d1f8..2c5c363 100644 --- a/examples/arp.rs +++ b/examples/arp.rs @@ -17,7 +17,7 @@ use cortex_m_rt::{entry, exception}; use cortex_m::interrupt::Mutex; use stm32_eth::{ mac::{ - frame_filtering::{FrameFiltering, FrameFilteringMode, Mac}, + frame_filter::{Filter, FilterConfig, Mac}, phy::BarePhy, Phy, }, @@ -63,12 +63,12 @@ fn main() -> ! { let some_mac = if eth_dma.tx_is_running() { 1 } else { 0 }; - let frame_filtering = FrameFiltering::filter_destinations( + let filter_config = FilterConfig::filter_destinations( Mac::new([some_mac, some_mac, some_mac, some_mac, some_mac, some_mac]), &[], ); - eth_mac.configure_filtering(&FrameFilteringMode::Filter(frame_filtering)); + eth_mac.configure_frame_filter(&Filter::Filter(filter_config)); let mut last_link_up = false; diff --git a/src/mac/frame_filtering/control.rs b/src/mac/frame_filter/control.rs similarity index 80% rename from src/mac/frame_filtering/control.rs rename to src/mac/frame_filter/control.rs index f8ffa6d..432a7ef 100644 --- a/src/mac/frame_filtering/control.rs +++ b/src/mac/frame_filter/control.rs @@ -2,7 +2,7 @@ /// on received control frames, #[derive(Debug, Clone)] -pub enum ControlFrameFiltering { +pub enum ControlFrameFilter { /// Prevent all control frames from reaching /// the application. BlockAll, @@ -16,15 +16,15 @@ pub enum ControlFrameFiltering { AddressFilter, } -impl ControlFrameFiltering { - /// Create a new [`ControlFrameFiltering`] that filters out +impl ControlFrameFilter { + /// Create a new [`ControlFrameFilter`] that filters out /// all control frames. pub const fn new() -> Self { Self::BlockAll } } -impl Default for ControlFrameFiltering { +impl Default for ControlFrameFilter { fn default() -> Self { Self::new() } diff --git a/src/mac/frame_filtering/destination.rs b/src/mac/frame_filter/destination.rs similarity index 62% rename from src/mac/frame_filtering/destination.rs rename to src/mac/frame_filter/destination.rs index f0c4e32..456d1b6 100644 --- a/src/mac/frame_filtering/destination.rs +++ b/src/mac/frame_filter/destination.rs @@ -1,36 +1,36 @@ -/// The type of filtering that the MAC should apply to -/// frames that are to be transmitted. +/// The type of destination address filtering that +/// the MAC should apply to incoming frames. #[derive(Debug, Clone)] -pub struct DestinationAddressFiltering { +pub struct DaFilter { /// Filtering to be performed based on perfect address matches. - pub perfect_filtering: PerfectDestinationAddressFilteringMode, + pub perfect_filtering: PerfectDaFilterMode, /// Enable or disable hash table filtering for destination /// addresses. pub hash_table_filtering: bool, } -impl DestinationAddressFiltering { - /// Create a new [`DestinationAddressFiltering`] that does +impl DaFilter { + /// Create a new [`DaFilter`] that does /// not filter any frames. pub const fn new() -> Self { Self { - perfect_filtering: PerfectDestinationAddressFilteringMode::new(), + perfect_filtering: PerfectDaFilterMode::new(), hash_table_filtering: false, } } } -impl Default for DestinationAddressFiltering { +impl Default for DaFilter { fn default() -> Self { Self::new() } } /// The type of destination address filtering that -/// the MAC should apply to frames. +/// the MAC should apply to incoming frames. #[derive(Debug, Clone)] -pub enum PerfectDestinationAddressFilteringMode { +pub enum PerfectDaFilterMode { /// Filter frames by their Destination Address, based on /// the addresses configured with [`AddressFilterType::Destination`]. /// @@ -44,15 +44,15 @@ pub enum PerfectDestinationAddressFilteringMode { Inverse, } -impl PerfectDestinationAddressFilteringMode { - /// Create a new [`PerfectDestinationAddressFilteringMode`] that filters +impl PerfectDaFilterMode { + /// Create a new [`PerfectDaFilterMode`] that filters /// out all frames. pub const fn new() -> Self { Self::Normal } } -impl Default for PerfectDestinationAddressFilteringMode { +impl Default for PerfectDaFilterMode { fn default() -> Self { Self::new() } diff --git a/src/mac/frame_filtering/hash_table.rs b/src/mac/frame_filter/hash_table.rs similarity index 100% rename from src/mac/frame_filtering/hash_table.rs rename to src/mac/frame_filter/hash_table.rs diff --git a/src/mac/frame_filtering/mod.rs b/src/mac/frame_filter/mod.rs similarity index 84% rename from src/mac/frame_filtering/mod.rs rename to src/mac/frame_filter/mod.rs index 78e43e1..41af9bd 100644 --- a/src/mac/frame_filtering/mod.rs +++ b/src/mac/frame_filter/mod.rs @@ -20,25 +20,25 @@ pub use control::*; /// The frame filtering that the MAC should apply to /// received Ethernet frames. #[derive(Debug, Clone)] -pub enum FrameFilteringMode { +pub enum Filter { /// No frame filtering on any frames. Promiscuous, /// Perform frame filtering based on the provided /// configuration. - Filter(FrameFiltering), + Filter(FilterConfig), } -impl Default for FrameFilteringMode { +impl Default for Filter { fn default() -> Self { Self::Promiscuous } } -impl FrameFilteringMode { +impl Filter { pub(crate) fn configure(&self, eth_mac: ÐERNET_MAC) { match self { - FrameFilteringMode::Promiscuous => eth_mac.macffr.write(|w| w.pm().set_bit()), - FrameFilteringMode::Filter(config) => config.configure(eth_mac), + Filter::Promiscuous => eth_mac.macffr.write(|w| w.pm().set_bit()), + Filter::Filter(config) => config.configure(eth_mac), } } } @@ -49,7 +49,7 @@ impl FrameFilteringMode { /// The total amount of [`MacAddressFilter`]s in this configuration object may /// be at most 3. #[derive(Debug, Clone)] -pub struct FrameFiltering { +pub struct FilterConfig { /// The MAC address of this station. This address is always /// used for Destination Address filtering. pub base_address: Mac, @@ -59,18 +59,18 @@ pub struct FrameFiltering { /// Frame filtering applied to frames based on /// their destination address. - pub destination_address_filter: DestinationAddressFiltering, + pub destination_address_filter: DaFilter, /// Frame filtering applied to frames based on /// their source address. - pub source_address_filter: SourceAddressFiltering, + pub source_address_filter: SaFilter, /// Frame filtering applied to frames based on /// whether they have a multicast address or not. - pub multicast_address_filter: MulticastAddressFiltering, + pub multicast_address_filter: MulticastAddressFilter, /// Control frame filtering mode, - pub control_filter: ControlFrameFiltering, + pub control_filter: ControlFrameFilter, /// Hash table configuration. pub hash_table_value: HashTableValue, @@ -89,8 +89,8 @@ pub struct FrameFiltering { pub receive_all: bool, } -impl FrameFiltering { - /// Create a new basic [`FrameFiltering`] that: +impl FilterConfig { + /// Create a new basic [`FilterConfig`] that: /// * Does not filter out frames destined for `station_addr` or an address /// contained in `extra_address`. /// * Does not filter out multicast frames. @@ -115,16 +115,16 @@ impl FrameFiltering { } } - FrameFiltering { + FilterConfig { base_address: station_addr, address_filters, - destination_address_filter: DestinationAddressFiltering { - perfect_filtering: PerfectDestinationAddressFilteringMode::Normal, + destination_address_filter: DaFilter { + perfect_filtering: PerfectDaFilterMode::Normal, hash_table_filtering: false, }, - source_address_filter: SourceAddressFiltering::Ignore, - multicast_address_filter: MulticastAddressFiltering::PassAll, - control_filter: ControlFrameFiltering::BlockAll, + source_address_filter: SaFilter::Ignore, + multicast_address_filter: MulticastAddressFilter::PassAll, + control_filter: ControlFrameFilter::BlockAll, hash_table_value: HashTableValue::new(), filter_broadcast: false, receive_all: false, @@ -132,7 +132,7 @@ impl FrameFiltering { } fn configure(&self, eth_mac: ÐERNET_MAC) { - let FrameFiltering { + let FilterConfig { base_address, address_filters, destination_address_filter, @@ -152,28 +152,28 @@ impl FrameFiltering { .write(|w| w.maca0l().bits(base_address.low())); let daif = match &destination_address_filter.perfect_filtering { - PerfectDestinationAddressFilteringMode::Normal => false, - PerfectDestinationAddressFilteringMode::Inverse => true, + PerfectDaFilterMode::Normal => false, + PerfectDaFilterMode::Inverse => true, }; let hu = destination_address_filter.hash_table_filtering; let (saf, saif) = match &source_address_filter { - SourceAddressFiltering::Ignore => (false, false), - SourceAddressFiltering::Normal => (true, false), - SourceAddressFiltering::Inverse => (true, true), + SaFilter::Ignore => (false, false), + SaFilter::Normal => (true, false), + SaFilter::Inverse => (true, true), }; let (pam, hm) = match &multicast_address_filter { - MulticastAddressFiltering::PassAll => (true, false), - MulticastAddressFiltering::DestinationAddressHash => (false, true), - MulticastAddressFiltering::DestinationAddress => (false, false), + MulticastAddressFilter::PassAll => (true, false), + MulticastAddressFilter::DestinationAddressHash => (false, true), + MulticastAddressFilter::DestinationAddress => (false, false), }; let pcf = match &control_filter { - ControlFrameFiltering::BlockAll => 0b00, - ControlFrameFiltering::NoPause => 0b01, - ControlFrameFiltering::AllowAll => 0b10, - ControlFrameFiltering::AddressFilter => 0b11, + ControlFrameFilter::BlockAll => 0b00, + ControlFrameFilter::NoPause => 0b01, + ControlFrameFilter::AllowAll => 0b10, + ControlFrameFilter::AddressFilter => 0b11, }; macro_rules! next_addr_reg { diff --git a/src/mac/frame_filtering/multicast.rs b/src/mac/frame_filter/multicast.rs similarity index 85% rename from src/mac/frame_filtering/multicast.rs rename to src/mac/frame_filter/multicast.rs index 769cf8b..4581d80 100644 --- a/src/mac/frame_filtering/multicast.rs +++ b/src/mac/frame_filter/multicast.rs @@ -1,6 +1,6 @@ /// Multicast address filtering #[derive(Debug, Clone)] -pub enum MulticastAddressFiltering { +pub enum MulticastAddressFilter { /// All received multicast frames are passed to the /// application. PassAll, @@ -14,7 +14,7 @@ pub enum MulticastAddressFiltering { DestinationAddress, } -impl MulticastAddressFiltering { +impl MulticastAddressFilter { /// Create a new MulticastAddressFiltering that does not /// filter any multicast frames. pub const fn new() -> Self { @@ -22,7 +22,7 @@ impl MulticastAddressFiltering { } } -impl Default for MulticastAddressFiltering { +impl Default for MulticastAddressFilter { fn default() -> Self { Self::new() } diff --git a/src/mac/frame_filtering/source.rs b/src/mac/frame_filter/source.rs similarity index 73% rename from src/mac/frame_filtering/source.rs rename to src/mac/frame_filter/source.rs index 477e3f9..983fbec 100644 --- a/src/mac/frame_filtering/source.rs +++ b/src/mac/frame_filter/source.rs @@ -1,8 +1,8 @@ -/// The type of frame filtering that the MAC should perform -/// on received frames. +/// The type of source address frame filtering that +/// the MAC should perform to received frames. #[derive(Debug, Clone)] -pub enum SourceAddressFiltering { +pub enum SaFilter { /// Source address filtering never fails. Ignore, /// Filter frames by their Source Address, based on @@ -17,15 +17,15 @@ pub enum SourceAddressFiltering { Inverse, } -impl SourceAddressFiltering { - /// Create a new [`SourceAddressFiltering`] that +impl SaFilter { + /// Create a new [`SaFilter`] that /// does not filter any frames. pub const fn new() -> Self { Self::Inverse } } -impl Default for SourceAddressFiltering { +impl Default for SaFilter { fn default() -> Self { Self::new() } diff --git a/src/mac/mod.rs b/src/mac/mod.rs index 795e327..7440dbd 100644 --- a/src/mac/mod.rs +++ b/src/mac/mod.rs @@ -11,7 +11,7 @@ use crate::{ mod miim; pub use miim::*; -pub mod frame_filtering; +pub mod frame_filter; /// Speeds at which this MAC can be configured #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -39,7 +39,7 @@ mod consts { /* For HCLK over 150 MHz */ pub const ETH_MACMIIAR_CR_HCLK_DIV_102: u8 = 4; } -use self::{consts::*, frame_filtering::FrameFilteringMode}; +use self::{consts::*, frame_filter::Filter}; /// HCLK must be at least 25MHz to use the ethernet peripheral. /// This (empty) struct is returned to indicate that it is not set @@ -139,7 +139,7 @@ impl EthernetMAC { .mmctimr .modify(|r, w| unsafe { w.bits(r.bits() | (1 << 21)) }); - FrameFilteringMode::Promiscuous.configure(ð_mac); + Filter::Promiscuous.configure(ð_mac); let mut me = Self { eth_mac }; @@ -207,8 +207,8 @@ impl EthernetMAC { /// Configure the frame filtering performed by this MAC. #[inline(always)] - pub fn configure_filtering(&self, filtering_config: &FrameFilteringMode) { - filtering_config.configure(&self.eth_mac); + pub fn configure_frame_filter(&self, filter_config: &Filter) { + filter_config.configure(&self.eth_mac); } }