Created
October 26, 2017 00:15
-
-
Save alevy/58da23cfac30d73fa566144a9e74fe4e to your computer and use it in GitHub Desktop.
Capsule "Hello World" every second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Sample capsule for Tock course at SOSP. It handles an alarm to | |
//! sample the ambient light sensor. | |
use kernel::hil::time::{self, Alarm, Frequency}; | |
use kernel::hil::sensors::{AmbientLight, AmbientLightClient}; | |
pub struct Sosp<'a, A: Alarm + 'a> { | |
alarm: &'a A, | |
light: &'a AmbientLight, | |
} | |
impl<'a, A: Alarm> Sosp<'a, A> { | |
pub fn new(alarm: &'a A, light: &'a AmbientLight) -> Sosp<'a, A> { | |
Sosp { | |
alarm: alarm, | |
light: light, | |
} | |
} | |
pub fn start(&self) { | |
self.alarm.set_alarm( | |
self.alarm.now().wrapping_add(<A::Frequency>::frequency())); | |
} | |
} | |
impl<'a, A: Alarm> time::Client for Sosp<'a, A> { | |
fn fired(&self) { | |
debug!("Hello World"); | |
self.start(); | |
} | |
} | |
impl<'a, A: Alarm> AmbientLightClient for Sosp<'a, A> { | |
fn callback(&self, lux: usize) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment