mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 20:51:31 +11:00
Removed incorret unsafe impl Sync, added interrupt_free around obtaining an alarm
This commit is contained in:
parent
1fd04d3384
commit
a9d96f352e
|
@ -13,9 +13,6 @@ pub struct Timer {
|
|||
alarms: [bool; 4],
|
||||
}
|
||||
|
||||
// Safety: All access is read-only.
|
||||
unsafe impl Sync for Timer {}
|
||||
|
||||
impl Timer {
|
||||
/// Create a new [`Timer`]
|
||||
pub fn new(timer: TIMER, resets: &mut RESETS) -> Self {
|
||||
|
@ -55,42 +52,50 @@ impl Timer {
|
|||
|
||||
/// Retrieve a reference to alarm 0. Will only return a value the first time this is called
|
||||
pub fn alarm_0(&mut self) -> Option<Alarm0> {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
if self.alarms[0] {
|
||||
self.alarms[0] = false;
|
||||
Some(Alarm0(PhantomData))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieve a reference to alarm 1. Will only return a value the first time this is called
|
||||
pub fn alarm_1(&mut self) -> Option<Alarm1> {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
if self.alarms[1] {
|
||||
self.alarms[1] = false;
|
||||
Some(Alarm1(PhantomData))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieve a reference to alarm 2. Will only return a value the first time this is called
|
||||
pub fn alarm_2(&mut self) -> Option<Alarm2> {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
if self.alarms[2] {
|
||||
self.alarms[2] = false;
|
||||
Some(Alarm2(PhantomData))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieve a reference to alarm 3. Will only return a value the first time this is called
|
||||
pub fn alarm_3(&mut self) -> Option<Alarm3> {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
if self.alarms[3] {
|
||||
self.alarms[3] = false;
|
||||
Some(Alarm3(PhantomData))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue