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

Commit 829ad62

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 842dac6 commit 829ad62

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-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: 130 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,133 @@ 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) || defined(__NRFX_DOXYGEN__)
42+
43+
void nrf_rtc_subscriber_add(int rtc_number, nrf_rtc_task_t task, uint8_t channel)
44+
{
45+
switch(task)
46+
{
47+
case NRF_RTC_TASK_START:
48+
switch(rtc_number)
49+
{
50+
case 0:
51+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_START);
52+
break;
53+
case 1:
54+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_START);
55+
break;
56+
case 2:
57+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_START);
58+
break;
59+
}
60+
break;
61+
case NRF_RTC_TASK_STOP:
62+
switch(rtc_number)
63+
{
64+
case 0:
65+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_STOP);
66+
break;
67+
case 1:
68+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_STOP);
69+
break;
70+
case 2:
71+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_STOP);
72+
break;
73+
}
74+
break;
75+
case NRF_RTC_TASK_CLEAR:
76+
switch(rtc_number)
77+
{
78+
case 0:
79+
nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_START);
80+
break;
81+
case 1:
82+
nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_START);
83+
break;
84+
case 2:
85+
nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_START);
86+
break;
87+
}
88+
break;
89+
default:
90+
break;
91+
}
92+
}
93+
94+
void nrf_rtc_subscriber_remove(int rtc_number, nrf_rtc_task_t task)
95+
{
96+
switch(rtc_number)
97+
{
98+
case 0:
99+
switch(task)
100+
{
101+
case NRF_RTC_TASK_START:
102+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_START);
103+
break;
104+
case NRF_RTC_TASK_STOP:
105+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_STOP);
106+
break;
107+
case NRF_RTC_TASK_CLEAR:
108+
nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_CLEAR);
109+
break;
110+
default:
111+
break;
112+
}
113+
break;
114+
case 1:
115+
switch(task)
116+
{
117+
case NRF_RTC_TASK_START:
118+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_START);
119+
break;
120+
case NRF_RTC_TASK_STOP:
121+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_STOP);
122+
break;
123+
case NRF_RTC_TASK_CLEAR:
124+
nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_CLEAR);
125+
break;
126+
default:
127+
break;
128+
}
129+
break;
130+
case 2:
131+
switch(task)
132+
{
133+
case NRF_RTC_TASK_START:
134+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_START);
135+
break;
136+
case NRF_RTC_TASK_STOP:
137+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_STOP);
138+
break;
139+
case NRF_RTC_TASK_CLEAR:
140+
nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_CLEAR);
141+
break;
142+
default:
143+
break;
144+
}
145+
break;
146+
default:
147+
break;
148+
}
149+
}
150+
151+
void nrf_rtc_subscribe_set(NRF_RTC_Type * p_reg,
152+
nrf_rtc_task_t task,
153+
uint8_t channel)
154+
{
155+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
156+
((uint32_t)channel | RTC_SUBSCRIBE_START_EN_Msk);
157+
nrf_rtc_subscriber_add(rtc_number_from_ptr(p_reg), task, channel);
158+
}
159+
160+
void nrf_rtc_subscribe_clear(NRF_RTC_Type * p_reg,
161+
nrf_rtc_task_t task)
162+
{
163+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
164+
nrf_rtc_subscriber_remove(rtc_number_from_ptr(p_reg), task);
165+
}
166+
#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
167+
38168
uint32_t nrf_rtc_counter_get(NRF_RTC_Type const * p_reg)
39169
{
40170
int i = rtc_number_from_ptr(p_reg);

0 commit comments

Comments
 (0)