Skip to content

Commit ac96b86

Browse files
ananglcarlescufi
authored andcommitted
driver: nrf_rtc_timer: Remove unnecessary setting of comparator
Remove a piece of code that was supposed to bring an extra update of the anchor value but which in fact was not able to provide it, because of the target time checking performed in process_channel(), and which is anyway unnecessary because the timeout span is limited to MAX_CYCLES in sys_clock_set_timeout(), so the timeout handler is guaranteed to be executed at least twice per each RTC overflow. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 205e684 commit ac96b86

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

drivers/timer/nrf_rtc_timer.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ static void set_comparator(int32_t chan, uint32_t cyc)
6666
nrf_rtc_cc_set(RTC, chan, cyc & COUNTER_MAX);
6767
}
6868

69-
static uint32_t get_comparator(int32_t chan)
70-
{
71-
return nrf_rtc_cc_get(RTC, chan);
72-
}
73-
7469
static bool event_check(int32_t chan)
7570
{
7671
return nrf_rtc_event_check(RTC, RTC_CHANNEL_EVENT_ADDR(chan));
@@ -387,7 +382,7 @@ static inline bool in_anchor_range(uint32_t cc_value)
387382
return (cc_value >= ANCHOR_RANGE_START) && (cc_value < ANCHOR_RANGE_END);
388383
}
389384

390-
static inline bool anchor_update(uint32_t cc_value)
385+
static inline void anchor_update(uint32_t cc_value)
391386
{
392387
/* Update anchor when far from overflow */
393388
if (in_anchor_range(cc_value)) {
@@ -397,10 +392,7 @@ static inline bool anchor_update(uint32_t cc_value)
397392
* `z_nrf_rtc_timer_read`.
398393
*/
399394
anchor = (((uint64_t)overflow_cnt) << COUNTER_BIT_WIDTH) + cc_value;
400-
return true;
401395
}
402-
403-
return false;
404396
}
405397

406398
static void sys_clock_timeout_handler(int32_t chan,
@@ -412,7 +404,7 @@ static void sys_clock_timeout_handler(int32_t chan,
412404

413405
last_count += dticks * CYC_PER_TICK;
414406

415-
bool anchor_updated = anchor_update(cc_value);
407+
anchor_update(cc_value);
416408

417409
if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) {
418410
/* protection is not needed because we are in the RTC interrupt
@@ -424,19 +416,6 @@ static void sys_clock_timeout_handler(int32_t chan,
424416

425417
sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ?
426418
(int32_t)dticks : (dticks > 0));
427-
428-
if (cc_value == get_comparator(chan)) {
429-
/* New value was not set. Set something that can update anchor.
430-
* If anchor was updated we can enable same CC value to trigger
431-
* interrupt after full cycle. Else set event in anchor update
432-
* range. Since anchor was not updated we know that it's very
433-
* far from mid point so setting is done without any protection.
434-
*/
435-
if (!anchor_updated) {
436-
set_comparator(chan, COUNTER_HALF_SPAN);
437-
}
438-
event_enable(chan);
439-
}
440419
}
441420

442421
static bool channel_processing_check_and_clear(int32_t chan)
@@ -627,6 +606,8 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
627606

628607
/* Due to elapsed time the calculation above might produce a
629608
* duration that laps the counter. Don't let it.
609+
* This limitation also guarantees that the anchor will be properly
610+
* updated before every overflow (see anchor_update()).
630611
*/
631612
if (cyc > MAX_CYCLES) {
632613
cyc = MAX_CYCLES;

0 commit comments

Comments
 (0)