#![no_std]
#![cfg_attr(not(doc), no_main)]
#![deny(missing_docs)]
use core::ptr::addr_of_mut;
use kernel::debug;
use kernel::platform::{KernelResources, SyscallDriverLookup};
use kernel::{capabilities, create_capability};
use nrf52840dk_lib::{self, PROCESSES};
const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
capsules_system::process_policies::PanicFaultPolicy {};
struct Platform {
base: nrf52840dk_lib::Platform,
eui64_driver: &'static nrf52840dk_lib::Eui64Driver,
ieee802154_driver: &'static nrf52840dk_lib::Ieee802154Driver,
udp_driver: &'static capsules_extra::net::udp::UDPDriver<'static>,
}
impl SyscallDriverLookup for Platform {
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
where
F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
{
match driver_num {
capsules_extra::eui64::DRIVER_NUM => f(Some(self.eui64_driver)),
capsules_extra::net::udp::DRIVER_NUM => f(Some(self.udp_driver)),
capsules_extra::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_driver)),
_ => self.base.with_driver(driver_num, f),
}
}
}
type Chip = nrf52840dk_lib::Chip;
impl KernelResources<Chip> for Platform {
type SyscallDriverLookup = Self;
type SyscallFilter = <nrf52840dk_lib::Platform as KernelResources<Chip>>::SyscallFilter;
type ProcessFault = <nrf52840dk_lib::Platform as KernelResources<Chip>>::ProcessFault;
type Scheduler = <nrf52840dk_lib::Platform as KernelResources<Chip>>::Scheduler;
type SchedulerTimer = <nrf52840dk_lib::Platform as KernelResources<Chip>>::SchedulerTimer;
type WatchDog = <nrf52840dk_lib::Platform as KernelResources<Chip>>::WatchDog;
type ContextSwitchCallback =
<nrf52840dk_lib::Platform as KernelResources<Chip>>::ContextSwitchCallback;
fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
self
}
fn syscall_filter(&self) -> &Self::SyscallFilter {
self.base.syscall_filter()
}
fn process_fault(&self) -> &Self::ProcessFault {
self.base.process_fault()
}
fn scheduler(&self) -> &Self::Scheduler {
self.base.scheduler()
}
fn scheduler_timer(&self) -> &Self::SchedulerTimer {
self.base.scheduler_timer()
}
fn watchdog(&self) -> &Self::WatchDog {
self.base.watchdog()
}
fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
self.base.context_switch_callback()
}
}
#[no_mangle]
pub unsafe fn main() {
let (board_kernel, base_platform, chip, default_peripherals, mux_alarm) =
nrf52840dk_lib::start();
let (eui64_driver, ieee802154_driver, udp_driver) =
nrf52840dk_lib::ieee802154_udp(board_kernel, default_peripherals, mux_alarm);
let platform = Platform {
base: base_platform,
eui64_driver,
ieee802154_driver,
udp_driver,
};
extern "C" {
static _sapps: u8;
static _eapps: u8;
static mut _sappmem: u8;
static _eappmem: u8;
}
let process_management_capability =
create_capability!(capabilities::ProcessManagementCapability);
kernel::process::load_processes(
board_kernel,
chip,
core::slice::from_raw_parts(
core::ptr::addr_of!(_sapps),
core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
),
core::slice::from_raw_parts_mut(
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_management_capability,
)
.unwrap_or_else(|err| {
debug!("Error loading processes!");
debug!("{:?}", err);
});
let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
board_kernel.kernel_loop(
&platform,
chip,
Some(&platform.base.ipc),
&main_loop_capability,
);
}