hail/
main.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//! Board file for Hail development platform.
6//!
7//! - <https://github.com/tock/tock/tree/master/boards/hail>
8//! - <https://github.com/lab11/hail>
9
10#![no_std]
11#![no_main]
12#![deny(missing_docs)]
13
14use core::ptr::{addr_of, addr_of_mut};
15
16use kernel::capabilities;
17use kernel::component::Component;
18use kernel::hil;
19use kernel::hil::led::LedLow;
20use kernel::hil::Controller;
21use kernel::platform::{KernelResources, SyscallDriverLookup};
22use kernel::scheduler::round_robin::RoundRobinSched;
23#[allow(unused_imports)]
24use kernel::{create_capability, debug, debug_gpio, static_init};
25use sam4l::chip::Sam4lDefaultPeripherals;
26
27/// Support routines for debugging I/O.
28///
29/// Note: Use of this module will trample any other USART0 configuration.
30pub mod io;
31#[allow(dead_code)]
32mod test_take_map_cell;
33
34// State for loading and holding applications.
35
36// Number of concurrent processes this platform supports.
37const NUM_PROCS: usize = 20;
38
39// Actual memory for holding the active process structures.
40static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
41    [None; NUM_PROCS];
42
43static mut CHIP: Option<&'static sam4l::chip::Sam4l<Sam4lDefaultPeripherals>> = None;
44static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
45    None;
46
47/// Dummy buffer that causes the linker to reserve enough space for the stack.
48#[no_mangle]
49#[link_section = ".stack_buffer"]
50pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
51
52type SI7021Sensor = components::si7021::SI7021ComponentType<
53    capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>,
54    capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, sam4l::i2c::I2CHw<'static>>,
55>;
56type TemperatureDriver = components::temperature::TemperatureComponentType<SI7021Sensor>;
57type HumidityDriver = components::humidity::HumidityComponentType<SI7021Sensor>;
58type RngDriver = components::rng::RngComponentType<sam4l::trng::Trng<'static>>;
59
60/// A structure representing this platform that holds references to all
61/// capsules for this platform.
62struct Hail {
63    console: &'static capsules_core::console::Console<'static>,
64    gpio: &'static capsules_core::gpio::GPIO<'static, sam4l::gpio::GPIOPin<'static>>,
65    alarm: &'static capsules_core::alarm::AlarmDriver<
66        'static,
67        capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<
68            'static,
69            sam4l::ast::Ast<'static>,
70        >,
71    >,
72    ambient_light: &'static capsules_extra::ambient_light::AmbientLight<'static>,
73    temp: &'static TemperatureDriver,
74    ninedof: &'static capsules_extra::ninedof::NineDof<'static>,
75    humidity: &'static HumidityDriver,
76    spi: &'static capsules_core::spi_controller::Spi<
77        'static,
78        capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<
79            'static,
80            sam4l::spi::SpiHw<'static>,
81        >,
82    >,
83    nrf51822: &'static capsules_extra::nrf51822_serialization::Nrf51822Serialization<'static>,
84    adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc<'static>>,
85    led: &'static capsules_core::led::LedDriver<
86        'static,
87        LedLow<'static, sam4l::gpio::GPIOPin<'static>>,
88        3,
89    >,
90    button: &'static capsules_core::button::Button<'static, sam4l::gpio::GPIOPin<'static>>,
91    rng: &'static RngDriver,
92    ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
93    crc: &'static capsules_extra::crc::CrcDriver<'static, sam4l::crccu::Crccu<'static>>,
94    dac: &'static capsules_extra::dac::Dac<'static>,
95    scheduler: &'static RoundRobinSched<'static>,
96    systick: cortexm4::systick::SysTick,
97}
98
99/// Mapping of integer syscalls to objects that implement syscalls.
100impl SyscallDriverLookup for Hail {
101    fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
102    where
103        F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
104    {
105        match driver_num {
106            capsules_core::console::DRIVER_NUM => f(Some(self.console)),
107            capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
108
109            capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
110            capsules_core::spi_controller::DRIVER_NUM => f(Some(self.spi)),
111            capsules_extra::nrf51822_serialization::DRIVER_NUM => f(Some(self.nrf51822)),
112            capsules_extra::ambient_light::DRIVER_NUM => f(Some(self.ambient_light)),
113            capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
114            capsules_core::led::DRIVER_NUM => f(Some(self.led)),
115            capsules_core::button::DRIVER_NUM => f(Some(self.button)),
116            capsules_extra::humidity::DRIVER_NUM => f(Some(self.humidity)),
117            capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
118            capsules_extra::ninedof::DRIVER_NUM => f(Some(self.ninedof)),
119
120            capsules_core::rng::DRIVER_NUM => f(Some(self.rng)),
121
122            capsules_extra::crc::DRIVER_NUM => f(Some(self.crc)),
123
124            capsules_extra::dac::DRIVER_NUM => f(Some(self.dac)),
125
126            kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
127            _ => f(None),
128        }
129    }
130}
131
132impl KernelResources<sam4l::chip::Sam4l<Sam4lDefaultPeripherals>> for Hail {
133    type SyscallDriverLookup = Self;
134    type SyscallFilter = ();
135    type ProcessFault = ();
136    type Scheduler = RoundRobinSched<'static>;
137    type SchedulerTimer = cortexm4::systick::SysTick;
138    type WatchDog = ();
139    type ContextSwitchCallback = ();
140
141    fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
142        self
143    }
144    fn syscall_filter(&self) -> &Self::SyscallFilter {
145        &()
146    }
147    fn process_fault(&self) -> &Self::ProcessFault {
148        &()
149    }
150    fn scheduler(&self) -> &Self::Scheduler {
151        self.scheduler
152    }
153    fn scheduler_timer(&self) -> &Self::SchedulerTimer {
154        &self.systick
155    }
156    fn watchdog(&self) -> &Self::WatchDog {
157        &()
158    }
159    fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
160        &()
161    }
162}
163
164/// Helper function called during bring-up that configures multiplexed I/O.
165unsafe fn set_pin_primary_functions(peripherals: &Sam4lDefaultPeripherals) {
166    use sam4l::gpio::PeripheralFunction::{A, B};
167
168    peripherals.pa[04].configure(Some(A)); // A0 - ADC0
169    peripherals.pa[05].configure(Some(A)); // A1 - ADC1
170                                           // DAC/WKP mode
171    peripherals.pa[06].configure(Some(A)); // DAC
172    peripherals.pa[07].configure(None); //... WKP - Wakeup
173                                        // // Analog Comparator Mode
174                                        // peripherals.pa[06].configure(Some(E)); // ACAN0 - ACIFC
175                                        // peripherals.pa[07].configure(Some(E)); // ACAP0 - ACIFC
176    peripherals.pa[08].configure(Some(A)); // FTDI_RTS - USART0 RTS
177    peripherals.pa[09].configure(None); //... ACC_INT1 - FXOS8700CQ Interrupt 1
178    peripherals.pa[10].configure(None); //... unused
179    peripherals.pa[11].configure(Some(A)); // FTDI_OUT - USART0 RX FTDI->SAM4L
180    peripherals.pa[12].configure(Some(A)); // FTDI_IN - USART0 TX SAM4L->FTDI
181    peripherals.pa[13].configure(None); //... RED_LED
182    peripherals.pa[14].configure(None); //... BLUE_LED
183    peripherals.pa[15].configure(None); //... GREEN_LED
184    peripherals.pa[16].configure(None); //... BUTTON - User Button
185    peripherals.pa[17].configure(None); //... !NRF_RESET - Reset line for nRF51822
186    peripherals.pa[18].configure(None); //... ACC_INT2 - FXOS8700CQ Interrupt 2
187    peripherals.pa[19].configure(None); //... unused
188    peripherals.pa[20].configure(None); //... !LIGHT_INT - ISL29035 Light Sensor Interrupt
189                                        // SPI Mode
190    peripherals.pa[21].configure(Some(A)); // D3 - SPI MISO
191    peripherals.pa[22].configure(Some(A)); // D2 - SPI MOSI
192    peripherals.pa[23].configure(Some(A)); // D4 - SPI SCK
193    peripherals.pa[24].configure(Some(A)); // D5 - SPI CS0
194                                           // // I2C Mode
195                                           // peripherals.pa[21].configure(None); // D3
196                                           // peripherals.pa[22].configure(None); // D2
197                                           // peripherals.pa[23].configure(Some(B)); // D4 - TWIMS0 SDA
198                                           // peripherals.pa[24].configure(Some(B)); // D5 - TWIMS0 SCL
199                                           // UART Mode
200    peripherals.pa[25].configure(Some(B)); // RX - USART2 RXD
201    peripherals.pa[26].configure(Some(B)); // TX - USART2 TXD
202
203    peripherals.pb[00].configure(Some(A)); // SENSORS_SDA - TWIMS1 SDA
204    peripherals.pb[01].configure(Some(A)); // SENSORS_SCL - TWIMS1 SCL
205                                           // ADC Mode
206    peripherals.pb[02].configure(Some(A)); // A2 - ADC3
207    peripherals.pb[03].configure(Some(A)); // A3 - ADC4
208                                           // // Analog Comparator Mode
209                                           // peripherals.pb[02].configure(Some(E)); // ACBN0 - ACIFC
210                                           // peripherals.pb[03].configure(Some(E)); // ACBP0 - ACIFC
211    peripherals.pb[04].configure(Some(A)); // A4 - ADC5
212    peripherals.pb[05].configure(Some(A)); // A5 - ADC6
213    peripherals.pb[06].configure(Some(A)); // NRF_CTS - USART3 RTS
214    peripherals.pb[07].configure(Some(A)); // NRF_RTS - USART3 CTS
215    peripherals.pb[08].configure(None); //... NRF_INT - Interrupt line nRF->SAM4L
216    peripherals.pb[09].configure(Some(A)); // NRF_OUT - USART3 RXD
217    peripherals.pb[10].configure(Some(A)); // NRF_IN - USART3 TXD
218    peripherals.pb[11].configure(None); //... D6
219    peripherals.pb[12].configure(None); //... D7
220    peripherals.pb[13].configure(None); //... unused
221    peripherals.pb[14].configure(None); //... D0
222    peripherals.pb[15].configure(None); //... D1
223}
224
225/// This is in a separate, inline(never) function so that its stack frame is
226/// removed when this function returns. Otherwise, the stack space used for
227/// these static_inits is wasted.
228#[inline(never)]
229unsafe fn start() -> (
230    &'static kernel::Kernel,
231    Hail,
232    &'static sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
233) {
234    sam4l::init();
235
236    let pm = static_init!(sam4l::pm::PowerManager, sam4l::pm::PowerManager::new());
237    let peripherals = static_init!(Sam4lDefaultPeripherals, Sam4lDefaultPeripherals::new(pm));
238
239    pm.setup_system_clock(
240        sam4l::pm::SystemClockSource::PllExternalOscillatorAt48MHz {
241            frequency: sam4l::pm::OscillatorFrequency::Frequency16MHz,
242            startup_mode: sam4l::pm::OscillatorStartup::SlowStart,
243        },
244        &peripherals.flash_controller,
245    );
246
247    // Source 32Khz and 1Khz clocks from RC23K (SAM4L Datasheet 11.6.8)
248    sam4l::bpm::set_ck32source(sam4l::bpm::CK32Source::RC32K);
249
250    set_pin_primary_functions(peripherals);
251    peripherals.setup_circular_deps();
252    let chip = static_init!(
253        sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
254        sam4l::chip::Sam4l::new(pm, peripherals)
255    );
256    CHIP = Some(chip);
257
258    // Create capabilities that the board needs to call certain protected kernel
259    // functions.
260    let process_management_capability =
261        create_capability!(capabilities::ProcessManagementCapability);
262    let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
263
264    // Configure kernel debug gpios as early as possible
265    kernel::debug::assign_gpios(
266        Some(&peripherals.pa[13]),
267        Some(&peripherals.pa[15]),
268        Some(&peripherals.pa[14]),
269    );
270
271    let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
272
273    let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
274        .finalize(components::process_printer_text_component_static!());
275    PROCESS_PRINTER = Some(process_printer);
276
277    // Initialize USART0 for Uart
278    peripherals.usart0.set_mode(sam4l::usart::UsartMode::Uart);
279
280    // Create a shared UART channel for the console and for kernel debug.
281    let uart_mux = components::console::UartMuxComponent::new(&peripherals.usart0, 115200)
282        .finalize(components::uart_mux_component_static!());
283    uart_mux.initialize();
284
285    hil::uart::Transmit::set_transmit_client(&peripherals.usart0, uart_mux);
286    hil::uart::Receive::set_receive_client(&peripherals.usart0, uart_mux);
287
288    let mux_alarm = components::alarm::AlarmMuxComponent::new(&peripherals.ast)
289        .finalize(components::alarm_mux_component_static!(sam4l::ast::Ast));
290    peripherals.ast.configure(mux_alarm);
291
292    // Setup the console and the process inspection console.
293    let console = components::console::ConsoleComponent::new(
294        board_kernel,
295        capsules_core::console::DRIVER_NUM,
296        uart_mux,
297    )
298    .finalize(components::console_component_static!());
299    let process_console = components::process_console::ProcessConsoleComponent::new(
300        board_kernel,
301        uart_mux,
302        mux_alarm,
303        process_printer,
304        Some(cortexm4::support::reset),
305    )
306    .finalize(components::process_console_component_static!(
307        sam4l::ast::Ast<'static>
308    ));
309    components::debug_writer::DebugWriterComponent::new(
310        uart_mux,
311        create_capability!(capabilities::SetDebugWriterCapability),
312    )
313    .finalize(components::debug_writer_component_static!());
314
315    // Initialize USART3 for UART for the nRF serialization link.
316    peripherals.usart3.set_mode(sam4l::usart::UsartMode::Uart);
317    // Create the Nrf51822Serialization driver for passing BLE commands
318    // over UART to the nRF51822 radio.
319    let nrf_serialization = components::nrf51822::Nrf51822Component::new(
320        board_kernel,
321        capsules_extra::nrf51822_serialization::DRIVER_NUM,
322        &peripherals.usart3,
323        &peripherals.pa[17],
324    )
325    .finalize(components::nrf51822_component_static!());
326
327    let sensors_i2c = components::i2c::I2CMuxComponent::new(&peripherals.i2c1, None)
328        .finalize(components::i2c_mux_component_static!(sam4l::i2c::I2CHw));
329
330    // SI7021 Temperature / Humidity Sensor, address: 0x40
331    let si7021 = components::si7021::SI7021Component::new(sensors_i2c, mux_alarm, 0x40).finalize(
332        components::si7021_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw),
333    );
334    let temp = components::temperature::TemperatureComponent::new(
335        board_kernel,
336        capsules_extra::temperature::DRIVER_NUM,
337        si7021,
338    )
339    .finalize(components::temperature_component_static!(SI7021Sensor));
340    let humidity = components::humidity::HumidityComponent::new(
341        board_kernel,
342        capsules_extra::humidity::DRIVER_NUM,
343        si7021,
344    )
345    .finalize(components::humidity_component_static!(SI7021Sensor));
346
347    // Configure the ISL29035, device address 0x44
348    let isl29035 = components::isl29035::Isl29035Component::new(sensors_i2c, mux_alarm).finalize(
349        components::isl29035_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw),
350    );
351    let ambient_light = components::isl29035::AmbientLightComponent::new(
352        board_kernel,
353        capsules_extra::ambient_light::DRIVER_NUM,
354        isl29035,
355    )
356    .finalize(components::ambient_light_component_static!());
357
358    // Alarm
359    let alarm = components::alarm::AlarmDriverComponent::new(
360        board_kernel,
361        capsules_core::alarm::DRIVER_NUM,
362        mux_alarm,
363    )
364    .finalize(components::alarm_component_static!(sam4l::ast::Ast));
365
366    // FXOS8700CQ accelerometer, device address 0x1e
367    let fxos8700 =
368        components::fxos8700::Fxos8700Component::new(sensors_i2c, 0x1e, &peripherals.pa[9])
369            .finalize(components::fxos8700_component_static!(sam4l::i2c::I2CHw));
370
371    let ninedof = components::ninedof::NineDofComponent::new(
372        board_kernel,
373        capsules_extra::ninedof::DRIVER_NUM,
374    )
375    .finalize(components::ninedof_component_static!(fxos8700));
376
377    // SPI
378    // Set up a SPI MUX, so there can be multiple clients.
379    let mux_spi = components::spi::SpiMuxComponent::new(&peripherals.spi)
380        .finalize(components::spi_mux_component_static!(sam4l::spi::SpiHw));
381    // Create the SPI system call capsule.
382    let spi_syscalls = components::spi::SpiSyscallComponent::new(
383        board_kernel,
384        mux_spi,
385        sam4l::spi::Peripheral::Peripheral0,
386        capsules_core::spi_controller::DRIVER_NUM,
387    )
388    .finalize(components::spi_syscall_component_static!(sam4l::spi::SpiHw));
389
390    // LEDs
391    let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
392        LedLow<'static, sam4l::gpio::GPIOPin>,
393        LedLow::new(&peripherals.pa[13]), // Red
394        LedLow::new(&peripherals.pa[15]), // Green
395        LedLow::new(&peripherals.pa[14]), // Blue
396    ));
397
398    // BUTTONs
399    let button = components::button::ButtonComponent::new(
400        board_kernel,
401        capsules_core::button::DRIVER_NUM,
402        components::button_component_helper!(
403            sam4l::gpio::GPIOPin,
404            (
405                &peripherals.pa[16],
406                kernel::hil::gpio::ActivationMode::ActiveLow,
407                kernel::hil::gpio::FloatingState::PullNone
408            )
409        ),
410    )
411    .finalize(components::button_component_static!(sam4l::gpio::GPIOPin));
412
413    // Setup ADC
414    let adc_channels = static_init!(
415        [sam4l::adc::AdcChannel; 6],
416        [
417            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD0), // A0
418            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD1), // A1
419            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD3), // A2
420            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD4), // A3
421            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD5), // A4
422            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD6), // A5
423        ]
424    );
425    let adc = components::adc::AdcDedicatedComponent::new(
426        &peripherals.adc,
427        adc_channels,
428        board_kernel,
429        capsules_core::adc::DRIVER_NUM,
430    )
431    .finalize(components::adc_dedicated_component_static!(sam4l::adc::Adc));
432
433    // Setup RNG
434    let rng = components::rng::RngComponent::new(
435        board_kernel,
436        capsules_core::rng::DRIVER_NUM,
437        &peripherals.trng,
438    )
439    .finalize(components::rng_component_static!(sam4l::trng::Trng));
440
441    // set GPIO driver controlling remaining GPIO pins
442    let gpio = components::gpio::GpioComponent::new(
443        board_kernel,
444        capsules_core::gpio::DRIVER_NUM,
445        components::gpio_component_helper!(
446            sam4l::gpio::GPIOPin,
447            0 => &peripherals.pb[14], // D0
448            1 => &peripherals.pb[15], // D1
449            2 => &peripherals.pb[11], // D6
450            3 => &peripherals.pb[12]  // D7
451        ),
452    )
453    .finalize(components::gpio_component_static!(sam4l::gpio::GPIOPin));
454
455    // CRC
456    let crc = components::crc::CrcComponent::new(
457        board_kernel,
458        capsules_extra::crc::DRIVER_NUM,
459        &peripherals.crccu,
460    )
461    .finalize(components::crc_component_static!(sam4l::crccu::Crccu));
462
463    // DAC
464    let dac = components::dac::DacComponent::new(&peripherals.dac)
465        .finalize(components::dac_component_static!());
466
467    // // DEBUG Restart All Apps
468    // //
469    // // Uncomment to enable a button press to restart all apps.
470    // //
471    // // Create a dummy object that provides the `ProcessManagementCapability` to
472    // // the `debug_process_restart` capsule.
473    // struct ProcessMgmtCap;
474    // unsafe impl capabilities::ProcessManagementCapability for ProcessMgmtCap {}
475    // let debug_process_restart = static_init!(
476    //     capsules_core::debug_process_restart::DebugProcessRestart<
477    //         ProcessMgmtCap,
478    //     >,
479    //     capsules_core::debug_process_restart::DebugProcessRestart::new(
480    //         board_kernel,
481    //         &peripherals.pa[16],
482    //         ProcessMgmtCap
483    //     )
484    // );
485    // peripherals.pa[16].set_client(debug_process_restart);
486
487    // Configure application fault policy
488    let fault_policy = static_init!(
489        capsules_system::process_policies::ThresholdRestartThenPanicFaultPolicy,
490        capsules_system::process_policies::ThresholdRestartThenPanicFaultPolicy::new(4)
491    );
492
493    let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
494        .finalize(components::round_robin_component_static!(NUM_PROCS));
495
496    let hail = Hail {
497        console,
498        gpio,
499        alarm,
500        ambient_light,
501        temp,
502        humidity,
503        ninedof,
504        spi: spi_syscalls,
505        nrf51822: nrf_serialization,
506        adc,
507        led,
508        button,
509        rng,
510        ipc: kernel::ipc::IPC::new(
511            board_kernel,
512            kernel::ipc::DRIVER_NUM,
513            &memory_allocation_capability,
514        ),
515        crc,
516        dac,
517        scheduler,
518        systick: cortexm4::systick::SysTick::new(),
519    };
520
521    // Setup the UART bus for nRF51 serialization..
522    hail.nrf51822.initialize();
523
524    let _ = process_console.start();
525
526    // Uncomment to measure overheads for TakeCell and MapCell:
527    // test_take_map_cell::test_take_map_cell();
528
529    debug!("Initialization complete. Entering main loop.");
530
531    // These symbols are defined in the linker script.
532    extern "C" {
533        /// Beginning of the ROM region containing app images.
534        static _sapps: u8;
535        /// End of the ROM region containing app images.
536        static _eapps: u8;
537        /// Beginning of the RAM region for app memory.
538        static mut _sappmem: u8;
539        /// End of the RAM region for app memory.
540        static _eappmem: u8;
541    }
542
543    kernel::process::load_processes(
544        board_kernel,
545        chip,
546        core::slice::from_raw_parts(
547            core::ptr::addr_of!(_sapps),
548            core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
549        ),
550        core::slice::from_raw_parts_mut(
551            core::ptr::addr_of_mut!(_sappmem),
552            core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
553        ),
554        &mut *addr_of_mut!(PROCESSES),
555        fault_policy,
556        &process_management_capability,
557    )
558    .unwrap_or_else(|err| {
559        debug!("Error loading processes!");
560        debug!("{:?}", err);
561    });
562
563    (board_kernel, hail, chip)
564}
565
566/// Main function called after RAM initialized.
567#[no_mangle]
568pub unsafe fn main() {
569    let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
570
571    let (board_kernel, platform, chip) = start();
572    board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
573}