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

Commit abb53a0

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

File tree

2 files changed

+323
-1
lines changed

2 files changed

+323
-1
lines changed

src/HW_models/NRF_TIMER.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include "time_machine_if.h"
99
#include "NRF_TIMER.h"
1010
#include "NRF_HW_model_top.h"
11+
#if defined(PPI_PRESENT)
1112
#include "NRF_PPI.h"
13+
#elif defined(DPPI_PRESENT)
14+
#include "NRF_DPPI.h"
15+
#endif
1216
#include "irq_ctrl.h"
1317
#include "irq_sources.h"
1418
#include "bs_tracing.h"
@@ -344,6 +348,7 @@ void nrf_timer_timer_triggered() {
344348

345349
NRF_TIMER_regs[t].EVENTS_COMPARE[cc] = 1;
346350

351+
#if !defined(DPPI_PRESENT)
347352
ppi_event_types_t event_cc;
348353
switch (t) {
349354
case 0:
@@ -365,6 +370,13 @@ void nrf_timer_timer_triggered() {
365370
}
366371

367372
nrf_ppi_event(event_cc + cc);
373+
#else
374+
if (NRF_TIMER_regs[t].PUBLISH_COMPARE[cc] & TIMER_PUBLISH_COMPARE_EN_Msk)
375+
{
376+
uint8_t channel = NRF_TIMER_regs[t].PUBLISH_COMPARE[cc] & TIMER_PUBLISH_COMPARE_CHIDX_Msk;
377+
nrf_dppi_publish(channel);
378+
}
379+
#endif
368380

369381
if ( TIMER_INTEN[t] & (TIMER_INTENSET_COMPARE0_Msk << cc) ){
370382
int irq = NRF5_IRQ_TIMER0_IRQn;
@@ -391,4 +403,3 @@ void nrf_timer_timer_triggered() {
391403
}//for t(imer)
392404
update_master_timer();
393405
}
394-

src/nrfx/hal/nrf_timer.c

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

1215
static int timer_number_from_ptr(NRF_TIMER_Type * p_reg){
1316
int i = ( (int)p_reg - (int)&NRF_TIMER_regs[0] ) / sizeof(NRF_TIMER_Type);
@@ -83,6 +86,314 @@ void nrf_timer_int_disable(NRF_TIMER_Type * p_reg,
8386
nrf_timer_regw_sideeffects_INTENCLR(i);
8487
}
8588

89+
#if defined(DPPI_PRESENT)
90+
91+
void nrf_timer_subscriber_add(int timer_number, nrf_timer_task_t task, uint8_t channel)
92+
{
93+
switch(timer_number)
94+
{
95+
case 0:
96+
switch(task)
97+
{
98+
case NRF_TIMER_TASK_START:
99+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_START);
100+
break;
101+
case NRF_TIMER_TASK_STOP:
102+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_STOP);
103+
break;
104+
case NRF_TIMER_TASK_COUNT:
105+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_COUNT);
106+
break;
107+
case NRF_TIMER_TASK_CLEAR:
108+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CLEAR);
109+
break;
110+
case NRF_TIMER_TASK_CAPTURE0:
111+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_0);
112+
break;
113+
case NRF_TIMER_TASK_CAPTURE1:
114+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_1);
115+
break;
116+
case NRF_TIMER_TASK_CAPTURE2:
117+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_2);
118+
break;
119+
case NRF_TIMER_TASK_CAPTURE3:
120+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_3);
121+
break;
122+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
123+
case NRF_TIMER_TASK_CAPTURE4:
124+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_4);
125+
break;
126+
#endif
127+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
128+
case NRF_TIMER_TASK_CAPTURE5:
129+
nrf_dppi_subscriber_add(channel, nrf_timer0_TASK_CAPTURE_5);
130+
break;
131+
#endif
132+
default:
133+
bs_trace_warning_line_time(
134+
"NRF_TIMER%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
135+
timer_number, task, channel);
136+
break;
137+
}
138+
break;
139+
case 1:
140+
switch(task)
141+
{
142+
case NRF_TIMER_TASK_START:
143+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_START);
144+
break;
145+
case NRF_TIMER_TASK_STOP:
146+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_STOP);
147+
break;
148+
case NRF_TIMER_TASK_COUNT:
149+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_COUNT);
150+
break;
151+
case NRF_TIMER_TASK_CLEAR:
152+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CLEAR);
153+
break;
154+
case NRF_TIMER_TASK_CAPTURE0:
155+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_0);
156+
break;
157+
case NRF_TIMER_TASK_CAPTURE1:
158+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_1);
159+
break;
160+
case NRF_TIMER_TASK_CAPTURE2:
161+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_2);
162+
break;
163+
case NRF_TIMER_TASK_CAPTURE3:
164+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_3);
165+
break;
166+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
167+
case NRF_TIMER_TASK_CAPTURE4:
168+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_4);
169+
break;
170+
#endif
171+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
172+
case NRF_TIMER_TASK_CAPTURE5:
173+
nrf_dppi_subscriber_add(channel, nrf_timer1_TASK_CAPTURE_5);
174+
break;
175+
#endif
176+
default:
177+
bs_trace_warning_line_time(
178+
"NRF_TIMER%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
179+
timer_number, task, channel);
180+
break;
181+
}
182+
break;
183+
case 2:
184+
switch(task)
185+
{
186+
case NRF_TIMER_TASK_START:
187+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_START);
188+
break;
189+
case NRF_TIMER_TASK_STOP:
190+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_STOP);
191+
break;
192+
case NRF_TIMER_TASK_COUNT:
193+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_COUNT);
194+
break;
195+
case NRF_TIMER_TASK_CLEAR:
196+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CLEAR);
197+
break;
198+
case NRF_TIMER_TASK_CAPTURE0:
199+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_0);
200+
break;
201+
case NRF_TIMER_TASK_CAPTURE1:
202+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_1);
203+
break;
204+
case NRF_TIMER_TASK_CAPTURE2:
205+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_2);
206+
break;
207+
case NRF_TIMER_TASK_CAPTURE3:
208+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_3);
209+
break;
210+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
211+
case NRF_TIMER_TASK_CAPTURE4:
212+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_4);
213+
break;
214+
#endif
215+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
216+
case NRF_TIMER_TASK_CAPTURE5:
217+
nrf_dppi_subscriber_add(channel, nrf_timer2_TASK_CAPTURE_5);
218+
break;
219+
#endif
220+
default:
221+
bs_trace_warning_line_time(
222+
"NRF_TIMER%i: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
223+
timer_number, task, channel);
224+
break;
225+
}
226+
break;
227+
default:
228+
bs_trace_warning_line_time(
229+
"NRF_TIMER: The timer number %i does not match any modelled TIMER => it will be ignored\n",
230+
timer_number);
231+
break;
232+
}
233+
}
234+
235+
void nrf_timer_subscriber_remove(int timer_number, nrf_timer_task_t task)
236+
{
237+
switch(timer_number)
238+
{
239+
case 0:
240+
switch(task)
241+
{
242+
case NRF_TIMER_TASK_START:
243+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_START);
244+
break;
245+
case NRF_TIMER_TASK_STOP:
246+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_STOP);
247+
break;
248+
case NRF_TIMER_TASK_COUNT:
249+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_COUNT);
250+
break;
251+
case NRF_TIMER_TASK_CLEAR:
252+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CLEAR);
253+
break;
254+
case NRF_TIMER_TASK_CAPTURE0:
255+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_0);
256+
break;
257+
case NRF_TIMER_TASK_CAPTURE1:
258+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_1);
259+
break;
260+
case NRF_TIMER_TASK_CAPTURE2:
261+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_2);
262+
break;
263+
case NRF_TIMER_TASK_CAPTURE3:
264+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_3);
265+
break;
266+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
267+
case NRF_TIMER_TASK_CAPTURE4:
268+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_4);
269+
break;
270+
#endif
271+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
272+
case NRF_TIMER_TASK_CAPTURE5:
273+
nrf_dppi_subscriber_remove(nrf_timer0_TASK_CAPTURE_5);
274+
break;
275+
#endif
276+
default:
277+
bs_trace_warning_line_time(
278+
"NRF_TIMER%i: The task %p does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
279+
timer_number, task);
280+
break;
281+
}
282+
break;
283+
case 1:
284+
switch(task)
285+
{
286+
case NRF_TIMER_TASK_START:
287+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_START);
288+
break;
289+
case NRF_TIMER_TASK_STOP:
290+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_STOP);
291+
break;
292+
case NRF_TIMER_TASK_COUNT:
293+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_COUNT);
294+
break;
295+
case NRF_TIMER_TASK_CLEAR:
296+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CLEAR);
297+
break;
298+
case NRF_TIMER_TASK_CAPTURE0:
299+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_0);
300+
break;
301+
case NRF_TIMER_TASK_CAPTURE1:
302+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_1);
303+
break;
304+
case NRF_TIMER_TASK_CAPTURE2:
305+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_2);
306+
break;
307+
case NRF_TIMER_TASK_CAPTURE3:
308+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_3);
309+
break;
310+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
311+
case NRF_TIMER_TASK_CAPTURE4:
312+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_4);
313+
break;
314+
#endif
315+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
316+
case NRF_TIMER_TASK_CAPTURE5:
317+
nrf_dppi_subscriber_remove(nrf_timer1_TASK_CAPTURE_5);
318+
break;
319+
#endif
320+
default:
321+
bs_trace_warning_line_time(
322+
"NRF_TIMER%i: The task %p does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
323+
timer_number, task);
324+
break;
325+
}
326+
break;
327+
case 2:
328+
switch(task)
329+
{
330+
case NRF_TIMER_TASK_START:
331+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_START);
332+
break;
333+
case NRF_TIMER_TASK_STOP:
334+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_STOP);
335+
break;
336+
case NRF_TIMER_TASK_COUNT:
337+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_COUNT);
338+
break;
339+
case NRF_TIMER_TASK_CLEAR:
340+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CLEAR);
341+
break;
342+
case NRF_TIMER_TASK_CAPTURE0:
343+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_0);
344+
break;
345+
case NRF_TIMER_TASK_CAPTURE1:
346+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_1);
347+
break;
348+
case NRF_TIMER_TASK_CAPTURE2:
349+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_2);
350+
break;
351+
case NRF_TIMER_TASK_CAPTURE3:
352+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_3);
353+
break;
354+
#if defined(TIMER_INTENSET_COMPARE4_Msk)
355+
case NRF_TIMER_TASK_CAPTURE4:
356+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_4);
357+
break;
358+
#endif
359+
#if defined(TIMER_INTENSET_COMPARE5_Msk)
360+
case NRF_TIMER_TASK_CAPTURE5:
361+
nrf_dppi_subscriber_remove(nrf_timer2_TASK_CAPTURE_5);
362+
break;
363+
#endif
364+
default:
365+
bs_trace_warning_line_time(
366+
"NRF_TIMER%i: The task %p does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
367+
timer_number, task);
368+
break;
369+
}
370+
break;
371+
default:
372+
bs_trace_warning_line_time(
373+
"NRF_TIMER: The timer number %i does not match any modelled TIMER => it will be ignored\n",
374+
timer_number);
375+
break;
376+
}
377+
}
378+
379+
void nrf_timer_subscribe_set(NRF_TIMER_Type * p_reg,
380+
nrf_timer_task_t task,
381+
uint8_t channel)
382+
{
383+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
384+
((uint32_t)channel | TIMER_SUBSCRIBE_START_EN_Msk);
385+
nrf_timer_subscriber_add(timer_number_from_ptr(p_reg), task, channel);
386+
}
387+
388+
void nrf_timer_subscribe_clear(NRF_TIMER_Type * p_reg,
389+
nrf_timer_task_t task)
390+
{
391+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
392+
nrf_timer_subscriber_remove(timer_number_from_ptr(p_reg), task);
393+
}
394+
395+
#endif // defined(DPPI_PRESENT)
396+
86397
void nrf_timer_mode_set(NRF_TIMER_Type * p_reg,
87398
nrf_timer_mode_t mode)
88399
{

0 commit comments

Comments
 (0)