bern_conf_type/
lib.rs

1//! Types and structures for the kernel config.
2//!
3//! Cargo features are somewhat limited and configuring the size of static
4//! arrays is straight forward. The types for the config are put into separate
5//! crate to ensure non-cyclic dependencies as the `conf` and `bern_kernel`
6//! crate depend on it.
7#![no_std]
8
9use bern_units::memory_size::Byte;
10
11/// Location of additional memory.
12pub enum MemoryLocation {
13    /// Located within the microcontroller.
14    Internal,
15    /// Memory is connected to the microcontroller via an external bus.
16    External,
17}
18
19/// Type of Memory.
20pub enum MemoryType {
21    /// Read-only memory.
22    Rom,
23    /// EERPOM.
24    ///
25    /// Bytes can be set/cleared individually.
26    Eeprom,
27    /// Flash memory.
28    ///
29    /// Clearing memory requires clearing whole pages.
30    Flash,
31    /// RAM for non-volatile data storage.
32    Ram,
33    /// Memory mapped peripheral.
34    Peripheral,
35}
36
37/// Kernel related config
38pub struct Kernel {
39    /// The number of different priorities.
40    /// Keep the number low as it influences overhead when switching threads.
41    pub priorities: u8,
42    /// Size of kernel memory region.
43    ///
44    /// **Note:** Must be sized accoring to memory protection restrictions.
45    pub memory_size: Byte,
46}
47
48pub struct Shared {
49    /// Size of the shared memory region (bss + data).
50    ///
51    /// **Note:** Must be sized accoring to memory protection restrictions.
52    pub size: Byte,
53}
54
55/// Definition of a memory section.
56pub struct Memory {
57    /// Name in the linker file.
58    pub link_name: &'static str,
59    /// Lowest address of the section.
60    pub start_address: usize,
61    /// Memory size.
62    pub size: Byte,
63}
64
65/// Definition of optional memory sections that go beyond the default of
66/// SRAM and flash.
67pub struct OptionalMemory {
68    /// Type of memory.
69    pub memory_type: MemoryType,
70    /// Location of the memory.
71    pub location: MemoryLocation,
72    /// Name in the linker file.
73    pub link_name: &'static str,
74    /// Lowest address of the section.
75    pub start_address: usize,
76    /// Memory size.
77    pub size: Byte,
78}
79
80/// Memory map.
81pub struct MemoryMap<const N: usize> {
82    /// Default internal flash memory.
83    pub flash: Memory,
84    /// Default internal SRAM.
85    pub sram: Memory,
86    /// Memory mapped peripheral address range.
87    pub peripheral: Memory,
88    /// Additional memory components such as
89    /// - Tightly coupled memory
90    /// - External RAM
91    /// - External flash
92    pub additional: [OptionalMemory; N],
93}
94
95/// Placement of static data and allocators.
96///
97/// Provide the name of the memory section used in the linker script.
98pub struct DataPlacement {
99    /// Static kernel data and kernel allocator.
100    ///
101    /// Inaccessible to the user.
102    pub kernel: &'static str,
103    /// Static process data and allocator.
104    pub processes: &'static str,
105    /// Shared memory section.
106    ///
107    /// Typically placed in `RAM`.
108    pub shared: &'static str,
109}
110
111/// Combined configuration.
112pub struct Conf<const N: usize> {
113    /// Kernel configuration.
114    pub kernel: Kernel,
115    /// Shared memory configuration.
116    pub shared: Shared,
117    /// Application memory map.
118    pub memory_map: MemoryMap<N>,
119    /// Placement of static data and allocators.
120    pub data_placement: DataPlacement,
121}