Skip to content

Commit

Permalink
kernel: make user-kernel boundary in Chip
Browse files Browse the repository at this point in the history
This removes the burden that the board author has to think about this,
since once the chip has been decided, the architecture has been decided
as well.
  • Loading branch information
bradjc committed Sep 28, 2018
1 parent 1c34d78 commit a2c3347
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 65 deletions.
4 changes: 1 addition & 3 deletions boards/ek-tm4c1294xl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use capsules::virtual_uart::{UartDevice, UartMux};
use kernel::capabilities;
use kernel::hil;
use kernel::hil::Controller;
use kernel::Chip;
use kernel::Platform;

#[macro_use]
Expand Down Expand Up @@ -255,8 +254,7 @@ pub unsafe fn reset_handler() {
}
kernel::procs::load_processes(
board_kernel,
&cortexm4::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
&mut APP_MEMORY,
&mut PROCESSES,
Expand Down
4 changes: 1 addition & 3 deletions boards/hail/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use kernel::capabilities;
use kernel::hil;
use kernel::hil::spi::SpiMaster;
use kernel::hil::Controller;
use kernel::Chip;
use kernel::Platform;

/// Support routines for debugging I/O.
Expand Down Expand Up @@ -591,8 +590,7 @@ pub unsafe fn reset_handler() {

kernel::procs::load_processes(
board_kernel,
&cortexm4::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
&mut APP_MEMORY,
&mut PROCESSES,
Expand Down
4 changes: 1 addition & 3 deletions boards/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use kernel::hil::radio;
use kernel::hil::radio::{RadioConfig, RadioData};
use kernel::hil::spi::SpiMaster;
use kernel::hil::Controller;
use kernel::Chip;

use components::adc::AdcComponent;
use components::alarm::AlarmDriverComponent;
Expand Down Expand Up @@ -392,8 +391,7 @@ pub unsafe fn reset_handler() {
}
kernel::procs::load_processes(
board_kernel,
&cortexm4::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
&mut APP_MEMORY,
&mut PROCESSES,
Expand Down
4 changes: 1 addition & 3 deletions boards/launchxl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use cc26x2::aon;
use cc26x2::prcm;
use kernel::capabilities;
use kernel::hil;
use kernel::Chip;

#[macro_use]
pub mod io;
Expand Down Expand Up @@ -364,8 +363,7 @@ pub unsafe fn reset_handler() {

kernel::procs::load_processes(
board_kernel,
&cortexm4::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
&mut APP_MEMORY,
&mut PROCESSES,
Expand Down
3 changes: 1 addition & 2 deletions boards/nordic/nrf51dk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ pub unsafe fn reset_handler() {
}
kernel::procs::load_processes(
board_kernel,
&cortexm0::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
&mut APP_MEMORY,
&mut PROCESSES,
Expand Down
4 changes: 1 addition & 3 deletions boards/nordic/nrf52dk_base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use capsules::virtual_spi::MuxSpiMaster;
use capsules::virtual_uart::{UartDevice, UartMux};
use kernel::capabilities;
use kernel::hil;
use kernel::Chip;
use nrf5x::rtc::Rtc;

/// Pins for SPI for the flash chip MX25R6435F
Expand Down Expand Up @@ -430,8 +429,7 @@ pub unsafe fn setup_board(
}
kernel::procs::load_processes(
board_kernel,
&cortexm4::syscall::SysCall::new(),
chip.mpu(),
chip,
&_sapps as *const u8,
app_memory,
process_pointers,
Expand Down
8 changes: 8 additions & 0 deletions chips/cc26x2/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use uart;

pub struct Cc26X2 {
mpu: cortexm4::mpu::MPU,
userspace_kernel_boundary: cortexm4::syscall::SysCall,
systick: cortexm4::systick::SysTick,
}

impl Cc26X2 {
pub unsafe fn new() -> Cc26X2 {
Cc26X2 {
mpu: cortexm4::mpu::MPU::new(),
userspace_kernel_boundary: cortexm4::syscall::SysCall::new(),
// The systick clocks with 48MHz by default
systick: cortexm4::systick::SysTick::new_with_calibration(48 * 1000000),
}
Expand All @@ -23,6 +25,7 @@ impl Cc26X2 {

impl kernel::Chip for Cc26X2 {
type MPU = cortexm4::mpu::MPU;
type UserspaceKernelBoundary = cortexm4::syscall::SysCall;
type SysTick = cortexm4::systick::SysTick;

fn mpu(&self) -> &Self::MPU {
Expand All @@ -32,6 +35,11 @@ impl kernel::Chip for Cc26X2 {
fn systick(&self) -> &Self::SysTick {
&self.systick
}

fn userspace_kernel_boundary(&self) -> &Self::UserspaceKernelBoundary {
&self.userspace_kernel_boundary
}

fn service_pending_interrupts(&self) {
unsafe {
while let Some(interrupt) = nvic::next_pending() {
Expand Down
17 changes: 13 additions & 4 deletions chips/nrf51/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ use nrf5x::peripheral_interrupts;
use radio;
use uart;

pub struct NRF51(());
pub struct NRF51 {
userspace_kernel_boundary: cortexm0::syscall::SysCall,
}

impl NRF51 {
pub unsafe fn new() -> NRF51 {
NRF51(())
NRF51 {
userspace_kernel_boundary: cortexm0::syscall::SysCall::new(),
}
}
}

impl kernel::Chip for NRF51 {
type MPU = ();
type UserspaceKernelBoundary = cortexm0::syscall::SysCall;
type SysTick = ();

fn mpu(&self) -> &Self::MPU {
&self.0
&()
}

fn systick(&self) -> &Self::SysTick {
&self.0
&()
}

fn userspace_kernel_boundary(&self) -> &cortexm0::syscall::SysCall {
&self.userspace_kernel_boundary
}

fn service_pending_interrupts(&self) {
Expand Down
7 changes: 7 additions & 0 deletions chips/nrf52/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use uart;

pub struct NRF52 {
mpu: cortexm4::mpu::MPU,
userspace_kernel_boundary: cortexm4::syscall::SysCall,
systick: cortexm4::systick::SysTick,
}

impl NRF52 {
pub unsafe fn new() -> NRF52 {
NRF52 {
mpu: cortexm4::mpu::MPU::new(),
userspace_kernel_boundary: cortexm4::syscall::SysCall::new(),
// The NRF52's systick is uncalibrated, but is clocked from the
// 64Mhz CPU clock.
systick: cortexm4::systick::SysTick::new_with_calibration(64000000),
Expand All @@ -29,6 +31,7 @@ impl NRF52 {

impl kernel::Chip for NRF52 {
type MPU = cortexm4::mpu::MPU;
type UserspaceKernelBoundary = cortexm4::syscall::SysCall;
type SysTick = cortexm4::systick::SysTick;

fn mpu(&self) -> &Self::MPU {
Expand All @@ -39,6 +42,10 @@ impl kernel::Chip for NRF52 {
&self.systick
}

fn userspace_kernel_boundary(&self) -> &Self::UserspaceKernelBoundary {
&self.userspace_kernel_boundary
}

fn service_pending_interrupts(&self) {
unsafe {
loop {
Expand Down
11 changes: 9 additions & 2 deletions chips/sam4l/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use usart;
use usbc;

pub struct Sam4l {
pub mpu: cortexm4::mpu::MPU,
pub systick: cortexm4::systick::SysTick,
mpu: cortexm4::mpu::MPU,
userspace_kernel_boundary: cortexm4::syscall::SysCall,
systick: cortexm4::systick::SysTick,
}

impl Sam4l {
Expand Down Expand Up @@ -62,13 +63,15 @@ impl Sam4l {

Sam4l {
mpu: cortexm4::mpu::MPU::new(),
userspace_kernel_boundary: cortexm4::syscall::SysCall::new(),
systick: cortexm4::systick::SysTick::new(),
}
}
}

impl Chip for Sam4l {
type MPU = cortexm4::mpu::MPU;
type UserspaceKernelBoundary = cortexm4::syscall::SysCall;
type SysTick = cortexm4::systick::SysTick;

fn service_pending_interrupts(&self) {
Expand Down Expand Up @@ -163,6 +166,10 @@ impl Chip for Sam4l {
&self.systick
}

fn userspace_kernel_boundary(&self) -> &cortexm4::syscall::SysCall {
&self.userspace_kernel_boundary
}

fn sleep(&self) {
if pm::deep_sleep_ready() {
unsafe {
Expand Down
11 changes: 9 additions & 2 deletions chips/tm4c129x/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ use kernel::Chip;
use uart;

pub struct Tm4c129x {
pub mpu: cortexm4::mpu::MPU,
pub systick: cortexm4::systick::SysTick,
mpu: cortexm4::mpu::MPU,
userspace_kernel_boundary: cortexm4::syscall::SysCall,
systick: cortexm4::systick::SysTick,
}

impl Tm4c129x {
pub unsafe fn new() -> Tm4c129x {
Tm4c129x {
mpu: cortexm4::mpu::MPU::new(),
userspace_kernel_boundary: cortexm4::syscall::SysCall::new(),
systick: cortexm4::systick::SysTick::new(),
}
}
}

impl Chip for Tm4c129x {
type MPU = cortexm4::mpu::MPU;
type UserspaceKernelBoundary = cortexm4::syscall::SysCall;
type SysTick = cortexm4::systick::SysTick;

fn service_pending_interrupts(&self) {
Expand Down Expand Up @@ -58,6 +61,10 @@ impl Chip for Tm4c129x {
&self.systick
}

fn userspace_kernel_boundary(&self) -> &cortexm4::syscall::SysCall {
&self.userspace_kernel_boundary
}

fn sleep(&self) {
/*if pm::deep_sleep_ready() {
unsafe {
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Interface for chips and boards.

use driver::Driver;
use syscall;

pub mod mpu;
crate mod systick;
Expand All @@ -17,12 +18,14 @@ pub trait Platform {
/// Interface for individual MCUs.
pub trait Chip {
type MPU: mpu::MPU;
type UserspaceKernelBoundary: syscall::UserspaceKernelBoundary;
type SysTick: systick::SysTick;

fn service_pending_interrupts(&self);
fn has_pending_interrupts(&self) -> bool;
fn mpu(&self) -> &Self::MPU;
fn systick(&self) -> &Self::SysTick;
fn userspace_kernel_boundary(&self) -> &Self::UserspaceKernelBoundary;
fn sleep(&self);
unsafe fn atomic<F, R>(&self, f: F) -> R
where
Expand Down
Loading

0 comments on commit a2c3347

Please sign in to comment.