Skip to content

Commit

Permalink
boards: create alarm component from platformtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Oct 8, 2024
1 parent 57c33b5 commit 61c8471
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
15 changes: 12 additions & 3 deletions boards/components/src/alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ use kernel::hil::time::{self, Alarm};
#[macro_export]
macro_rules! alarm_mux_component_static {
($A:ty $(,)?) => {{
kernel::static_buf!(capsules_core::virtualizers::virtual_alarm::MuxAlarm<'static, $A>)
kernel::static_buf!(
capsules_core::virtualizers::virtual_alarm::MuxAlarm<
'static,
<$A as crate::ComponentTypes>::AlarmType,
>
)
};};
}

Expand Down Expand Up @@ -73,8 +78,12 @@ pub struct AlarmMuxComponent<A: 'static + time::Alarm<'static>> {
}

impl<A: 'static + time::Alarm<'static>> AlarmMuxComponent<A> {
pub fn new(alarm: &'static A) -> AlarmMuxComponent<A> {
AlarmMuxComponent { alarm }
pub fn new<C: crate::ComponentTypes<'static, AlarmType = A>>(
platform: &'static C,
) -> AlarmMuxComponent<A> {
AlarmMuxComponent {
alarm: platform.get_alarm(),
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ pub trait ComponentTypes<'a> {

type AlarmType: Alarm<'a>;
type AlarmDriver: SyscallDriver = ();
const ALARM_DRIVER_NUM: usize;

type ButtonDriver: SyscallDriver = ();

type LedType: Led;
type LedDriver: SyscallDriver = ();

fn get_alarm(&self) -> &Self::AlarmType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const NUM_PROCS: usize = 8;
static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
[None; NUM_PROCS];

static mut CHIP: Option<&'static <Platform as ComponentTypes>::ChipType> = None;
static mut CHIP: Option<&'static <PlatformTypes as ComponentTypes>::ChipType> = None;

/// Dummy buffer that causes the linker to reserve enough space for the stack.
#[no_mangle]
Expand All @@ -73,13 +73,18 @@ pub static mut STACK_MEMORY: [u8; 0x2000] = [0; 0x2000];
/// Supported drivers by the platform
pub struct Platform {
console: &'static capsules_core::console::Console<'static>,
led: &'static <Platform as ComponentTypes<'static>>::LedDriver,
alarm: &'static <Platform as ComponentTypes<'static>>::AlarmDriver,
led: &'static <PlatformTypes as ComponentTypes<'static>>::LedDriver,
alarm: &'static <PlatformTypes as ComponentTypes<'static>>::AlarmDriver,
scheduler: &'static RoundRobinSched<'static>,
systick: cortexm4::systick::SysTick,
}

impl ComponentTypes<'static> for Platform {
/// Container for all type information about this particular board.
pub struct PlatformTypes {
peripherals: &'static Nrf52840DefaultPeripherals<'static>,
}

impl ComponentTypes<'static> for PlatformTypes {
type ChipType = nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>;
type ProcessType = kernel::process::ProcessStandard<
'static,
Expand All @@ -88,9 +93,14 @@ impl ComponentTypes<'static> for Platform {

type AlarmType = nrf52840::rtc::Rtc<'static>;
type AlarmDriver = components::alarm::AlarmDriverComponentType<Self::AlarmType>;
const ALARM_DRIVER_NUM: usize = capsules_core::alarm::DRIVER_NUM;

type LedType = kernel::hil::led::LedLow<'static, nrf52840::gpio::GPIOPin<'static>>;
type LedDriver = components::led::LedsComponentType<Self::LedType, 4>;

fn get_alarm(&self) -> &Self::AlarmType {
&self.peripherals.nrf52.rtc
}
}

impl SyscallDriverLookup for Platform {
Expand Down Expand Up @@ -203,6 +213,13 @@ pub unsafe fn main() {
)
.finalize(());

let platform_type = static_init!(
PlatformTypes,
PlatformTypes {
peripherals: nrf52840_peripherals,
}
);

//--------------------------------------------------------------------------
// CAPABILITIES
//--------------------------------------------------------------------------
Expand All @@ -216,7 +233,7 @@ pub unsafe fn main() {
//--------------------------------------------------------------------------

let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
Platform,
PlatformTypes,
LedLow::new(&nrf52840_peripherals.gpio_port[LED1_PIN]),
LedLow::new(&nrf52840_peripherals.gpio_port[LED2_PIN]),
LedLow::new(&nrf52840_peripherals.gpio_port[LED3_PIN]),
Expand All @@ -229,14 +246,14 @@ pub unsafe fn main() {

let rtc = &base_peripherals.rtc;
let _ = rtc.start();
let mux_alarm = components::alarm::AlarmMuxComponent::new(rtc)
.finalize(components::alarm_mux_component_static!(nrf52840::rtc::Rtc));
let mux_alarm = components::alarm::AlarmMuxComponent::new(platform_type)
.finalize(components::alarm_mux_component_static!(PlatformTypes));
let alarm = components::alarm::AlarmDriverComponent::new(
board_kernel,
capsules_core::alarm::DRIVER_NUM,
PlatformTypes::ALARM_DRIVER_NUM,
mux_alarm,
)
.finalize(components::alarm_component_static!(Platform));
.finalize(components::alarm_component_static!(PlatformTypes));

//--------------------------------------------------------------------------
// UART & CONSOLE & DEBUG
Expand Down Expand Up @@ -296,7 +313,7 @@ pub unsafe fn main() {
let storage_permissions_policy =
components::storage_permissions::null::StoragePermissionsNullComponent::new().finalize(
components::storage_permissions_null_component_static!(
<Platform as ComponentTypes>::ChipType,
<PlatformTypes as ComponentTypes>::ChipType,
),
);

Expand All @@ -315,7 +332,7 @@ pub unsafe fn main() {
storage_permissions_policy,
)
.finalize(components::process_loader_sequential_component_static!(
<Platform as ComponentTypes>::ChipType,
<PlatformTypes as ComponentTypes>::ChipType,
NUM_PROCS
));

Expand Down

0 comments on commit 61c8471

Please sign in to comment.