1#![no_std]
11#![cfg_attr(not(doc), no_main)]
14#![deny(missing_docs)]
15
16mod imix_components;
17use core::ptr::{addr_of, addr_of_mut};
18
19use capsules_core::alarm::AlarmDriver;
20use capsules_core::console_ordered::ConsoleOrdered;
21use capsules_core::virtualizers::virtual_aes_ccm::MuxAES128CCM;
22use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
23use capsules_core::virtualizers::virtual_i2c::MuxI2C;
24use capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice;
25use capsules_extra::net::ieee802154::MacAddress;
26use capsules_extra::net::ipv6::ip_utils::IPAddr;
27use kernel::capabilities;
28use kernel::component::Component;
29use kernel::deferred_call::DeferredCallClient;
30use kernel::hil::i2c::I2CMaster;
31use kernel::hil::radio;
32#[allow(unused_imports)]
33use kernel::hil::radio::{RadioConfig, RadioData};
34use kernel::hil::symmetric_encryption::AES128;
35use kernel::platform::{KernelResources, SyscallDriverLookup};
36use kernel::scheduler::round_robin::RoundRobinSched;
37
38use kernel::hil::led::LedHigh;
40use kernel::hil::Controller;
41#[allow(unused_imports)]
42use kernel::{create_capability, debug, debug_gpio, static_buf, static_init};
43use sam4l::chip::Sam4lDefaultPeripherals;
44
45use components::alarm::{AlarmDriverComponent, AlarmMuxComponent};
46use components::console::{ConsoleOrderedComponent, UartMuxComponent};
47use components::crc::CrcComponent;
48use components::debug_writer::DebugWriterComponent;
49use components::gpio::GpioComponent;
50use components::isl29035::AmbientLightComponent;
51use components::isl29035::Isl29035Component;
52use components::led::LedsComponent;
53use components::nrf51822::Nrf51822Component;
54use components::process_console::ProcessConsoleComponent;
55use components::rng::RngComponent;
56use components::si7021::SI7021Component;
57use components::spi::{SpiComponent, SpiSyscallComponent};
58
59pub mod io;
63
64#[allow(dead_code)]
66mod test;
67
68mod power;
70
71#[allow(dead_code)]
72mod alarm_test;
73
74#[allow(dead_code)]
75mod multi_timer_test;
76
77const NUM_PROCS: usize = 4;
80
81const RADIO_CHANNEL: radio::RadioChannel = radio::RadioChannel::Channel26;
90const DST_MAC_ADDR: MacAddress = MacAddress::Short(49138);
91const DEFAULT_CTX_PREFIX_LEN: u8 = 8; const DEFAULT_CTX_PREFIX: [u8; 16] = [0x0_u8; 16]; const PAN_ID: u16 = 0xABCD;
94
95const FAULT_RESPONSE: capsules_system::process_policies::StopFaultPolicy =
97 capsules_system::process_policies::StopFaultPolicy {};
98
99static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
100 [None; NUM_PROCS];
101
102static mut CHIP: Option<&'static sam4l::chip::Sam4l<Sam4lDefaultPeripherals>> = None;
103static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
104 None;
105
106#[no_mangle]
108#[link_section = ".stack_buffer"]
109pub static mut STACK_MEMORY: [u8; 0x2000] = [0; 0x2000];
110
111type SI7021Sensor = components::si7021::SI7021ComponentType<
112 capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>,
113 capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, sam4l::i2c::I2CHw<'static>>,
114>;
115type TemperatureDriver = components::temperature::TemperatureComponentType<SI7021Sensor>;
116type HumidityDriver = components::humidity::HumidityComponentType<SI7021Sensor>;
117type RngDriver = components::rng::RngComponentType<sam4l::trng::Trng<'static>>;
118
119type Rf233 = capsules_extra::rf233::RF233<
120 'static,
121 VirtualSpiMasterDevice<'static, sam4l::spi::SpiHw<'static>>,
122>;
123type Ieee802154MacDevice =
124 components::ieee802154::Ieee802154ComponentMacDeviceType<Rf233, sam4l::aes::Aes<'static>>;
125
126struct Imix {
127 pconsole: &'static capsules_core::process_console::ProcessConsole<
128 'static,
129 { capsules_core::process_console::DEFAULT_COMMAND_HISTORY_LEN },
130 capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<
131 'static,
132 sam4l::ast::Ast<'static>,
133 >,
134 components::process_console::Capability,
135 >,
136 console: &'static capsules_core::console_ordered::ConsoleOrdered<
137 'static,
138 VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>,
139 >,
140 gpio: &'static capsules_core::gpio::GPIO<'static, sam4l::gpio::GPIOPin<'static>>,
141 alarm: &'static AlarmDriver<'static, VirtualMuxAlarm<'static, sam4l::ast::Ast<'static>>>,
142 temp: &'static TemperatureDriver,
143 humidity: &'static HumidityDriver,
144 ambient_light: &'static capsules_extra::ambient_light::AmbientLight<'static>,
145 adc: &'static capsules_core::adc::AdcDedicated<'static, sam4l::adc::Adc<'static>>,
146 led: &'static capsules_core::led::LedDriver<
147 'static,
148 LedHigh<'static, sam4l::gpio::GPIOPin<'static>>,
149 1,
150 >,
151 button: &'static capsules_core::button::Button<'static, sam4l::gpio::GPIOPin<'static>>,
152 rng: &'static RngDriver,
153 analog_comparator: &'static capsules_extra::analog_comparator::AnalogComparator<
154 'static,
155 sam4l::acifc::Acifc<'static>,
156 >,
157 spi: &'static capsules_core::spi_controller::Spi<
158 'static,
159 VirtualSpiMasterDevice<'static, sam4l::spi::SpiHw<'static>>,
160 >,
161 ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
162 ninedof: &'static capsules_extra::ninedof::NineDof<'static>,
163 udp_driver: &'static capsules_extra::net::udp::UDPDriver<'static>,
164 crc: &'static capsules_extra::crc::CrcDriver<'static, sam4l::crccu::Crccu<'static>>,
165 usb_driver: &'static capsules_extra::usb::usb_user::UsbSyscallDriver<
166 'static,
167 capsules_extra::usb::usbc_client::Client<'static, sam4l::usbc::Usbc<'static>>,
168 >,
169 nrf51822: &'static capsules_extra::nrf51822_serialization::Nrf51822Serialization<'static>,
170 nonvolatile_storage:
171 &'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
172 scheduler: &'static RoundRobinSched<'static>,
173 systick: cortexm4::systick::SysTick,
174}
175
176impl SyscallDriverLookup for Imix {
177 fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
178 where
179 F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
180 {
181 match driver_num {
182 capsules_core::console_ordered::DRIVER_NUM => f(Some(self.console)),
183 capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
184 capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
185 capsules_core::spi_controller::DRIVER_NUM => f(Some(self.spi)),
186 capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
187 capsules_core::led::DRIVER_NUM => f(Some(self.led)),
188 capsules_core::button::DRIVER_NUM => f(Some(self.button)),
189 capsules_extra::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
190 capsules_extra::ambient_light::DRIVER_NUM => f(Some(self.ambient_light)),
191 capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
192 capsules_extra::humidity::DRIVER_NUM => f(Some(self.humidity)),
193 capsules_extra::ninedof::DRIVER_NUM => f(Some(self.ninedof)),
194 capsules_extra::crc::DRIVER_NUM => f(Some(self.crc)),
195 capsules_extra::usb::usb_user::DRIVER_NUM => f(Some(self.usb_driver)),
196 capsules_extra::net::udp::DRIVER_NUM => f(Some(self.udp_driver)),
197 capsules_extra::nrf51822_serialization::DRIVER_NUM => f(Some(self.nrf51822)),
198 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => {
199 f(Some(self.nonvolatile_storage))
200 }
201 capsules_core::rng::DRIVER_NUM => f(Some(self.rng)),
202 kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
203 _ => f(None),
204 }
205 }
206}
207
208impl KernelResources<sam4l::chip::Sam4l<Sam4lDefaultPeripherals>> for Imix {
209 type SyscallDriverLookup = Self;
210 type SyscallFilter = ();
211 type ProcessFault = ();
212 type Scheduler = RoundRobinSched<'static>;
213 type SchedulerTimer = cortexm4::systick::SysTick;
214 type WatchDog = ();
215 type ContextSwitchCallback = ();
216
217 fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
218 self
219 }
220 fn syscall_filter(&self) -> &Self::SyscallFilter {
221 &()
222 }
223 fn process_fault(&self) -> &Self::ProcessFault {
224 &()
225 }
226 fn scheduler(&self) -> &Self::Scheduler {
227 self.scheduler
228 }
229 fn scheduler_timer(&self) -> &Self::SchedulerTimer {
230 &self.systick
231 }
232 fn watchdog(&self) -> &Self::WatchDog {
233 &()
234 }
235 fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
236 &()
237 }
238}
239
240unsafe fn set_pin_primary_functions(peripherals: &Sam4lDefaultPeripherals) {
241 use sam4l::gpio::PeripheralFunction::{A, B, C, E};
242
243 peripherals.pa[04].configure(Some(A)); peripherals.pa[05].configure(Some(A)); peripherals.pa[06].configure(Some(C)); peripherals.pa[07].configure(Some(A)); peripherals.pa[08].configure(None); peripherals.pa[09].configure(None); peripherals.pa[10].configure(None); peripherals.pa[13].configure(None); peripherals.pa[14].configure(None); peripherals.pa[17].configure(None); peripherals.pa[18].configure(Some(A)); peripherals.pa[20].configure(None); peripherals.pa[21].configure(Some(E)); peripherals.pa[22].configure(Some(E)); peripherals.pa[25].configure(Some(A)); peripherals.pa[26].configure(Some(A)); peripherals.pb[00].configure(Some(A)); peripherals.pb[01].configure(Some(A)); peripherals.pb[02].configure(Some(A)); peripherals.pb[03].configure(Some(A)); peripherals.pb[04].configure(Some(A)); peripherals.pb[05].configure(Some(A)); peripherals.pb[06].configure(Some(A)); peripherals.pb[07].configure(None); peripherals.pb[09].configure(Some(A)); peripherals.pb[10].configure(Some(A)); peripherals.pb[11].configure(Some(A)); peripherals.pb[12].configure(Some(A)); peripherals.pb[13].configure(Some(A)); peripherals.pb[14].configure(Some(A)); peripherals.pb[15].configure(Some(A)); peripherals.pc[00].configure(Some(A)); peripherals.pc[01].configure(Some(A)); peripherals.pc[02].configure(Some(A)); peripherals.pc[03].configure(Some(A)); peripherals.pc[04].configure(Some(A)); peripherals.pc[05].configure(Some(A)); peripherals.pc[06].configure(Some(A)); peripherals.pc[07].configure(Some(B)); peripherals.pc[08].configure(Some(E)); peripherals.pc[09].configure(Some(E)); peripherals.pc[10].configure(Some(E)); peripherals.pc[11].configure(Some(B)); peripherals.pc[12].configure(Some(B)); peripherals.pc[13].configure(Some(E)); peripherals.pc[14].configure(Some(E)); peripherals.pc[16].configure(None); peripherals.pc[17].configure(None); peripherals.pc[18].configure(None); peripherals.pc[19].configure(None); peripherals.pc[22].configure(None); peripherals.pc[24].configure(None); peripherals.pc[25].configure(Some(B)); peripherals.pc[26].configure(None); peripherals.pc[27].configure(None); peripherals.pc[28].configure(None); peripherals.pc[29].configure(None); peripherals.pc[30].configure(None); peripherals.pc[31].configure(None); }
309
310#[inline(never)]
314unsafe fn start() -> (
315 &'static kernel::Kernel,
316 Imix,
317 &'static sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
318) {
319 sam4l::init();
320 let pm = static_init!(sam4l::pm::PowerManager, sam4l::pm::PowerManager::new());
321 let peripherals = static_init!(Sam4lDefaultPeripherals, Sam4lDefaultPeripherals::new(pm));
322
323 pm.setup_system_clock(
324 sam4l::pm::SystemClockSource::PllExternalOscillatorAt48MHz {
325 frequency: sam4l::pm::OscillatorFrequency::Frequency16MHz,
326 startup_mode: sam4l::pm::OscillatorStartup::FastStart,
327 },
328 &peripherals.flash_controller,
329 );
330
331 sam4l::bpm::set_ck32source(sam4l::bpm::CK32Source::RC32K);
333
334 set_pin_primary_functions(peripherals);
335
336 peripherals.setup_circular_deps();
337 let chip = static_init!(
338 sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
339 sam4l::chip::Sam4l::new(pm, peripherals)
340 );
341 CHIP = Some(chip);
342
343 let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
346
347 power::configure_submodules(
348 &peripherals.pa,
349 &peripherals.pb,
350 &peripherals.pc,
351 power::SubmoduleConfig {
352 rf233: true,
353 nrf51422: true,
354 sensors: true,
355 trng: true,
356 },
357 );
358
359 let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
360
361 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
362 .finalize(components::process_printer_text_component_static!());
363 PROCESS_PRINTER = Some(process_printer);
364
365 peripherals.usart3.set_mode(sam4l::usart::UsartMode::Uart);
368 let uart_mux = UartMuxComponent::new(&peripherals.usart3, 115200)
369 .finalize(components::uart_mux_component_static!());
370
371 let mux_alarm = AlarmMuxComponent::new(&peripherals.ast)
373 .finalize(components::alarm_mux_component_static!(sam4l::ast::Ast));
374 peripherals.ast.configure(mux_alarm);
375
376 let alarm =
377 AlarmDriverComponent::new(board_kernel, capsules_core::alarm::DRIVER_NUM, mux_alarm)
378 .finalize(components::alarm_component_static!(sam4l::ast::Ast));
379
380 let pconsole = ProcessConsoleComponent::new(
381 board_kernel,
382 uart_mux,
383 mux_alarm,
384 process_printer,
385 Some(cortexm4::support::reset),
386 )
387 .finalize(components::process_console_component_static!(
388 sam4l::ast::Ast
389 ));
390
391 let console = ConsoleOrderedComponent::new(
392 board_kernel,
393 capsules_core::console_ordered::DRIVER_NUM,
394 uart_mux,
395 mux_alarm,
396 200,
397 5,
398 5,
399 )
400 .finalize(components::console_ordered_component_static!(
401 sam4l::ast::Ast
402 ));
403 DebugWriterComponent::new(uart_mux).finalize(components::debug_writer_component_static!());
404
405 peripherals.usart2.set_mode(sam4l::usart::UsartMode::Uart);
407 let nrf_serialization = Nrf51822Component::new(
408 board_kernel,
409 capsules_extra::nrf51822_serialization::DRIVER_NUM,
410 &peripherals.usart2,
411 &peripherals.pb[07],
412 )
413 .finalize(components::nrf51822_component_static!());
414
415 let mux_i2c = static_init!(
417 MuxI2C<'static, sam4l::i2c::I2CHw<'static>>,
418 MuxI2C::new(&peripherals.i2c2, None)
419 );
420 kernel::deferred_call::DeferredCallClient::register(mux_i2c);
421 peripherals.i2c2.set_master_client(mux_i2c);
422
423 let isl29035 = Isl29035Component::new(mux_i2c, mux_alarm).finalize(
424 components::isl29035_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw<'static>),
425 );
426 let ambient_light = AmbientLightComponent::new(
427 board_kernel,
428 capsules_extra::ambient_light::DRIVER_NUM,
429 isl29035,
430 )
431 .finalize(components::ambient_light_component_static!());
432
433 let si7021 = SI7021Component::new(mux_i2c, mux_alarm, 0x40).finalize(
434 components::si7021_component_static!(sam4l::ast::Ast, sam4l::i2c::I2CHw<'static>),
435 );
436 let temp = components::temperature::TemperatureComponent::new(
437 board_kernel,
438 capsules_extra::temperature::DRIVER_NUM,
439 si7021,
440 )
441 .finalize(components::temperature_component_static!(SI7021Sensor));
442 let humidity = components::humidity::HumidityComponent::new(
443 board_kernel,
444 capsules_extra::humidity::DRIVER_NUM,
445 si7021,
446 )
447 .finalize(components::humidity_component_static!(SI7021Sensor));
448
449 let fxos8700 = components::fxos8700::Fxos8700Component::new(mux_i2c, 0x1e, &peripherals.pc[13])
450 .finalize(components::fxos8700_component_static!(
451 sam4l::i2c::I2CHw<'static>
452 ));
453
454 let ninedof = components::ninedof::NineDofComponent::new(
455 board_kernel,
456 capsules_extra::ninedof::DRIVER_NUM,
457 )
458 .finalize(components::ninedof_component_static!(fxos8700));
459
460 let mux_spi = components::spi::SpiMuxComponent::new(&peripherals.spi).finalize(
462 components::spi_mux_component_static!(sam4l::spi::SpiHw<'static>),
463 );
464
465 let spi_syscalls = SpiSyscallComponent::new(
466 board_kernel,
467 mux_spi,
468 sam4l::spi::Peripheral::Peripheral2,
469 capsules_core::spi_controller::DRIVER_NUM,
470 )
471 .finalize(components::spi_syscall_component_static!(
472 sam4l::spi::SpiHw<'static>
473 ));
474 let rf233_spi = SpiComponent::new(mux_spi, sam4l::spi::Peripheral::Peripheral3).finalize(
475 components::spi_component_static!(sam4l::spi::SpiHw<'static>),
476 );
477 let rf233 = components::rf233::RF233Component::new(
478 rf233_spi,
479 &peripherals.pa[09], &peripherals.pa[10], &peripherals.pa[08], &peripherals.pa[08],
483 RADIO_CHANNEL,
484 )
485 .finalize(components::rf233_component_static!(
486 sam4l::spi::SpiHw<'static>
487 ));
488
489 let adc_channels = static_init!(
491 [sam4l::adc::AdcChannel; 6],
492 [
493 sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD1), sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD2), sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD3), sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD4), sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD5), sam4l::adc::AdcChannel::new(sam4l::adc::Channel::AD6), ]
500 );
501 let adc = components::adc::AdcDedicatedComponent::new(
502 &peripherals.adc,
503 adc_channels,
504 board_kernel,
505 capsules_core::adc::DRIVER_NUM,
506 )
507 .finalize(components::adc_dedicated_component_static!(sam4l::adc::Adc));
508
509 let gpio = GpioComponent::new(
510 board_kernel,
511 capsules_core::gpio::DRIVER_NUM,
512 components::gpio_component_helper!(
513 sam4l::gpio::GPIOPin,
514 0 => &peripherals.pc[31],
515 1 => &peripherals.pc[30],
516 2 => &peripherals.pc[29],
517 3 => &peripherals.pc[28],
518 4 => &peripherals.pc[27],
519 5 => &peripherals.pc[26],
520 6 => &peripherals.pa[20]
521 ),
522 )
523 .finalize(components::gpio_component_static!(sam4l::gpio::GPIOPin));
524
525 let led = LedsComponent::new().finalize(components::led_component_static!(
526 LedHigh<'static, sam4l::gpio::GPIOPin>,
527 LedHigh::new(&peripherals.pc[10]),
528 ));
529
530 let button = components::button::ButtonComponent::new(
531 board_kernel,
532 capsules_core::button::DRIVER_NUM,
533 components::button_component_helper!(
534 sam4l::gpio::GPIOPin,
535 (
536 &peripherals.pc[24],
537 kernel::hil::gpio::ActivationMode::ActiveLow,
538 kernel::hil::gpio::FloatingState::PullNone
539 )
540 ),
541 )
542 .finalize(components::button_component_static!(sam4l::gpio::GPIOPin));
543
544 let crc = CrcComponent::new(
545 board_kernel,
546 capsules_extra::crc::DRIVER_NUM,
547 &peripherals.crccu,
548 )
549 .finalize(components::crc_component_static!(sam4l::crccu::Crccu));
550
551 let ac_0 = static_init!(
552 sam4l::acifc::AcChannel,
553 sam4l::acifc::AcChannel::new(sam4l::acifc::Channel::AC0)
554 );
555 let ac_1 = static_init!(
556 sam4l::acifc::AcChannel,
557 sam4l::acifc::AcChannel::new(sam4l::acifc::Channel::AC0)
558 );
559 let ac_2 = static_init!(
560 sam4l::acifc::AcChannel,
561 sam4l::acifc::AcChannel::new(sam4l::acifc::Channel::AC0)
562 );
563 let ac_3 = static_init!(
564 sam4l::acifc::AcChannel,
565 sam4l::acifc::AcChannel::new(sam4l::acifc::Channel::AC0)
566 );
567 let analog_comparator = components::analog_comparator::AnalogComparatorComponent::new(
568 &peripherals.acifc,
569 components::analog_comparator_component_helper!(
570 <sam4l::acifc::Acifc as kernel::hil::analog_comparator::AnalogComparator>::Channel,
571 ac_0,
572 ac_1,
573 ac_2,
574 ac_3
575 ),
576 board_kernel,
577 capsules_extra::analog_comparator::DRIVER_NUM,
578 )
579 .finalize(components::analog_comparator_component_static!(
580 sam4l::acifc::Acifc
581 ));
582 let rng = RngComponent::new(
583 board_kernel,
584 capsules_core::rng::DRIVER_NUM,
585 &peripherals.trng,
586 )
587 .finalize(components::rng_component_static!(sam4l::trng::Trng));
588
589 let serial_num: sam4l::serial_num::SerialNum = sam4l::serial_num::SerialNum::new();
595 let serial_num_bottom_16 = (serial_num.get_lower_64() & 0x0000_0000_0000_ffff) as u16;
596 let src_mac_from_serial_num: MacAddress = MacAddress::Short(serial_num_bottom_16);
597 const DEFAULT_EXT_SRC_MAC: [u8; 8] = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77];
598
599 let aes_mux = static_init!(
600 MuxAES128CCM<'static, sam4l::aes::Aes>,
601 MuxAES128CCM::new(&peripherals.aes)
602 );
603 aes_mux.register();
604 peripherals.aes.set_client(aes_mux);
605
606 let (_, mux_mac) = components::ieee802154::Ieee802154Component::new(
607 board_kernel,
608 capsules_extra::ieee802154::DRIVER_NUM,
609 rf233,
610 aes_mux,
611 PAN_ID,
612 serial_num_bottom_16,
613 DEFAULT_EXT_SRC_MAC,
614 )
615 .finalize(components::ieee802154_component_static!(
616 capsules_extra::rf233::RF233<
617 'static,
618 VirtualSpiMasterDevice<'static, sam4l::spi::SpiHw<'static>>,
619 >,
620 sam4l::aes::Aes<'static>
621 ));
622
623 let usb_driver = components::usb::UsbComponent::new(
624 board_kernel,
625 capsules_extra::usb::usb_user::DRIVER_NUM,
626 &peripherals.usbc,
627 )
628 .finalize(components::usb_component_static!(sam4l::usbc::Usbc));
629
630 extern "C" {
633 static _sstorage: u8;
635 static _estorage: u8;
636 }
637
638 let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
639 board_kernel,
640 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM,
641 &peripherals.flash_controller,
642 0x60000, 0x20000, core::ptr::addr_of!(_sstorage) as usize, core::ptr::addr_of!(_estorage) as usize - core::ptr::addr_of!(_sstorage) as usize, )
647 .finalize(components::nonvolatile_storage_component_static!(
648 sam4l::flashcalw::FLASHCALW
649 ));
650
651 let local_ip_ifaces = static_init!(
652 [IPAddr; 3],
653 [
654 IPAddr([
655 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
656 0x0e, 0x0f,
657 ]),
658 IPAddr([
659 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
660 0x1e, 0x1f,
661 ]),
662 IPAddr::generate_from_mac(src_mac_from_serial_num),
663 ]
664 );
665
666 let (udp_send_mux, udp_recv_mux, udp_port_table) = components::udp_mux::UDPMuxComponent::new(
667 mux_mac,
668 DEFAULT_CTX_PREFIX_LEN,
669 DEFAULT_CTX_PREFIX,
670 DST_MAC_ADDR,
671 src_mac_from_serial_num, local_ip_ifaces,
674 mux_alarm,
675 )
676 .finalize(components::udp_mux_component_static!(
677 sam4l::ast::Ast,
678 Ieee802154MacDevice
679 ));
680
681 let udp_driver = components::udp_driver::UDPDriverComponent::new(
683 board_kernel,
684 capsules_extra::net::udp::driver::DRIVER_NUM,
685 udp_send_mux,
686 udp_recv_mux,
687 udp_port_table,
688 local_ip_ifaces,
689 )
690 .finalize(components::udp_driver_component_static!(sam4l::ast::Ast));
691
692 let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
693 .finalize(components::round_robin_component_static!(NUM_PROCS));
694
695 let sha = components::sha::ShaSoftware256Component::new()
697 .finalize(components::sha_software_256_component_static!());
698
699 let checking_policy = components::appid::checker_sha::AppCheckerSha256Component::new(sha)
701 .finalize(components::app_checker_sha256_component_static!());
702
703 let assigner = components::appid::assigner_name::AppIdAssignerNamesComponent::new()
705 .finalize(components::appid_assigner_names_component_static!());
706
707 let checker = components::appid::checker::ProcessCheckerMachineComponent::new(checking_policy)
709 .finalize(components::process_checker_machine_component_static!());
710
711 let storage_permissions_policy =
716 components::storage_permissions::individual::StoragePermissionsIndividualComponent::new()
717 .finalize(
718 components::storage_permissions_individual_component_static!(
719 sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
720 kernel::process::ProcessStandardDebugFull,
721 ),
722 );
723
724 let _loader = components::loader::sequential::ProcessLoaderSequentialComponent::new(
730 checker,
731 &mut *addr_of_mut!(PROCESSES),
732 board_kernel,
733 chip,
734 &FAULT_RESPONSE,
735 assigner,
736 storage_permissions_policy,
737 )
738 .finalize(components::process_loader_sequential_component_static!(
739 sam4l::chip::Sam4l<Sam4lDefaultPeripherals>,
740 kernel::process::ProcessStandardDebugFull,
741 NUM_PROCS
742 ));
743
744 let imix = Imix {
745 pconsole,
746 console,
747 alarm,
748 gpio,
749 temp,
750 humidity,
751 ambient_light,
752 adc,
753 led,
754 button,
755 rng,
756 analog_comparator,
757 crc,
758 spi: spi_syscalls,
759 ipc: kernel::ipc::IPC::new(board_kernel, kernel::ipc::DRIVER_NUM, &grant_cap),
760 ninedof,
761 udp_driver,
762 usb_driver,
763 nrf51822: nrf_serialization,
764 nonvolatile_storage,
765 scheduler,
766 systick: cortexm4::systick::SysTick::new(),
767 };
768
769 imix.nrf51822.initialize();
771
772 let _ = rf233.reset();
775 let _ = rf233.start();
776
777 let _ = imix.pconsole.start();
778
779 debug!("Initialization complete. Entering main loop");
829
830 (board_kernel, imix, chip)
831}
832
833#[no_mangle]
835pub unsafe fn main() {
836 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
837
838 let (board_kernel, platform, chip) = start();
839 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
840}