1#![no_std]
71#![deny(missing_docs)]
72
73use core::ptr::addr_of;
74
75use capsules_core::virtualizers::virtual_alarm::{MuxAlarm, VirtualMuxAlarm};
76use capsules_extra::net::ieee802154::MacAddress;
77use capsules_extra::net::ipv6::ip_utils::IPAddr;
78use kernel::component::Component;
79use kernel::hil::led::LedLow;
80use kernel::hil::time::Counter;
81#[allow(unused_imports)]
82use kernel::hil::usb::Client;
83use kernel::platform::{KernelResources, SyscallDriverLookup};
84use kernel::process::ProcessArray;
85use kernel::scheduler::round_robin::RoundRobinSched;
86#[allow(unused_imports)]
87use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init};
88use nrf52840::gpio::Pin;
89use nrf52840::interrupt_service::Nrf52840DefaultPeripherals;
90use nrf52_components::{UartChannel, UartPins};
91
92const LED1_PIN: Pin = Pin::P0_13;
94const LED2_PIN: Pin = Pin::P0_14;
95const LED3_PIN: Pin = Pin::P0_15;
96const LED4_PIN: Pin = Pin::P0_16;
97
98const BUTTON1_PIN: Pin = Pin::P0_11;
100const BUTTON2_PIN: Pin = Pin::P0_12;
101const BUTTON3_PIN: Pin = Pin::P0_24;
102const BUTTON4_PIN: Pin = Pin::P0_25;
103const BUTTON_RST_PIN: Pin = Pin::P0_18;
104
105const UART_RTS: Option<Pin> = Some(Pin::P0_05);
106const UART_TXD: Pin = Pin::P0_06;
107const UART_CTS: Option<Pin> = Some(Pin::P0_07);
108const UART_RXD: Pin = Pin::P0_08;
109
110const SPI_MOSI: Pin = Pin::P0_20;
111const SPI_MISO: Pin = Pin::P0_21;
112const SPI_CLK: Pin = Pin::P0_19;
113const SPI_CS: Pin = Pin::P0_22;
114
115const SPI_MX25R6435F_CHIP_SELECT: Pin = Pin::P0_17;
116const SPI_MX25R6435F_WRITE_PROTECT_PIN: Pin = Pin::P0_22;
117const SPI_MX25R6435F_HOLD_PIN: Pin = Pin::P0_23;
118
119const I2C_SDA_PIN: Pin = Pin::P0_26;
121const I2C_SCL_PIN: Pin = Pin::P0_27;
122
123const PAN_ID: u16 = 0xABCD;
125const DST_MAC_ADDR: capsules_extra::net::ieee802154::MacAddress =
126    capsules_extra::net::ieee802154::MacAddress::Short(49138);
127const DEFAULT_CTX_PREFIX_LEN: u8 = 8; const DEFAULT_CTX_PREFIX: [u8; 16] = [0x0_u8; 16]; pub mod io;
132
133const USB_DEBUGGING: bool = false;
137
138pub type ChipHw = nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>;
140
141pub const NUM_PROCS: usize = 8;
143
144static mut PROCESSES: Option<&'static ProcessArray<NUM_PROCS>> = None;
146static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;
147static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
148    None;
149
150kernel::stack_size! {0x2000}
151
152type AlarmDriver = components::alarm::AlarmDriverComponentType<nrf52840::rtc::Rtc<'static>>;
157type RngDriver = components::rng::RngComponentType<nrf52840::trng::Trng<'static>>;
158
159type Mx25r6435f = components::mx25r6435f::Mx25r6435fComponentType<
161    nrf52840::spi::SPIM<'static>,
162    nrf52840::gpio::GPIOPin<'static>,
163    nrf52840::rtc::Rtc<'static>,
164>;
165const TICKV_PAGE_SIZE: usize =
166    core::mem::size_of::<<Mx25r6435f as kernel::hil::flash::Flash>::Page>();
167type Siphasher24 = components::siphash::Siphasher24ComponentType;
168type TicKVDedicatedFlash =
169    components::tickv::TicKVDedicatedFlashComponentType<Mx25r6435f, Siphasher24, TICKV_PAGE_SIZE>;
170type TicKVKVStore = components::kv::TicKVKVStoreComponentType<
171    TicKVDedicatedFlash,
172    capsules_extra::tickv::TicKVKeyType,
173>;
174type KVStorePermissions = components::kv::KVStorePermissionsComponentType<TicKVKVStore>;
175type VirtualKVPermissions = components::kv::VirtualKVPermissionsComponentType<KVStorePermissions>;
176type KVDriver = components::kv::KVDriverComponentType<VirtualKVPermissions>;
177
178type TemperatureDriver =
180    components::temperature::TemperatureComponentType<nrf52840::temperature::Temp<'static>>;
181
182type Ieee802154MacDevice = components::ieee802154::Ieee802154ComponentMacDeviceType<
184    nrf52840::ieee802154_radio::Radio<'static>,
185    nrf52840::aes::AesECB<'static>,
186>;
187pub type Ieee802154Driver = components::ieee802154::Ieee802154ComponentType<
189    nrf52840::ieee802154_radio::Radio<'static>,
190    nrf52840::aes::AesECB<'static>,
191>;
192
193pub type Eui64Driver = components::eui64::Eui64ComponentType;
196
197pub struct Platform {
199    ble_radio: &'static capsules_extra::ble_advertising_driver::BLE<
200        'static,
201        nrf52840::ble_radio::Radio<'static>,
202        VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
203    >,
204    button: &'static capsules_core::button::Button<'static, nrf52840::gpio::GPIOPin<'static>>,
205    pconsole: &'static capsules_core::process_console::ProcessConsole<
206        'static,
207        { capsules_core::process_console::DEFAULT_COMMAND_HISTORY_LEN },
208        VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
209        components::process_console::Capability,
210    >,
211    console: &'static capsules_core::console::Console<'static>,
212    gpio: &'static capsules_core::gpio::GPIO<'static, nrf52840::gpio::GPIOPin<'static>>,
213    led: &'static capsules_core::led::LedDriver<
214        'static,
215        kernel::hil::led::LedLow<'static, nrf52840::gpio::GPIOPin<'static>>,
216        4,
217    >,
218    rng: &'static RngDriver,
219    adc: &'static capsules_core::adc::AdcDedicated<'static, nrf52840::adc::Adc<'static>>,
220    temp: &'static TemperatureDriver,
221    pub ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
223    analog_comparator: &'static capsules_extra::analog_comparator::AnalogComparator<
224        'static,
225        nrf52840::acomp::Comparator<'static>,
226    >,
227    alarm: &'static AlarmDriver,
228    i2c_master_slave: &'static capsules_core::i2c_master_slave_driver::I2CMasterSlaveDriver<
229        'static,
230        nrf52840::i2c::TWI<'static>,
231    >,
232    spi_controller: &'static capsules_core::spi_controller::Spi<
233        'static,
234        capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<
235            'static,
236            nrf52840::spi::SPIM<'static>,
237        >,
238    >,
239    kv_driver: &'static KVDriver,
240    scheduler: &'static RoundRobinSched<'static>,
241    systick: cortexm4::systick::SysTick,
242}
243
244impl SyscallDriverLookup for Platform {
245    fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
246    where
247        F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
248    {
249        match driver_num {
250            capsules_core::console::DRIVER_NUM => f(Some(self.console)),
251            capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
252            capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
253            capsules_core::led::DRIVER_NUM => f(Some(self.led)),
254            capsules_core::button::DRIVER_NUM => f(Some(self.button)),
255            capsules_core::rng::DRIVER_NUM => f(Some(self.rng)),
256            capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
257            capsules_extra::ble_advertising_driver::DRIVER_NUM => f(Some(self.ble_radio)),
258            capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
259            capsules_extra::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
260            kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
261            capsules_core::i2c_master_slave_driver::DRIVER_NUM => f(Some(self.i2c_master_slave)),
262            capsules_core::spi_controller::DRIVER_NUM => f(Some(self.spi_controller)),
263            capsules_extra::kv_driver::DRIVER_NUM => f(Some(self.kv_driver)),
264            _ => f(None),
265        }
266    }
267}
268
269impl KernelResources<ChipHw> for Platform {
270    type SyscallDriverLookup = Self;
271    type SyscallFilter = ();
272    type ProcessFault = ();
273    type Scheduler = RoundRobinSched<'static>;
274    type SchedulerTimer = cortexm4::systick::SysTick;
275    type WatchDog = ();
276    type ContextSwitchCallback = ();
277
278    fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
279        self
280    }
281    fn syscall_filter(&self) -> &Self::SyscallFilter {
282        &()
283    }
284    fn process_fault(&self) -> &Self::ProcessFault {
285        &()
286    }
287    fn scheduler(&self) -> &Self::Scheduler {
288        self.scheduler
289    }
290    fn scheduler_timer(&self) -> &Self::SchedulerTimer {
291        &self.systick
292    }
293    fn watchdog(&self) -> &Self::WatchDog {
294        &()
295    }
296    fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
297        &()
298    }
299}
300
301pub unsafe fn ieee802154_udp(
303    board_kernel: &'static kernel::Kernel,
304    nrf52840_peripherals: &'static Nrf52840DefaultPeripherals<'static>,
305    mux_alarm: &'static MuxAlarm<nrf52840::rtc::Rtc>,
306) -> (
307    &'static Eui64Driver,
308    &'static Ieee802154Driver,
309    &'static capsules_extra::net::udp::UDPDriver<'static>,
310) {
311    let aes_mux =
316        components::ieee802154::MuxAes128ccmComponent::new(&nrf52840_peripherals.nrf52.ecb)
317            .finalize(components::mux_aes128ccm_component_static!(
318                nrf52840::aes::AesECB
319            ));
320
321    let device_id = (*addr_of!(nrf52840::ficr::FICR_INSTANCE)).id();
326    let device_id_bottom_16: u16 = u16::from_le_bytes([device_id[0], device_id[1]]);
327
328    let eui64_driver = components::eui64::Eui64Component::new(u64::from_le_bytes(device_id))
329        .finalize(components::eui64_component_static!());
330
331    let (ieee802154_driver, mux_mac) = components::ieee802154::Ieee802154Component::new(
332        board_kernel,
333        capsules_extra::ieee802154::DRIVER_NUM,
334        &nrf52840_peripherals.ieee802154_radio,
335        aes_mux,
336        PAN_ID,
337        device_id_bottom_16,
338        device_id,
339    )
340    .finalize(components::ieee802154_component_static!(
341        nrf52840::ieee802154_radio::Radio,
342        nrf52840::aes::AesECB<'static>
343    ));
344
345    let local_ip_ifaces = static_init!(
350        [IPAddr; 3],
351        [
352            IPAddr::generate_from_mac(capsules_extra::net::ieee802154::MacAddress::Long(device_id)),
353            IPAddr([
354                0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
355                0x1e, 0x1f,
356            ]),
357            IPAddr::generate_from_mac(capsules_extra::net::ieee802154::MacAddress::Short(
358                device_id_bottom_16
359            )),
360        ]
361    );
362
363    let (udp_send_mux, udp_recv_mux, udp_port_table) = components::udp_mux::UDPMuxComponent::new(
364        mux_mac,
365        DEFAULT_CTX_PREFIX_LEN,
366        DEFAULT_CTX_PREFIX,
367        DST_MAC_ADDR,
368        MacAddress::Long(device_id),
369        local_ip_ifaces,
370        mux_alarm,
371    )
372    .finalize(components::udp_mux_component_static!(
373        nrf52840::rtc::Rtc,
374        Ieee802154MacDevice
375    ));
376
377    let udp_driver = components::udp_driver::UDPDriverComponent::new(
379        board_kernel,
380        capsules_extra::net::udp::driver::DRIVER_NUM,
381        udp_send_mux,
382        udp_recv_mux,
383        udp_port_table,
384        local_ip_ifaces,
385    )
386    .finalize(components::udp_driver_component_static!(nrf52840::rtc::Rtc));
387
388    (eui64_driver, ieee802154_driver, udp_driver)
389}
390
391#[inline(never)]
395pub unsafe fn start_no_pconsole() -> (
396    &'static kernel::Kernel,
397    Platform,
398    &'static ChipHw,
399    &'static Nrf52840DefaultPeripherals<'static>,
400    &'static MuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
401) {
402    nrf52840::init();
408
409    let ieee802154_ack_buf = static_init!(
412        [u8; nrf52840::ieee802154_radio::ACK_BUF_SIZE],
413        [0; nrf52840::ieee802154_radio::ACK_BUF_SIZE]
414    );
415    let nrf52840_peripherals = static_init!(
417        Nrf52840DefaultPeripherals,
418        Nrf52840DefaultPeripherals::new(ieee802154_ack_buf)
419    );
420
421    nrf52840_peripherals.init();
423    let base_peripherals = &nrf52840_peripherals.nrf52;
424
425    kernel::debug::assign_gpios(
427        Some(&nrf52840_peripherals.gpio_port[LED1_PIN]),
428        Some(&nrf52840_peripherals.gpio_port[LED2_PIN]),
429        Some(&nrf52840_peripherals.gpio_port[LED3_PIN]),
430    );
431
432    let uart_channel = if USB_DEBUGGING {
436        let rtt_memory_refs = components::segger_rtt::SeggerRttMemoryComponent::new()
439            .finalize(components::segger_rtt_memory_component_static!());
440
441        self::io::set_rtt_memory(&*core::ptr::from_mut(rtt_memory_refs.rtt_memory));
446
447        UartChannel::Rtt(rtt_memory_refs)
448    } else {
449        UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD))
450    };
451
452    let processes = components::process_array::ProcessArrayComponent::new()
454        .finalize(components::process_array_component_static!(NUM_PROCS));
455    PROCESSES = Some(processes);
456
457    let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
459
460    let chip = static_init!(ChipHw, nrf52840::chip::NRF52::new(nrf52840_peripherals));
463    CHIP = Some(chip);
464
465    nrf52_components::startup::NrfStartupComponent::new(
468        false,
469        BUTTON_RST_PIN,
470        nrf52840::uicr::Regulator0Output::DEFAULT,
471        &base_peripherals.nvmc,
472    )
473    .finalize(());
474
475    let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
482    let gpio_port = &nrf52840_peripherals.gpio_port;
483
484    let gpio = components::gpio::GpioComponent::new(
490        board_kernel,
491        capsules_core::gpio::DRIVER_NUM,
492        components::gpio_component_helper!(
493            nrf52840::gpio::GPIOPin,
494            0 => &nrf52840_peripherals.gpio_port[Pin::P1_01],
495            1 => &nrf52840_peripherals.gpio_port[Pin::P1_02],
496            2 => &nrf52840_peripherals.gpio_port[Pin::P1_03],
497            3 => &nrf52840_peripherals.gpio_port[Pin::P1_04],
498            4 => &nrf52840_peripherals.gpio_port[Pin::P1_05],
499            5 => &nrf52840_peripherals.gpio_port[Pin::P1_06],
500            6 => &nrf52840_peripherals.gpio_port[Pin::P1_07],
501            7 => &nrf52840_peripherals.gpio_port[Pin::P1_08],
502            10 => &nrf52840_peripherals.gpio_port[Pin::P1_12],
510            11 => &nrf52840_peripherals.gpio_port[Pin::P1_13],
511            12 => &nrf52840_peripherals.gpio_port[Pin::P1_14],
512            13 => &nrf52840_peripherals.gpio_port[Pin::P1_15],
513        ),
514    )
515    .finalize(components::gpio_component_static!(nrf52840::gpio::GPIOPin));
516
517    let button = components::button::ButtonComponent::new(
522        board_kernel,
523        capsules_core::button::DRIVER_NUM,
524        components::button_component_helper!(
525            nrf52840::gpio::GPIOPin,
526            (
527                &nrf52840_peripherals.gpio_port[BUTTON1_PIN],
528                kernel::hil::gpio::ActivationMode::ActiveLow,
529                kernel::hil::gpio::FloatingState::PullUp
530            ),
531            (
532                &nrf52840_peripherals.gpio_port[BUTTON2_PIN],
533                kernel::hil::gpio::ActivationMode::ActiveLow,
534                kernel::hil::gpio::FloatingState::PullUp
535            ),
536            (
537                &nrf52840_peripherals.gpio_port[BUTTON3_PIN],
538                kernel::hil::gpio::ActivationMode::ActiveLow,
539                kernel::hil::gpio::FloatingState::PullUp
540            ),
541            (
542                &nrf52840_peripherals.gpio_port[BUTTON4_PIN],
543                kernel::hil::gpio::ActivationMode::ActiveLow,
544                kernel::hil::gpio::FloatingState::PullUp
545            )
546        ),
547    )
548    .finalize(components::button_component_static!(
549        nrf52840::gpio::GPIOPin
550    ));
551
552    let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
557        LedLow<'static, nrf52840::gpio::GPIOPin>,
558        LedLow::new(&nrf52840_peripherals.gpio_port[LED1_PIN]),
559        LedLow::new(&nrf52840_peripherals.gpio_port[LED2_PIN]),
560        LedLow::new(&nrf52840_peripherals.gpio_port[LED3_PIN]),
561        LedLow::new(&nrf52840_peripherals.gpio_port[LED4_PIN]),
562    ));
563
564    let rtc = &base_peripherals.rtc;
569    let _ = rtc.start();
570    let mux_alarm = components::alarm::AlarmMuxComponent::new(rtc)
571        .finalize(components::alarm_mux_component_static!(nrf52840::rtc::Rtc));
572    let alarm = components::alarm::AlarmDriverComponent::new(
573        board_kernel,
574        capsules_core::alarm::DRIVER_NUM,
575        mux_alarm,
576    )
577    .finalize(components::alarm_component_static!(nrf52840::rtc::Rtc));
578
579    let uart_channel = nrf52_components::UartChannelComponent::new(
584        uart_channel,
585        mux_alarm,
586        &base_peripherals.uarte0,
587    )
588    .finalize(nrf52_components::uart_channel_component_static!(
589        nrf52840::rtc::Rtc
590    ));
591
592    let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
594        .finalize(components::process_printer_text_component_static!());
595    PROCESS_PRINTER = Some(process_printer);
596
597    let uart_mux = components::console::UartMuxComponent::new(uart_channel, 115200)
599        .finalize(components::uart_mux_component_static!());
600
601    let pconsole = components::process_console::ProcessConsoleComponent::new(
604        board_kernel,
605        uart_mux,
606        mux_alarm,
607        process_printer,
608        Some(cortexm4::support::reset),
609    )
610    .finalize(components::process_console_component_static!(
611        nrf52840::rtc::Rtc<'static>
612    ));
613
614    let console = components::console::ConsoleComponent::new(
616        board_kernel,
617        capsules_core::console::DRIVER_NUM,
618        uart_mux,
619    )
620    .finalize(components::console_component_static!());
621
622    components::debug_writer::DebugWriterComponent::new::<
624        <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
625    >(
626        uart_mux,
627        create_capability!(capabilities::SetDebugWriterCapability),
628    )
629    .finalize(components::debug_writer_component_static!());
630
631    let ble_radio = components::ble::BLEComponent::new(
636        board_kernel,
637        capsules_extra::ble_advertising_driver::DRIVER_NUM,
638        &base_peripherals.ble_radio,
639        mux_alarm,
640    )
641    .finalize(components::ble_component_static!(
642        nrf52840::rtc::Rtc,
643        nrf52840::ble_radio::Radio
644    ));
645
646    let temp = components::temperature::TemperatureComponent::new(
651        board_kernel,
652        capsules_extra::temperature::DRIVER_NUM,
653        &base_peripherals.temp,
654    )
655    .finalize(components::temperature_component_static!(
656        nrf52840::temperature::Temp
657    ));
658
659    let rng = components::rng::RngComponent::new(
664        board_kernel,
665        capsules_core::rng::DRIVER_NUM,
666        &base_peripherals.trng,
667    )
668    .finalize(components::rng_component_static!(nrf52840::trng::Trng));
669
670    let adc_channels = static_init!(
675        [nrf52840::adc::AdcChannelSetup; 6],
676        [
677            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput1),
678            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput2),
679            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput4),
680            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput5),
681            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput6),
682            nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput7),
683        ]
684    );
685    let adc = components::adc::AdcDedicatedComponent::new(
686        &base_peripherals.adc,
687        adc_channels,
688        board_kernel,
689        capsules_core::adc::DRIVER_NUM,
690    )
691    .finalize(components::adc_dedicated_component_static!(
692        nrf52840::adc::Adc
693    ));
694
695    let mux_spi = components::spi::SpiMuxComponent::new(&base_peripherals.spim0)
700        .finalize(components::spi_mux_component_static!(nrf52840::spi::SPIM));
701
702    let spi_controller = components::spi::SpiSyscallComponent::new(
704        board_kernel,
705        mux_spi,
706        kernel::hil::spi::cs::IntoChipSelect::<_, kernel::hil::spi::cs::ActiveLow>::into_cs(
707            &gpio_port[SPI_CS],
708        ),
709        capsules_core::spi_controller::DRIVER_NUM,
710    )
711    .finalize(components::spi_syscall_component_static!(
712        nrf52840::spi::SPIM
713    ));
714
715    base_peripherals.spim0.configure(
716        nrf52840::pinmux::Pinmux::new(SPI_MOSI as u32),
717        nrf52840::pinmux::Pinmux::new(SPI_MISO as u32),
718        nrf52840::pinmux::Pinmux::new(SPI_CLK as u32),
719    );
720
721    let mx25r6435f = components::mx25r6435f::Mx25r6435fComponent::new(
726        Some(&gpio_port[SPI_MX25R6435F_WRITE_PROTECT_PIN]),
727        Some(&gpio_port[SPI_MX25R6435F_HOLD_PIN]),
728        &gpio_port[SPI_MX25R6435F_CHIP_SELECT],
729        mux_alarm,
730        mux_spi,
731    )
732    .finalize(components::mx25r6435f_component_static!(
733        nrf52840::spi::SPIM,
734        nrf52840::gpio::GPIOPin,
735        nrf52840::rtc::Rtc
736    ));
737
738    let page_buffer = static_init!(
744        <Mx25r6435f as kernel::hil::flash::Flash>::Page,
745        <Mx25r6435f as kernel::hil::flash::Flash>::Page::default()
746    );
747
748    let sip_hash = components::siphash::Siphasher24Component::new()
750        .finalize(components::siphasher24_component_static!());
751
752    let tickv = components::tickv::TicKVDedicatedFlashComponent::new(
754        sip_hash,
755        mx25r6435f,
756        0, (capsules_extra::mx25r6435f::SECTOR_SIZE as usize) * 32, page_buffer,
759    )
760    .finalize(components::tickv_dedicated_flash_component_static!(
761        Mx25r6435f,
762        Siphasher24,
763        TICKV_PAGE_SIZE,
764    ));
765
766    let tickv_kv_store = components::kv::TicKVKVStoreComponent::new(tickv).finalize(
768        components::tickv_kv_store_component_static!(
769            TicKVDedicatedFlash,
770            capsules_extra::tickv::TicKVKeyType,
771        ),
772    );
773
774    let kv_store_permissions = components::kv::KVStorePermissionsComponent::new(tickv_kv_store)
775        .finalize(components::kv_store_permissions_component_static!(
776            TicKVKVStore
777        ));
778
779    let mux_kv = components::kv::KVPermissionsMuxComponent::new(kv_store_permissions).finalize(
781        components::kv_permissions_mux_component_static!(KVStorePermissions),
782    );
783
784    let virtual_kv_driver = components::kv::VirtualKVPermissionsComponent::new(mux_kv).finalize(
786        components::virtual_kv_permissions_component_static!(KVStorePermissions),
787    );
788
789    let kv_driver = components::kv::KVDriverComponent::new(
791        virtual_kv_driver,
792        board_kernel,
793        capsules_extra::kv_driver::DRIVER_NUM,
794    )
795    .finalize(components::kv_driver_component_static!(
796        VirtualKVPermissions
797    ));
798
799    let i2c_master_slave = components::i2c::I2CMasterSlaveDriverComponent::new(
804        board_kernel,
805        capsules_core::i2c_master_slave_driver::DRIVER_NUM,
806        &base_peripherals.twi1,
807    )
808    .finalize(components::i2c_master_slave_component_static!(
809        nrf52840::i2c::TWI
810    ));
811
812    base_peripherals.twi1.configure(
813        nrf52840::pinmux::Pinmux::new(I2C_SCL_PIN as u32),
814        nrf52840::pinmux::Pinmux::new(I2C_SDA_PIN as u32),
815    );
816    base_peripherals.twi1.set_speed(nrf52840::i2c::Speed::K400);
817
818    let analog_comparator_channel = static_init!(
825        nrf52840::acomp::Channel,
826        nrf52840::acomp::Channel::new(nrf52840::acomp::ChannelNumber::AC0)
827    );
828    let analog_comparator = components::analog_comparator::AnalogComparatorComponent::new(
829        &base_peripherals.acomp,
830        components::analog_comparator_component_helper!(
831            nrf52840::acomp::Channel,
832            analog_comparator_channel
833        ),
834        board_kernel,
835        capsules_extra::analog_comparator::DRIVER_NUM,
836    )
837    .finalize(components::analog_comparator_component_static!(
838        nrf52840::acomp::Comparator
839    ));
840
841    nrf52_components::NrfClockComponent::new(&base_peripherals.clock).finalize(());
846
847    let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
899        .finalize(components::round_robin_component_static!(NUM_PROCS));
900
901    let platform = Platform {
902        button,
903        ble_radio,
904        pconsole,
905        console,
906        led,
907        gpio,
908        rng,
909        adc,
910        temp,
911        alarm,
912        analog_comparator,
913        ipc: kernel::ipc::IPC::new(
914            board_kernel,
915            kernel::ipc::DRIVER_NUM,
916            &memory_allocation_capability,
917        ),
918        i2c_master_slave,
919        spi_controller,
920        kv_driver,
921        scheduler,
922        systick: cortexm4::systick::SysTick::new_with_calibration(64000000),
923    };
924
925    base_peripherals.adc.calibrate();
926
927    debug!("Initialization complete. Entering main loop\r");
928    debug!("{}", &*addr_of!(nrf52840::ficr::FICR_INSTANCE));
929
930    (
931        board_kernel,
932        platform,
933        chip,
934        nrf52840_peripherals,
935        mux_alarm,
936    )
937}
938
939#[inline(never)]
943pub unsafe fn start() -> (
944    &'static kernel::Kernel,
945    Platform,
946    &'static ChipHw,
947    &'static Nrf52840DefaultPeripherals<'static>,
948    &'static MuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
949) {
950    let (kernel, platform, chip, peripherals, mux_alarm) = start_no_pconsole();
951    let _ = platform.pconsole.start();
952    (kernel, platform, chip, peripherals, mux_alarm)
953}