21
21
22
22
#if (CONFIG_NRF_RTC_COUNTER_BIT_WIDTH < RTC_BIT_WIDTH )
23
23
#define CUSTOM_COUNTER_BIT_WIDTH 1
24
- #define WRAP_CH 1
24
+ #define WRAP_CH 0
25
+ #define SYS_CLOCK_CH 1
25
26
#include "nrfx_ppi.h"
26
27
#else
27
28
#define CUSTOM_COUNTER_BIT_WIDTH 0
29
+ #define SYS_CLOCK_CH 0
28
30
#endif
29
31
30
32
#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \
37
39
#define RTC_IRQn NRFX_IRQ_NUMBER_GET(RTC)
38
40
#define RTC_LABEL rtc1
39
41
#define CHAN_COUNT_MAX (RTC1_CC_NUM - (RTC_PRETICK ? 1 : 0))
40
- #define SYS_CLOCK_CH 0
41
42
42
43
BUILD_ASSERT (CHAN_COUNT <= CHAN_COUNT_MAX , "Not enough compare channels" );
43
44
/* Ensure that counter driver for RTC1 is not enabled. */
@@ -275,15 +276,6 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact)
275
276
*/
276
277
enum { MIN_CYCLES_FROM_NOW = 3 };
277
278
uint32_t cc_val = req_cc ;
278
-
279
- #if CUSTOM_COUNTER_BIT_WIDTH
280
- /* If a CC value is 0 when a CLEAR task is set, this will not
281
- * trigger a COMAPRE event. Need to use 1 instead.
282
- */
283
- if (cc_val % COUNTER_MAX == 0 ) {
284
- cc_val = 1 ;
285
- }
286
- #endif
287
279
uint32_t cc_inc = MIN_CYCLES_FROM_NOW ;
288
280
289
281
/* Disable event routing for the channel to avoid getting a COMPARE
@@ -299,6 +291,14 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact)
299
291
for (;;) {
300
292
uint32_t now ;
301
293
294
+ #if CUSTOM_COUNTER_BIT_WIDTH
295
+ /* If a CC value is 0 when a CLEAR task is set, this will not
296
+ * trigger a COMAPRE event. Need to use 1 instead.
297
+ */
298
+ if ((cc_val & COUNTER_MAX ) == 0 ) {
299
+ cc_val = 1 ;
300
+ }
301
+ #endif
302
302
set_comparator (chan , cc_val );
303
303
/* Enable event routing after the required CC value was set.
304
304
* Even though the above operation may get repeated (see below),
@@ -597,16 +597,16 @@ void rtc_nrf_isr(const void *arg)
597
597
}
598
598
599
599
#if CUSTOM_COUNTER_BIT_WIDTH
600
- if (nrfy_rtc_int_enable_check (RTC , NRF_RTC_INT_COMPARE1_MASK ) &&
601
- nrfy_rtc_events_process (RTC , NRF_RTC_INT_COMPARE1_MASK )) {
600
+ if (nrfy_rtc_int_enable_check (RTC , NRF_RTC_CHANNEL_INT_MASK ( WRAP_CH ) ) &&
601
+ nrfy_rtc_events_process (RTC , NRF_RTC_CHANNEL_INT_MASK ( WRAP_CH ) )) {
602
602
#else
603
603
if (nrfy_rtc_int_enable_check (RTC , NRF_RTC_INT_OVERFLOW_MASK ) &&
604
604
nrfy_rtc_events_process (RTC , NRF_RTC_INT_OVERFLOW_MASK )) {
605
605
#endif
606
606
overflow_cnt ++ ;
607
607
}
608
608
609
- for (int32_t chan = 0 ; chan < CHAN_COUNT ; chan ++ ) {
609
+ for (int32_t chan = SYS_CLOCK_CH ; chan < CHAN_COUNT ; chan ++ ) {
610
610
process_channel (chan );
611
611
}
612
612
}
0 commit comments