Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 43afd6c

Browse files
committed
rtc: Add support for DPPI to RTC
Add use of DPPI to RTC if DPPI is defined. Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
1 parent abb53a0 commit 43afd6c

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed

src/HW_models/NRF_RTC.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
#include <stdbool.h>
88
#include <stdint.h>
99
#include "NRF_RTC.h"
10+
#if defined(PPI_PRESENT)
1011
#include "NRF_PPI.h"
12+
#elif defined(DPPI_PRESENT)
13+
#include "NRF_DPPI.h"
14+
#endif
1115
#include "NRF_CLOCK.h"
1216
#include "NRF_HW_model_top.h"
1317
#include "irq_ctrl.h"
@@ -200,6 +204,7 @@ static unsigned int get_irq_t(int rtc)
200204
return irq_t;
201205
}
202206

207+
#if defined(PPI_PRESENT)
203208
static ppi_event_types_t get_event(int rtc)
204209
{
205210
ppi_event_types_t event = RTC0_EVENTS_COMPARE_0;
@@ -217,19 +222,27 @@ static ppi_event_types_t get_event(int rtc)
217222

218223
return event;
219224
}
225+
#endif /*PPI_PRESENT*/
220226

221227
void nrf_rtc_timer_triggered() {
222228
for ( int rtc = 0; rtc < N_RTC-1/*the 3rd rtc does not have an int*/ ; rtc++ ){
223229
if ( RTC_Running[rtc] == false ) {
224230
continue;
225231
}
232+
233+
#if defined(PPI_PRESENT)
226234
ppi_event_types_t event = get_event(rtc);
235+
#endif
227236

228237
NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc];
229238

230239
uint32_t mask = RTC_EVTEN_COMPARE0_Msk;
231240

241+
#if defined(PPI_PRESENT)
232242
for ( int cc = 0 ; cc < N_CC ; cc++, event++, mask <<=1) {
243+
#else
244+
for ( int cc = 0 ; cc < N_CC ; cc++, mask <<=1) {
245+
#endif
233246
if ( cc_timers[rtc][cc] == Timer_RTC ){ //This CC is matching now
234247
update_cc_timer(rtc, cc); //Next time it will match
235248

@@ -238,7 +251,12 @@ void nrf_rtc_timer_triggered() {
238251
if ( ( RTC_regs->EVTEN | RTC_INTEN[rtc] ) & mask ) {
239252
RTC_regs->EVENTS_COMPARE[cc] = 1;
240253
if ( RTC_regs->EVTEN & mask ){
254+
#if defined(PPI_PRESENT)
241255
nrf_ppi_event(event);
256+
#elif defined(DPPI_PRESENT)
257+
uint8_t channel = NRF_RTC_regs[rtc].PUBLISH_COMPARE[cc] & RTC_PUBLISH_COMPARE_CHIDX_Msk;
258+
nrf_dppi_publish(channel);
259+
#endif
242260
}
243261
if ( RTC_INTEN[rtc] & mask ){
244262
hw_irq_ctrl_set_irq(get_irq_t(rtc));

src/HW_models/NRF_RTC.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ void nrf_rtc_clean_up();
1818
void nrf_rtc_LF_tick();
1919
void nrf_rtc_timer_triggered();
2020
void nrf_rtc_update_COUNTER(int rtc);
21+
void nrf_rtc0_TASKS_START();
22+
void nrf_rtc0_TASKS_STOP();
23+
void nrf_rtc0_TASKS_CLEAR();
24+
void nrf_rtc1_TASKS_START();
25+
void nrf_rtc1_TASKS_STOP();
26+
void nrf_rtc1_TASKS_CLEAR();
27+
void nrf_rtc2_TASKS_START();
28+
void nrf_rtc2_TASKS_STOP();
29+
void nrf_rtc2_TASKS_CLEAR();
2130
void nrf_rtc_regw_sideeffect_TASKS_START(int i);
2231
void nrf_rtc_regw_sideeffect_TASKS_STOP(int i);
2332
void nrf_rtc_regw_sideeffect_TASKS_CLEAR(int i);

src/nrfx/hal/nrf_rtc.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "hal/nrf_rtc.h"
99
#include "bs_tracing.h"
1010
#include "NRF_RTC.h"
11+
#if defined(DPPI_PRESENT)
12+
#include "NRF_DPPI.h"
13+
#endif
1114

1215
static int rtc_number_from_ptr(NRF_RTC_Type const * p_reg){
1316
int i = ( (int)p_reg - (int)&NRF_RTC_regs[0] ) / sizeof(NRF_RTC_Type);
@@ -35,6 +38,163 @@ void nrf_rtc_int_disable(NRF_RTC_Type * p_reg, uint32_t mask)
3538
nrf_rtc_regw_sideeffect_INTENCLR(i);
3639
}
3740

41+
#if defined(DPPI_PRESENT)
42+
43+
void nrf_rtc_subscriber_add(int rtc_number, nrf_rtc_task_t task, uint8_t channel)
44+
{
45+
switch(rtc_number)
46+
{
47+
case 0:
48+
switch(task)
49+
{
50+
case NRF_RTC_TASK_START:
51+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_START);
52+
break;
53+
case NRF_RTC_TASK_STOP:
54+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_STOP);
55+
break;
56+
case NRF_RTC_TASK_CLEAR:
57+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_CLEAR);
58+
break;
59+
default:
60+
bs_trace_warning_line_time(
61+
"NRF_RTC%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
62+
rtc_number, task, channel);
63+
break;
64+
}
65+
break;
66+
case 1:
67+
switch(task)
68+
{
69+
case NRF_RTC_TASK_START:
70+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_START);
71+
break;
72+
case NRF_RTC_TASK_STOP:
73+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_STOP);
74+
break;
75+
case NRF_RTC_TASK_CLEAR:
76+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_CLEAR);
77+
break;
78+
default:
79+
bs_trace_warning_line_time(
80+
"NRF_RTC%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
81+
rtc_number, task, channel);
82+
break;
83+
}
84+
break;
85+
case 2:
86+
switch(task)
87+
{
88+
case NRF_RTC_TASK_START:
89+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_START);
90+
break;
91+
case NRF_RTC_TASK_STOP:
92+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_STOP);
93+
break;
94+
case NRF_RTC_TASK_CLEAR:
95+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_CLEAR);
96+
break;
97+
default:
98+
bs_trace_warning_line_time(
99+
"NRF_RTC%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
100+
rtc_number, task, channel);
101+
break;
102+
}
103+
break;
104+
default:
105+
bs_trace_warning_line_time(
106+
"NRF_RTC: The rtc number %p does not match any modelled RTC => it will be ignored\n",
107+
rtc_number);
108+
break;
109+
}
110+
}
111+
112+
void nrf_rtc_subscriber_remove(int rtc_number, nrf_rtc_task_t task)
113+
{
114+
switch(rtc_number)
115+
{
116+
case 0:
117+
switch(task)
118+
{
119+
case NRF_RTC_TASK_START:
120+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_START);
121+
break;
122+
case NRF_RTC_TASK_STOP:
123+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_STOP);
124+
break;
125+
case NRF_RTC_TASK_CLEAR:
126+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_CLEAR);
127+
break;
128+
default:
129+
bs_trace_warning_line_time(
130+
"NRF_RTC%i: The task %p fdoes not match any modelled task in NRF_DPPI.c => it will be ignored\n",
131+
rtc_number, task);
132+
break;
133+
}
134+
break;
135+
case 1:
136+
switch(task)
137+
{
138+
case NRF_RTC_TASK_START:
139+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_START);
140+
break;
141+
case NRF_RTC_TASK_STOP:
142+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_STOP);
143+
break;
144+
case NRF_RTC_TASK_CLEAR:
145+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_CLEAR);
146+
break;
147+
default:
148+
bs_trace_warning_line_time(
149+
"NRF_RTC%i: The task %p fdoes not match any modelled task in NRF_DPPI.c => it will be ignored\n",
150+
rtc_number, task);
151+
break;
152+
}
153+
break;
154+
case 2:
155+
switch(task)
156+
{
157+
case NRF_RTC_TASK_START:
158+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_START);
159+
break;
160+
case NRF_RTC_TASK_STOP:
161+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_STOP);
162+
break;
163+
case NRF_RTC_TASK_CLEAR:
164+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_CLEAR);
165+
break;
166+
default:
167+
bs_trace_warning_line_time(
168+
"NRF_RTC%i: The task %p fdoes not match any modelled task in NRF_DPPI.c => it will be ignored\n",
169+
rtc_number, task);
170+
break;
171+
}
172+
break;
173+
default:
174+
bs_trace_warning_line_time(
175+
"NRF_RTC: The rtc number %i does not match any modelled RTC => it will be ignored\n",
176+
rtc_number);
177+
break;
178+
}
179+
}
180+
181+
void nrf_rtc_subscribe_set(NRF_RTC_Type * p_reg,
182+
nrf_rtc_task_t task,
183+
uint8_t channel)
184+
{
185+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
186+
((uint32_t)channel | RTC_SUBSCRIBE_START_EN_Msk);
187+
nrf_rtc_subscriber_add(rtc_number_from_ptr(p_reg), task, channel);
188+
}
189+
190+
void nrf_rtc_subscribe_clear(NRF_RTC_Type * p_reg,
191+
nrf_rtc_task_t task)
192+
{
193+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
194+
nrf_rtc_subscriber_remove(rtc_number_from_ptr(p_reg), task);
195+
}
196+
#endif // defined(DPPI_PRESENT)
197+
38198
uint32_t nrf_rtc_counter_get(NRF_RTC_Type const * p_reg)
39199
{
40200
int i = rtc_number_from_ptr(p_reg);

0 commit comments

Comments
 (0)