some more adaptions
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
cea9c2fc37
commit
911fe8771e
@ -150,7 +150,9 @@ impl TimerDriverEmbassy {
|
|||||||
let alarm = &self.alarms.borrow(cs)[i];
|
let alarm = &self.alarms.borrow(cs)[i];
|
||||||
let at = alarm.timestamp.get();
|
let at = alarm.timestamp.get();
|
||||||
let alarm_tim = alarm_tim(0);
|
let alarm_tim = alarm_tim(0);
|
||||||
if at < t + three_quarters_of_period(rst_val) {
|
if at < t {
|
||||||
|
self.trigger_alarm(i, cs);
|
||||||
|
} else if at - t <= u32::MAX as u64 {
|
||||||
alarm_tim.enable().write(|w| unsafe { w.bits(0) });
|
alarm_tim.enable().write(|w| unsafe { w.bits(0) });
|
||||||
alarm_tim
|
alarm_tim
|
||||||
.cnt_value()
|
.cnt_value()
|
||||||
@ -202,10 +204,9 @@ impl Driver for TimerDriverEmbassy {
|
|||||||
// Double read to protect against race conditions when the counter is overflowing.
|
// Double read to protect against race conditions when the counter is overflowing.
|
||||||
period2 = self.periods.load(Ordering::Relaxed);
|
period2 = self.periods.load(Ordering::Relaxed);
|
||||||
if period1 == period2 {
|
if period1 == period2 {
|
||||||
break;
|
return (period1 as u64 * rst_val as u64) + counter_val as u64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(period1 as u64 * rst_val as u64) + counter_val as u64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
||||||
@ -268,17 +269,12 @@ impl Driver for TimerDriverEmbassy {
|
|||||||
// by the Alarm trait contract. What's not allowed is triggering alarms *before* their scheduled time,
|
// by the Alarm trait contract. What's not allowed is triggering alarms *before* their scheduled time,
|
||||||
// and we don't do that here.
|
// and we don't do that here.
|
||||||
let safe_timestamp = timestamp.max(t + 3);
|
let safe_timestamp = timestamp.max(t + 3);
|
||||||
let rst_val = timekeeping_tim().rst_value().read().bits();
|
let diff = safe_timestamp - t;
|
||||||
let rst_val_alarm = (safe_timestamp % rst_val as u64) as u32;
|
alarm_tim.rst_value().write(|w| unsafe { w.bits(u32::MAX) });
|
||||||
alarm_tim
|
if diff <= u32::MAX as u64 {
|
||||||
.rst_value()
|
|
||||||
.write(|w| unsafe { w.bits(rst_val_alarm) });
|
|
||||||
|
|
||||||
let diff = timestamp - t;
|
|
||||||
if diff < (three_quarters_of_period(rst_val as u64)) {
|
|
||||||
alarm_tim
|
alarm_tim
|
||||||
.cnt_value()
|
.cnt_value()
|
||||||
.write(|w| unsafe { w.bits(rst_val_alarm) });
|
.write(|w| unsafe { w.bits(diff as u32) });
|
||||||
alarm_tim.ctrl().modify(|_, w| w.irq_enb().set_bit());
|
alarm_tim.ctrl().modify(|_, w| w.irq_enb().set_bit());
|
||||||
alarm_tim.enable().write(|w| unsafe { w.bits(1) });
|
alarm_tim.enable().write(|w| unsafe { w.bits(1) });
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
let portg = PinsG::new(&mut dp.sysconfig, dp.portg);
|
let portg = PinsG::new(&mut dp.sysconfig, dp.portg);
|
||||||
let mut led = portg.pg5.into_readable_push_pull_output();
|
let mut led = portg.pg5.into_readable_push_pull_output();
|
||||||
loop {
|
loop {
|
||||||
Timer::after_secs(1).await;
|
Timer::after_millis(500).await;
|
||||||
led.toggle().ok();
|
led.toggle().ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user