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