some more adaptions
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-09-17 18:36:03 +02:00
parent cea9c2fc37
commit 911fe8771e
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 9 additions and 13 deletions

View File

@ -150,7 +150,9 @@ impl TimerDriverEmbassy {
let alarm = &self.alarms.borrow(cs)[i];
let at = alarm.timestamp.get();
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
.cnt_value()
@ -202,10 +204,9 @@ impl Driver for TimerDriverEmbassy {
// Double read to protect against race conditions when the counter is overflowing.
period2 = self.periods.load(Ordering::Relaxed);
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> {
@ -268,17 +269,12 @@ impl Driver for TimerDriverEmbassy {
// by the Alarm trait contract. What's not allowed is triggering alarms *before* their scheduled time,
// and we don't do that here.
let safe_timestamp = timestamp.max(t + 3);
let rst_val = timekeeping_tim().rst_value().read().bits();
let rst_val_alarm = (safe_timestamp % rst_val as u64) as u32;
alarm_tim
.rst_value()
.write(|w| unsafe { w.bits(rst_val_alarm) });
let diff = timestamp - t;
if diff < (three_quarters_of_period(rst_val as u64)) {
let diff = safe_timestamp - t;
alarm_tim.rst_value().write(|w| unsafe { w.bits(u32::MAX) });
if diff <= u32::MAX as u64 {
alarm_tim
.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.enable().write(|w| unsafe { w.bits(1) });
}

View File

@ -38,7 +38,7 @@ async fn main(_spawner: Spawner) {
let portg = PinsG::new(&mut dp.sysconfig, dp.portg);
let mut led = portg.pg5.into_readable_push_pull_output();
loop {
Timer::after_secs(1).await;
Timer::after_millis(500).await;
led.toggle().ok();
}
}