hail/
test_take_map_cell.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
5use core::ptr::addr_of;
6
7use kernel::debug;
8use kernel::utilities::cells::MapCell;
9
10pub unsafe fn test_take_map_cell() {
11    static FOO: u32 = 1234;
12
13    static mut MC_REF: MapCell<&'static u32> = MapCell::new(&FOO);
14    test_map_cell(&*addr_of!(MC_REF));
15
16    static mut MC1: MapCell<[[u8; 256]; 1]> = MapCell::new([[125; 256]; 1]);
17    test_map_cell(&*addr_of!(MC1));
18
19    static mut MC2: MapCell<[[u8; 256]; 2]> = MapCell::new([[125; 256]; 2]);
20    test_map_cell(&*addr_of!(MC2));
21
22    static mut MC3: MapCell<[[u8; 256]; 3]> = MapCell::new([[125; 256]; 3]);
23    test_map_cell(&*addr_of!(MC3));
24
25    static mut MC4: MapCell<[[u8; 256]; 4]> = MapCell::new([[125; 256]; 4]);
26    test_map_cell(&*addr_of!(MC4));
27
28    static mut MC5: MapCell<[[u8; 256]; 5]> = MapCell::new([[125; 256]; 5]);
29    test_map_cell(&*addr_of!(MC5));
30
31    static mut MC6: MapCell<[[u8; 256]; 6]> = MapCell::new([[125; 256]; 6]);
32    test_map_cell(&*addr_of!(MC6));
33
34    static mut MC7: MapCell<[[u8; 256]; 7]> = MapCell::new([[125; 256]; 7]);
35    test_map_cell(&*addr_of!(MC7));
36}
37
38#[inline(never)]
39#[allow(unused_unsafe)]
40unsafe fn test_map_cell<A>(tc: &MapCell<A>) {
41    let dwt_ctl: *mut u32 = 0xE0001000 as *mut u32;
42    let dwt_cycles: *mut u32 = 0xE0001004 as *mut u32;
43    let demcr: *mut u32 = 0xE000EDFC as *mut u32;
44
45    ::core::ptr::write_volatile(demcr, 0x01000000);
46    ::core::ptr::write_volatile(dwt_cycles, 0);
47    ::core::ptr::write_volatile(dwt_ctl, ::core::ptr::read_volatile(dwt_ctl) | 1);
48    tc.map(|_| ());
49    let end = ::core::ptr::read_volatile(dwt_cycles);
50    debug!("time: {}, size: {}", end, ::core::mem::size_of_val(tc));
51}