imix/test/crc_test.rs
1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Test that CRC is working properly.
6//!
7//! To test, add the following line to the imix boot sequence:
8//! ```
9//! test::crc_test::run_crc();
10//! ```
11//! You should see the following output:
12//! ```
13//! CRC32: 0xcbf43926
14//! CRC32C: 0xe3069283
15//! CRC16CITT: 0x89f6
16//!
17//! ```
18//!
19//! These results are for computing the CRC over the string
20//! "123456789" (not including the quotes). The result values were
21//! taken from
22//! <https://reveng.sourceforge.io/crc-catalogue/17plus.htm>
23
24use capsules_extra::test::crc::TestCrc;
25use kernel::hil::crc::Crc;
26use kernel::static_init;
27use sam4l::crccu::Crccu;
28
29pub unsafe fn run_crc(crc: &'static Crccu) {
30 let t = static_init_crc(crc);
31 crc.set_client(t);
32
33 t.run();
34}
35
36unsafe fn static_init_crc(crc: &'static Crccu) -> &'static TestCrc<'static, Crccu<'static>> {
37 let data = static_init!([u8; 9], [0; 9]);
38
39 for i in 0..9 {
40 data[i] = i as u8 + b'1';
41 }
42 static_init!(TestCrc<'static, Crccu>, TestCrc::new(crc, data))
43}