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