1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Procedural macros for the `bern_kernel`.
//!
//! This crate provides macros that:
//! - simplify the kernel usage
//! - make kernel development less tedious (used internally)
use TokenStream;
use ToTokens;
/// Generates an enum with values and a map to match the enum to another type.
///
/// e.g.
/// ```ignore
/// enum_map!{
/// Size, u8;
/// S128 = 5, 128;
/// S256 = 6, 256;
/// }
/// ```
/// expands to
/// ```ignore
/// #[derive(Copy, Clone, Debug, Eq, PartialEq)]
/// #[repr(u8)]
/// pub enum Size {
/// S128 = 5,
/// S256 = 6,
/// }
/// impl Size {
/// pub const fn bits(self) -> u8 {
/// self as u8
/// }
/// }
///
/// #[macro_export]
/// macro_rules! size_from {
/// (128) => { Size::S128 };
/// (256) => { Size::S256 };
/// ($x:expr) => {
/// compile_error!("Invalid parameter - possible values are: 128, 256");
/// }
/// }
/// ```
/// ```
/// Creates a new process and the required linker sections.
///
/// # Example
/// ```ignore
/// // Create a process named `my_proc` with 32kB memory.
/// static MY_PROC: &Process = bern_kernel::new_process!(my_proc, 32768);
///
/// // Place static variable in process memory.
/// #[link_section = ".process.my_proc"]
/// static DATA: u32 = 0xDEADBEEF;
///
/// #[entry]
/// fn main() -> ! {
/// let board = Board::new();
/// bern_kernel::init();
/// /*..*/
/// MY_PROC.init(move |c| {
/// // Spawn threads.
/// }).unwrap();
/// /*..*/
/// bern_kernel::start();
/// }
/// ```