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::debug::PanicResources;
17use kernel::hil;
18use kernel::hil::led::LedLow;
19use kernel::hil::Controller;
20use kernel::platform::{KernelResources, SyscallDriverLookup};
21use kernel::scheduler::round_robin::RoundRobinSched;
22use kernel::utilities::single_thread_value::SingleThreadValue;
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
39type ChipHw = sam4l::chip::Sam4l<Sam4lDefaultPeripherals>;
40type ProcessPrinterInUse = capsules_system::process_printer::ProcessPrinterText;
41
42/// Resources for when a board panics used by io.rs.
43static PANIC_RESOURCES: SingleThreadValue<PanicResources<ChipHw, ProcessPrinterInUse>> =
44    SingleThreadValue::new(PanicResources::new());
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    // Initialize deferred calls very early.
233    kernel::deferred_call::initialize_deferred_call_state::<
234        <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
235    >();
236
237    // Bind global variables to this thread.
238    PANIC_RESOURCES.bind_to_thread::<<ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider>();
239
240    let pm = static_init!(sam4l::pm::PowerManager, sam4l::pm::PowerManager::new());
241    let peripherals = static_init!(Sam4lDefaultPeripherals, Sam4lDefaultPeripherals::new(pm));
242
243    pm.setup_system_clock(
244        sam4l::pm::SystemClockSource::PllExternalOscillatorAt48MHz {
245            frequency: sam4l::pm::OscillatorFrequency::Frequency16MHz,
246            startup_mode: sam4l::pm::OscillatorStartup::SlowStart,
247        },
248        &peripherals.flash_controller,
249    );
250
251    // Source 32Khz and 1Khz clocks from RC23K (SAM4L Datasheet 11.6.8)
252    sam4l::bpm::set_ck32source(sam4l::bpm::CK32Source::RC32K);
253
254    set_pin_primary_functions(peripherals);
255    peripherals.setup_circular_deps();
256    let chip = static_init!(
257        sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
258        sam4l::chip::Sam4l::new(pm, peripherals)
259    );
260    PANIC_RESOURCES.get().map(|resources| {
261        resources.chip.put(chip);
262    });
263
264    // Create capabilities that the board needs to call certain protected kernel
265    // functions.
266    let process_management_capability =
267        create_capability!(capabilities::ProcessManagementCapability);
268    let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
269
270    // Configure kernel debug gpios as early as possible
271    let debug_gpios = static_init!(
272        [&'static dyn kernel::hil::gpio::Pin; 3],
273        [
274            &peripherals.pa[13],
275            &peripherals.pa[14],
276            &peripherals.pa[15],
277        ]
278    );
279    kernel::debug::initialize_debug_gpio::<
280        <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
281    >();
282    kernel::debug::assign_gpios(debug_gpios);
283
284    // Create an array to hold process references.
285    let processes = components::process_array::ProcessArrayComponent::new()
286        .finalize(components::process_array_component_static!(NUM_PROCS));
287    PANIC_RESOURCES.get().map(|resources| {
288        resources.processes.put(processes.as_slice());
289    });
290
291    // Setup space to store the core kernel data structure.
292    let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
293
294    let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
295        .finalize(components::process_printer_text_component_static!());
296    PANIC_RESOURCES.get().map(|resources| {
297        resources.printer.put(process_printer);
298    });
299
300    // Initialize USART0 for Uart
301    peripherals.usart0.set_mode(sam4l::usart::UsartMode::Uart);
302
303    // Create a shared UART channel for the console and for kernel debug.
304    let uart_mux = components::console::UartMuxComponent::new(&peripherals.usart0, 115200)
305        .finalize(components::uart_mux_component_static!());
306    uart_mux.initialize();
307
308    hil::uart::Transmit::set_transmit_client(&peripherals.usart0, uart_mux);
309    hil::uart::Receive::set_receive_client(&peripherals.usart0, uart_mux);
310
311    let mux_alarm = components::alarm::AlarmMuxComponent::new(&peripherals.ast)
312        .finalize(components::alarm_mux_component_static!(sam4l::ast::Ast));
313    peripherals.ast.configure(mux_alarm);
314
315    // Setup the console and the process inspection console.
316    let console = components::console::ConsoleComponent::new(
317        board_kernel,
318        capsules_core::console::DRIVER_NUM,
319        uart_mux,
320    )
321    .finalize(components::console_component_static!());
322    let process_console = components::process_console::ProcessConsoleComponent::new(
323        board_kernel,
324        uart_mux,
325        mux_alarm,
326        process_printer,
327        Some(cortexm4::support::reset),
328    )
329    .finalize(components::process_console_component_static!(
330        sam4l::ast::Ast<'static>
331    ));
332    components::debug_writer::DebugWriterComponent::new::<
333        <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
334    >(
335        uart_mux,
336        create_capability!(capabilities::SetDebugWriterCapability),
337    )
338    .finalize(components::debug_writer_component_static!());
339
340    // Initialize USART3 for UART for the nRF serialization link.
341    peripherals.usart3.set_mode(sam4l::usart::UsartMode::Uart);
342    // Create the Nrf51822Serialization driver for passing BLE commands
343    // over UART to the nRF51822 radio.
344    let nrf_serialization = components::nrf51822::Nrf51822Component::new(
345        board_kernel,
346        capsules_extra::nrf51822_serialization::DRIVER_NUM,
347        &peripherals.usart3,
348        &peripherals.pa[17],
349    )
350    .finalize(components::nrf51822_component_static!());
351
352    let sensors_i2c = components::i2c::I2CMuxComponent::new(&peripherals.i2c1, None)
353        .finalize(components::i2c_mux_component_static!(sam4l::i2c::I2CHw));
354
355    // SI7021 Temperature / Humidity Sensor, address: 0x40
356    let si7021 = components::si7021::SI7021Component::new(sensors_i2c, mux_alarm, 0x40).finalize(
357        components::si7021_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw),
358    );
359    let temp = components::temperature::TemperatureComponent::new(
360        board_kernel,
361        capsules_extra::temperature::DRIVER_NUM,
362        si7021,
363    )
364    .finalize(components::temperature_component_static!(SI7021Sensor));
365    let humidity = components::humidity::HumidityComponent::new(
366        board_kernel,
367        capsules_extra::humidity::DRIVER_NUM,
368        si7021,
369    )
370    .finalize(components::humidity_component_static!(SI7021Sensor));
371
372    // Configure the ISL29035, device address 0x44
373    let isl29035 = components::isl29035::Isl29035Component::new(sensors_i2c, mux_alarm).finalize(
374        components::isl29035_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw),
375    );
376    let ambient_light = components::isl29035::AmbientLightComponent::new(
377        board_kernel,
378        capsules_extra::ambient_light::DRIVER_NUM,
379        isl29035,
380    )
381    .finalize(components::ambient_light_component_static!());
382
383    // Alarm
384    let alarm = components::alarm::AlarmDriverComponent::new(
385        board_kernel,
386        capsules_core::alarm::DRIVER_NUM,
387        mux_alarm,
388    )
389    .finalize(components::alarm_component_static!(sam4l::ast::Ast));
390
391    // FXOS8700CQ accelerometer, device address 0x1e
392    let fxos8700 =
393        components::fxos8700::Fxos8700Component::new(sensors_i2c, 0x1e, &peripherals.pa[9])
394            .finalize(components::fxos8700_component_static!(sam4l::i2c::I2CHw));
395
396    let ninedof = components::ninedof::NineDofComponent::new(
397        board_kernel,
398        capsules_extra::ninedof::DRIVER_NUM,
399    )
400    .finalize(components::ninedof_component_static!(fxos8700));
401
402    // SPI
403    // Set up a SPI MUX, so there can be multiple clients.
404    let mux_spi = components::spi::SpiMuxComponent::new(&peripherals.spi)
405        .finalize(components::spi_mux_component_static!(sam4l::spi::SpiHw));
406    // Create the SPI system call capsule.
407    let spi_syscalls = components::spi::SpiSyscallComponent::new(
408        board_kernel,
409        mux_spi,
410        sam4l::spi::Peripheral::Peripheral0,
411        capsules_core::spi_controller::DRIVER_NUM,
412    )
413    .finalize(components::spi_syscall_component_static!(sam4l::spi::SpiHw));
414
415    // LEDs
416    let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
417        LedLow<'static, sam4l::gpio::GPIOPin>,
418        LedLow::new(&peripherals.pa[13]), // Red
419        LedLow::new(&peripherals.pa[15]), // Green
420        LedLow::new(&peripherals.pa[14]), // Blue
421    ));
422
423    // BUTTONs
424    let button = components::button::ButtonComponent::new(
425        board_kernel,
426        capsules_core::button::DRIVER_NUM,
427        components::button_component_helper!(
428            sam4l::gpio::GPIOPin,
429            (
430                &peripherals.pa[16],
431                kernel::hil::gpio::ActivationMode::ActiveLow,
432                kernel::hil::gpio::FloatingState::PullNone
433            )
434        ),
435    )
436    .finalize(components::button_component_static!(sam4l::gpio::GPIOPin));
437
438    // Setup ADC
439    let adc_channels = static_init!(
440        [sam4l::adc::AdcChannel; 6],
441        [
442            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD0), // A0
443            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD1), // A1
444            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD3), // A2
445            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD4), // A3
446            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD5), // A4
447            sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD6), // A5
448        ]
449    );
450    let adc = components::adc::AdcDedicatedComponent::new(
451        &peripherals.adc,
452        adc_channels,
453        board_kernel,
454        capsules_core::adc::DRIVER_NUM,
455    )
456    .finalize(components::adc_dedicated_component_static!(sam4l::adc::Adc));
457
458    // Setup RNG
459    let rng = components::rng::RngComponent::new(
460        board_kernel,
461        capsules_core::rng::DRIVER_NUM,
462        &peripherals.trng,
463    )
464    .finalize(components::rng_component_static!(sam4l::trng::Trng));
465
466    // set GPIO driver controlling remaining GPIO pins
467    let gpio = components::gpio::GpioComponent::new(
468        board_kernel,
469        capsules_core::gpio::DRIVER_NUM,
470        components::gpio_component_helper!(
471            sam4l::gpio::GPIOPin,
472            0 => &peripherals.pb[14], // D0
473            1 => &peripherals.pb[15], // D1
474            2 => &peripherals.pb[11], // D6
475            3 => &peripherals.pb[12]  // D7
476        ),
477    )
478    .finalize(components::gpio_component_static!(sam4l::gpio::GPIOPin));
479
480    // CRC
481    let crc = components::crc::CrcComponent::new(
482        board_kernel,
483        capsules_extra::crc::DRIVER_NUM,
484        &peripherals.crccu,
485    )
486    .finalize(components::crc_component_static!(sam4l::crccu::Crccu));
487
488    // DAC
489    let dac = components::dac::DacComponent::new(&peripherals.dac)
490        .finalize(components::dac_component_static!());
491
492    // // DEBUG Restart All Apps
493    // //
494    // // Uncomment to enable a button press to restart all apps.
495    // //
496    // // Create a dummy object that provides the `ProcessManagementCapability` to
497    // // the `debug_process_restart` capsule.
498    // struct ProcessMgmtCap;
499    // unsafe impl capabilities::ProcessManagementCapability for ProcessMgmtCap {}
500    // let debug_process_restart = static_init!(
501    //     capsules_core::debug_process_restart::DebugProcessRestart<
502    //         ProcessMgmtCap,
503    //     >,
504    //     capsules_core::debug_process_restart::DebugProcessRestart::new(
505    //         board_kernel,
506    //         &peripherals.pa[16],
507    //         ProcessMgmtCap
508    //     )
509    // );
510    // peripherals.pa[16].set_client(debug_process_restart);
511
512    // Configure application fault policy
513    let fault_policy = static_init!(
514        capsules_system::process_policies::ThresholdRestartThenPanicFaultPolicy,
515        capsules_system::process_policies::ThresholdRestartThenPanicFaultPolicy::new(4)
516    );
517
518    let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
519        .finalize(components::round_robin_component_static!(NUM_PROCS));
520
521    let hail = Hail {
522        console,
523        gpio,
524        alarm,
525        ambient_light,
526        temp,
527        humidity,
528        ninedof,
529        spi: spi_syscalls,
530        nrf51822: nrf_serialization,
531        adc,
532        led,
533        button,
534        rng,
535        ipc: kernel::ipc::IPC::new(
536            board_kernel,
537            kernel::ipc::DRIVER_NUM,
538            &memory_allocation_capability,
539        ),
540        crc,
541        dac,
542        scheduler,
543        systick: cortexm4::systick::SysTick::new(),
544    };
545
546    // Setup the UART bus for nRF51 serialization..
547    hail.nrf51822.initialize();
548
549    let _ = process_console.start();
550
551    // Uncomment to measure overheads for TakeCell and MapCell:
552    // test_take_map_cell::test_take_map_cell();
553
554    debug!("Initialization complete. Entering main loop.");
555
556    // These symbols are defined in the linker script.
557    extern "C" {
558        /// Beginning of the ROM region containing app images.
559        static _sapps: u8;
560        /// End of the ROM region containing app images.
561        static _eapps: u8;
562        /// Beginning of the RAM region for app memory.
563        static mut _sappmem: u8;
564        /// End of the RAM region for app memory.
565        static _eappmem: u8;
566    }
567
568    kernel::process::load_processes(
569        board_kernel,
570        chip,
571        core::slice::from_raw_parts(
572            core::ptr::addr_of!(_sapps),
573            core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
574        ),
575        core::slice::from_raw_parts_mut(
576            core::ptr::addr_of_mut!(_sappmem),
577            core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
578        ),
579        fault_policy,
580        &process_management_capability,
581    )
582    .unwrap_or_else(|err| {
583        debug!("Error loading processes!");
584        debug!("{:?}", err);
585    });
586
587    (board_kernel, hail, chip)
588}
589
590/// Main function called after RAM initialized.
591#[no_mangle]
592pub unsafe fn main() {
593    let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
594
595    let (board_kernel, platform, chip) = start();
596    board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
597}