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