Chip

Trait Chip 

Source
pub trait Chip {
    type MPU: MPU;
    type ThreadIdProvider: ThreadIdProvider;
    type UserspaceKernelBoundary: UserspaceKernelBoundary;

    // Required methods
    fn service_pending_interrupts(&self);
    fn has_pending_interrupts(&self) -> bool;
    fn mpu(&self) -> &Self::MPU;
    fn userspace_kernel_boundary(&self) -> &Self::UserspaceKernelBoundary;
    fn sleep(&self);
    unsafe fn with_interrupts_disabled<F, R>(&self, f: F) -> R
       where F: FnOnce() -> R;
    unsafe fn print_state(this: Option<&Self>, writer: &mut dyn Write);
}
Expand description

Interface for individual MCUs.

The trait defines chip-specific properties of Tock’s operation. These include whether and which memory protection mechanism and scheduler_timer to use, how to switch between the kernel and userland applications, and how to handle hardware events.

Each microcontroller should define a struct and implement this trait.

Required Associated Types§

Source

type MPU: MPU

The particular Memory Protection Unit (MPU) for this chip.

Source

type ThreadIdProvider: ThreadIdProvider

Provider to query the currently running thread ID.

Source

type UserspaceKernelBoundary: UserspaceKernelBoundary

The implementation of the interface between userspace and the kernel for this specific chip. Likely this is architecture specific, but individual chips may have various custom requirements.

Required Methods§

Source

fn service_pending_interrupts(&self)

The kernel calls this function to tell the chip to check for all pending interrupts and to correctly dispatch them to the peripheral drivers for the chip.

This function should loop internally until all interrupts have been handled. It is ok, however, if an interrupt occurs after the last check but before this function returns. The kernel will handle this edge case.

Source

fn has_pending_interrupts(&self) -> bool

Ask the chip to check if there are any pending interrupts.

Source

fn mpu(&self) -> &Self::MPU

Returns a reference to the implementation for the MPU on this chip.

Source

fn userspace_kernel_boundary(&self) -> &Self::UserspaceKernelBoundary

Returns a reference to the implementation for the interface between userspace and kernelspace.

Source

fn sleep(&self)

Called when there is nothing left for the chip to do and it should enter a low power sleep state. This low power sleep state should allow interrupts to still be active so that the next interrupt event wakes the chip and resumes the scheduler.

Source

unsafe fn with_interrupts_disabled<F, R>(&self, f: F) -> R
where F: FnOnce() -> R,

Run a function in an atomic state w.r.t. to the current core. This means that interrupts are disabled so that an interrupt will not fire during the passed in function’s execution, but does not make any guarantees about memory consistency on a multi-core system.

Source

unsafe fn print_state(this: Option<&Self>, writer: &mut dyn Write)

Print out debug information about the current chip state (system registers, MPU configuration, etc.) to a supplied writer.

This function may be called across thread boundaries (such as from a panic handler). As implementors of Chip do not have to be Send or Sync, &self may not be available in these contexts. Therefore, this function instead accepts an Option<&Self> parameter named this. In contexts where &self is available, callers should invoke this function by passing Some(&self) to this. Otherwise, this will be set to None. The implementation of print_state may not print certain information if it depends on runtime-accessible state in Self, but that reference is not provided.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§