diff options
| -rw-r--r-- | embassy-net-adin1110/src/lib.rs | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index e917edcc8..8b81065c5 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs | |||
| @@ -95,11 +95,6 @@ pub struct ADIN1110<SPI> { | |||
| 95 | crc: bool, | 95 | crc: bool, |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /// Round size up the N u32; | ||
| 99 | pub(crate) fn size_align_u32(size: u32) -> u32 { | ||
| 100 | (size + 3) & 0xFFFF_FFFC | ||
| 101 | } | ||
| 102 | |||
| 103 | impl<SPI: SpiDevice> ADIN1110<SPI> { | 98 | impl<SPI: SpiDevice> ADIN1110<SPI> { |
| 104 | pub fn new(spi: SPI, crc: bool) -> Self { | 99 | pub fn new(spi: SPI, crc: bool) -> Self { |
| 105 | Self { spi, crc } | 100 | Self { spi, crc } |
| @@ -192,14 +187,12 @@ impl<SPI: SpiDevice> ADIN1110<SPI> { | |||
| 192 | let mut tx_buf = Vec::<u8, 16>::new(); | 187 | let mut tx_buf = Vec::<u8, 16>::new(); |
| 193 | 188 | ||
| 194 | // Size of the frame, also includes the appednded header. | 189 | // Size of the frame, also includes the appednded header. |
| 195 | let packet_size = self.read_reg(sr::RX_FSIZE).await?; | 190 | let packet_size = self.read_reg(sr::RX_FSIZE).await? as usize; |
| 196 | 191 | ||
| 197 | // Packet read of write to the MAC packet buffer must be a multipul of 4! | 192 | // Packet read of write to the MAC packet buffer must be a multipul of 4! |
| 198 | let read_size = size_align_u32(packet_size); | 193 | let read_size = packet_size.next_multiple_of(4); |
| 199 | 194 | ||
| 200 | if packet_size < u32::try_from(FRAME_HEADER_LEN + FSC_LEN).unwrap() | 195 | if packet_size < (FRAME_HEADER_LEN + FSC_LEN) || read_size > packet.len() { |
| 201 | || read_size > u32::try_from(packet.len()).unwrap() | ||
| 202 | { | ||
| 203 | return Err(AdinError::PACKET_TOO_BIG); | 196 | return Err(AdinError::PACKET_TOO_BIG); |
| 204 | } | 197 | } |
| 205 | 198 | ||
| @@ -836,18 +829,6 @@ mod tests { | |||
| 836 | spi.done(); | 829 | spi.done(); |
| 837 | } | 830 | } |
| 838 | 831 | ||
| 839 | #[test] | ||
| 840 | fn align_size() { | ||
| 841 | assert_eq!(size_align_u32(1), 4); | ||
| 842 | assert_eq!(size_align_u32(2), 4); | ||
| 843 | assert_eq!(size_align_u32(3), 4); | ||
| 844 | assert_eq!(size_align_u32(4), 4); | ||
| 845 | assert_eq!(size_align_u32(5), 8); | ||
| 846 | assert_eq!(size_align_u32(6), 8); | ||
| 847 | assert_eq!(size_align_u32(7), 8); | ||
| 848 | assert_eq!(size_align_u32(8), 8); | ||
| 849 | } | ||
| 850 | |||
| 851 | // #[test] | 832 | // #[test] |
| 852 | // fn write_packet_to_fifo_less_64b_with_crc() { | 833 | // fn write_packet_to_fifo_less_64b_with_crc() { |
| 853 | // // Configure expectations | 834 | // // Configure expectations |
| @@ -1224,10 +1205,9 @@ mod tests { | |||
| 1224 | // Packet FCS | 1205 | // Packet FCS |
| 1225 | spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap(); | 1206 | spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap(); |
| 1226 | 1207 | ||
| 1227 | let spi_packet_len = u32::try_from(spi_packet.len()).unwrap(); | ||
| 1228 | |||
| 1229 | // SPI HEADER Padding of u32 | 1208 | // SPI HEADER Padding of u32 |
| 1230 | for _ in spi_packet_len..size_align_u32(spi_packet_len) { | 1209 | let spi_packet_len = spi_packet.len(); |
| 1210 | for _ in spi_packet_len..spi_packet_len.next_multiple_of(4) { | ||
| 1231 | spi_packet.push(0x00).unwrap(); | 1211 | spi_packet.push(0x00).unwrap(); |
| 1232 | } | 1212 | } |
| 1233 | 1213 | ||
