diff options
Diffstat (limited to 'examples/mcxa/src/bin/crc.rs')
| -rw-r--r-- | examples/mcxa/src/bin/crc.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/mcxa/src/bin/crc.rs b/examples/mcxa/src/bin/crc.rs new file mode 100644 index 000000000..417b4f865 --- /dev/null +++ b/examples/mcxa/src/bin/crc.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use hal::config::Config; | ||
| 6 | use hal::crc::Crc; | ||
| 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
| 8 | |||
| 9 | #[embassy_executor::main] | ||
| 10 | async fn main(_spawner: Spawner) { | ||
| 11 | let config = Config::default(); | ||
| 12 | let mut p = hal::init(config); | ||
| 13 | |||
| 14 | defmt::info!("CRC example"); | ||
| 15 | |||
| 16 | let buf = b"123456789"; | ||
| 17 | |||
| 18 | let mut crc = Crc::new_ccitt_false(p.CRC0.reborrow()); | ||
| 19 | let sum = crc.feed_bytes(buf); | ||
| 20 | assert_eq!(sum, 0x29b1); | ||
| 21 | |||
| 22 | let mut crc = Crc::new_maxim(p.CRC0.reborrow()); | ||
| 23 | let sum = crc.feed_bytes(buf); | ||
| 24 | assert_eq!(sum, 0x44c2); | ||
| 25 | |||
| 26 | let mut crc = Crc::new_kermit(p.CRC0.reborrow()); | ||
| 27 | let sum = crc.feed_bytes(buf); | ||
| 28 | assert_eq!(sum, 0x2189); | ||
| 29 | |||
| 30 | let mut crc = Crc::new_iso_hdlc(p.CRC0.reborrow()); | ||
| 31 | let sum = crc.feed_bytes(buf); | ||
| 32 | assert_eq!(sum, 0xcbf4_3926); | ||
| 33 | |||
| 34 | let mut crc = Crc::new_posix(p.CRC0.reborrow()); | ||
| 35 | let sum = crc.feed_bytes(buf); | ||
| 36 | assert_eq!(sum, 0x765e_7680); | ||
| 37 | |||
| 38 | defmt::info!("CRC successful"); | ||
| 39 | } | ||
