diff options
Diffstat (limited to 'embassy-net-adin1110/src/crc32.rs')
| -rw-r--r-- | embassy-net-adin1110/src/crc32.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/embassy-net-adin1110/src/crc32.rs b/embassy-net-adin1110/src/crc32.rs index ec020b70c..d7c8346aa 100644 --- a/embassy-net-adin1110/src/crc32.rs +++ b/embassy-net-adin1110/src/crc32.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /// CRC32 lookup table. | ||
| 1 | pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ | 2 | pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ |
| 2 | 0x0000_0000, | 3 | 0x0000_0000, |
| 3 | 0x7707_3096, | 4 | 0x7707_3096, |
| @@ -263,8 +264,10 @@ pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ | |||
| 263 | pub struct ETH_FCS(pub u32); | 264 | pub struct ETH_FCS(pub u32); |
| 264 | 265 | ||
| 265 | impl ETH_FCS { | 266 | impl ETH_FCS { |
| 267 | /// CRC32_OK | ||
| 266 | pub const CRC32_OK: u32 = 0x2144_df1c; | 268 | pub const CRC32_OK: u32 = 0x2144_df1c; |
| 267 | 269 | ||
| 270 | /// Create a new frame check sequence from `data`. | ||
| 268 | #[must_use] | 271 | #[must_use] |
| 269 | pub fn new(data: &[u8]) -> Self { | 272 | pub fn new(data: &[u8]) -> Self { |
| 270 | let fcs = data.iter().fold(u32::MAX, |crc, byte| { | 273 | let fcs = data.iter().fold(u32::MAX, |crc, byte| { |
| @@ -274,6 +277,7 @@ impl ETH_FCS { | |||
| 274 | Self(fcs) | 277 | Self(fcs) |
| 275 | } | 278 | } |
| 276 | 279 | ||
| 280 | /// Update the frame check sequence with `data`. | ||
| 277 | #[must_use] | 281 | #[must_use] |
| 278 | pub fn update(self, data: &[u8]) -> Self { | 282 | pub fn update(self, data: &[u8]) -> Self { |
| 279 | let fcs = data.iter().fold(self.0 ^ u32::MAX, |crc, byte| { | 283 | let fcs = data.iter().fold(self.0 ^ u32::MAX, |crc, byte| { |
| @@ -283,16 +287,19 @@ impl ETH_FCS { | |||
| 283 | Self(fcs) | 287 | Self(fcs) |
| 284 | } | 288 | } |
| 285 | 289 | ||
| 290 | /// Check if the frame check sequence is correct. | ||
| 286 | #[must_use] | 291 | #[must_use] |
| 287 | pub fn crc_ok(&self) -> bool { | 292 | pub fn crc_ok(&self) -> bool { |
| 288 | self.0 == Self::CRC32_OK | 293 | self.0 == Self::CRC32_OK |
| 289 | } | 294 | } |
| 290 | 295 | ||
| 296 | /// Switch byte order. | ||
| 291 | #[must_use] | 297 | #[must_use] |
| 292 | pub fn hton_bytes(&self) -> [u8; 4] { | 298 | pub fn hton_bytes(&self) -> [u8; 4] { |
| 293 | self.0.to_le_bytes() | 299 | self.0.to_le_bytes() |
| 294 | } | 300 | } |
| 295 | 301 | ||
| 302 | /// Switch byte order as a u32. | ||
| 296 | #[must_use] | 303 | #[must_use] |
| 297 | pub fn hton(&self) -> u32 { | 304 | pub fn hton(&self) -> u32 { |
| 298 | self.0.to_le() | 305 | self.0.to_le() |
