aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2019-11-19 14:00:22 +0000
committerGravatar GitHub <noreply@github.com> 2019-11-19 14:00:22 +0000
commit82efffd7069e96efa8fd5c5c93a6d8092d9993c1 (patch)
tree3374c81102bd515e47ad8b50d8453047ddc96c35 /src
parent8374fce0dfbc945f878b9c0f5525ce8d48aaa428 (diff)
parentfef738e832e3d16009ce9b33d1918e131ff9a8cf (diff)
downloadrtic-82efffd7069e96efa8fd5c5c93a6d8092d9993c1.tar.gz
rtic-82efffd7069e96efa8fd5c5c93a6d8092d9993c1.tar.zst
rtic-82efffd7069e96efa8fd5c5c93a6d8092d9993c1.zip
Merge #277
277: TimerQueue.dequeue: don't set SYST reload to 0 r=korken89 a=mpasternacki ARM Architecture Reference Manual says: "Setting SYST_RVR to zero has the effect of disabling the SysTick counter independently of the counter enable bit." If Monotonic's ratio is less than one, the timeout calculations can compute zero if next task is scheduled after current instant, but before next timer tick. This results in disabling SYST and freezing the timer queue. The division by ratio's denominator rounds downward and the dequeue condition is `if instant < now`. If ratio is small enough, this results in unnecessary interrupts: Let's say `instant - now` is 99 and ratio is 1/25. Then, `dur` will equal 3 and the next tick will happen at `now + 75`. In the next interrupt, `instant > now` and additional tick needs to be scheduled (which doesn't happen, because now `instant - now` is less than 25, so reload will be set to 0 and timer queue will stop). Adding one to computed duration will prevent both freezing and additional interrupts. When ratio is 1 or close, timer queue code overhead will prevent this from happening. I am working with a chip where CPU is clocked at 600MHz and SysTick is 100kHz and the freeze happens quite often. Co-authored-by: Maciej Pasternacki <maciej@3ofcoins.net>
Diffstat (limited to 'src')
-rw-r--r--src/tq.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/tq.rs b/src/tq.rs
index 4edb40a7..21beeb9c 100644
--- a/src/tq.rs
+++ b/src/tq.rs
@@ -68,6 +68,13 @@ where
.map(|x| x / ratio.denominator)
}) {
None => MAX,
+
+ // ARM Architecture Reference Manual says:
+ // "Setting SYST_RVR to zero has the effect of
+ // disabling the SysTick counter independently
+ // of the counter enable bit."
+ Some(0) => 1,
+
Some(x) => cmp::min(MAX, x),
};
mem::transmute::<_, SYST>(()).set_reload(dur);