-
Notifications
You must be signed in to change notification settings - Fork 666
/
mod.rs
53 lines (45 loc) · 1.48 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Interface for chips and boards.
use driver::Driver;
use syscall;
pub mod mpu;
crate mod systick;
/// Interface for individual boards.
pub trait Platform {
/// Platform-specific mapping of syscall numbers to objects that implement
/// the Driver methods for that syscall
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
where
F: FnOnce(Option<&Driver>) -> R;
}
/// 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
F: FnOnce() -> R;
}
/// Generic operations that clock-like things are expected to support.
pub trait ClockInterface {
fn is_enabled(&self) -> bool;
fn enable(&self);
fn disable(&self);
}
/// Helper struct for interfaces that expect clocks, but have no clock control
pub struct NoClockControl {}
impl ClockInterface for NoClockControl {
fn is_enabled(&self) -> bool {
true
}
fn enable(&self) {}
fn disable(&self) {}
}
/// Instance of NoClockControl for things that need references to `ClockInterface` objects
pub static mut NO_CLOCK_CONTROL: NoClockControl = NoClockControl {};