Skip to content

Commit

Permalink
drivers: timer: nrf_rtc_timer: Fix set_comparator corner case
Browse files Browse the repository at this point in the history
Update the logic in a corner case, when the target comparator value is
one cycle ahead of the counter value.

Experiments have shown, that `set_comparator(cyc + 1);` might be not
enough in that case, and we still may (rarely) miss the interrupt.
This could happen when the counter incremented its value after the `dt`
variable was set. As we should set the comparator value two cycles
ahead to be on the safe side, increment the target comparator value
by 2 instead of 1.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos authored and carlescufi committed Aug 1, 2019
1 parent e9cdcc2 commit 9f34d17
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/timer/nrf_rtc_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle)
}
} else if (dt == 1) {
/* Too soon, interrupt won't arrive. */
set_comparator(cyc + 1);
set_comparator(cyc + 2);
}
/* Otherwise it was two cycles out, we're fine */
}
Expand Down

0 comments on commit 9f34d17

Please sign in to comment.