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

Commit d3a91b4

Browse files
committed
clock: Add support for DPPI to CLOCK
Add use of DPPI to CLOCK if DPPI is defined. Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
1 parent 5d85a21 commit d3a91b4

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

src/HW_models/NRF_CLOCK.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <stdint.h>
99
#include "time_machine_if.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 "NRF_RTC.h"
1317
#include "irq_ctrl.h"
1418
#include "irq_sources.h"
@@ -141,7 +145,17 @@ void nrf_clock_LFTimer_triggered(){
141145
| (NRF_CLOCK_regs.LFCLKSRCCOPY << CLOCK_LFCLKSTAT_SRC_Pos);
142146

143147
NRF_CLOCK_regs.EVENTS_LFCLKSTARTED = 1;
148+
149+
#if defined(PPI_PRESENT)
144150
nrf_ppi_event(CLOCK_EVENTS_LFCLKSTARTED);
151+
#elif defined(DPPI_PRESENT)
152+
if (NRF_CLOCK_regs.PUBLISH_LFCLKSTARTED & CLOCK_PUBLISH_LFCLKSTARTED_EN_Msk)
153+
{
154+
uint8_t channel = NRF_CLOCK_regs.PUBLISH_LFCLKSTARTED & CLOCK_PUBLISH_LFCLKSTARTED_CHIDX_Msk;
155+
nrf_dppi_publish(channel);
156+
}
157+
#endif
158+
145159
if ( CLOCK_INTEN & CLOCK_INTENSET_LFCLKSTARTED_Msk ){
146160
hw_irq_ctrl_set_irq(NRF5_IRQ_POWER_CLOCK_IRQn);
147161
}
@@ -157,11 +171,26 @@ void nrf_clock_HFTimer_triggered(){
157171
if ( HF_Clock_state == Starting ){
158172
HF_Clock_state = Started;
159173

174+
#if !defined(NRF53_SERIES)
160175
NRF_CLOCK_regs.HFCLKSTAT = CLOCK_HFCLKSTAT_STATE_Msk
161176
| ( CLOCK_HFCLKSTAT_SRC_Xtal << CLOCK_HFCLKSTAT_SRC_Pos);
177+
#else
178+
NRF_CLOCK_regs.HFCLKSTAT = CLOCK_HFCLKSTAT_STATE_Msk
179+
| ( CLOCK_HFCLKSTAT_SRC_HFXO << CLOCK_HFCLKSTAT_SRC_Pos);
180+
#endif
162181

163182
NRF_CLOCK_regs.EVENTS_HFCLKSTARTED = 1;
183+
184+
#if defined(PPI_PRESENT)
164185
nrf_ppi_event(CLOCK_EVENTS_HFCLKSTARTED);
186+
#elif defined(DPPI_PRESENT)
187+
if (NRF_CLOCK_regs.PUBLISH_HFCLKSTARTED & CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk)
188+
{
189+
uint8_t channel = NRF_CLOCK_regs.PUBLISH_HFCLKSTARTED & CLOCK_PUBLISH_HFCLKSTARTED_CHIDX_Msk;
190+
nrf_dppi_publish(channel);
191+
}
192+
#endif
193+
165194
if ( CLOCK_INTEN & CLOCK_INTENSET_HFCLKSTARTED_Msk ){
166195
hw_irq_ctrl_set_irq(NRF5_IRQ_POWER_CLOCK_IRQn);
167196
}

src/HW_models/NRF_CLOCK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void nrf_clock_LFTimer_triggered();
1919
void nrf_clock_HFTimer_triggered();
2020
void nrf_clock_TASKS_LFCLKSTART();
2121
void nrf_clock_TASKS_HFCLKSTART();
22+
void nrf_clock_TASKS_HFCLKSTOP();
2223
void nrf_clock_reqw_sideeffects_INTENSET();
2324
void nrf_clock_reqw_sideeffects_INTENCLR();
2425
void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTART();

src/nrfx/hal/nrf_clock.c

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

1215
void nrf_clock_int_enable(NRF_CLOCK_Type * p_reg, uint32_t mask)
1316
{
@@ -46,3 +49,62 @@ void nrf_clock_task_trigger(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task)
4649
bs_trace_warning_line_time("Not supported task started in nrf_clock, %d\n", task);
4750
}
4851
}
52+
53+
54+
#if defined(DPPI_PRESENT)
55+
void nrf_clock_subscriber_add(nrf_clock_task_t task, uint8_t channel)
56+
{
57+
switch(task) {
58+
case NRF_CLOCK_TASK_HFCLKSTART:
59+
nrf_dppi_subscriber_add(channel, nrf_clock_TASKS_HFCLKSTART);
60+
break;
61+
case NRF_CLOCK_TASK_HFCLKSTOP:
62+
nrf_dppi_subscriber_add(channel, nrf_clock_TASKS_HFCLKSTOP);
63+
break;
64+
case NRF_CLOCK_TASK_LFCLKSTART:
65+
nrf_dppi_subscriber_add(channel, nrf_clock_TASKS_LFCLKSTART);
66+
break;
67+
default:
68+
bs_trace_warning_line_time(
69+
"NRF_CLOCK: The task %p for chnbr %i does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
70+
task, channel);
71+
break;
72+
}
73+
}
74+
75+
void nrf_clock_subscriber_remove(nrf_clock_task_t task)
76+
{
77+
switch(task) {
78+
case NRF_CLOCK_TASK_HFCLKSTART:
79+
nrf_dppi_subscriber_remove(nrf_clock_TASKS_HFCLKSTART);
80+
break;
81+
case NRF_CLOCK_TASK_HFCLKSTOP:
82+
nrf_dppi_subscriber_remove(nrf_clock_TASKS_HFCLKSTOP);
83+
break;
84+
case NRF_CLOCK_TASK_LFCLKSTART:
85+
nrf_dppi_subscriber_remove(nrf_clock_TASKS_LFCLKSTART);
86+
break;
87+
default:
88+
bs_trace_warning_line_time(
89+
"NRF_CLOCK: The task %p does not match any modelled task in NRF_DPPI.c => it will be ignored\n",
90+
task);
91+
break;
92+
}
93+
}
94+
95+
void nrf_clock_subscribe_set(NRF_CLOCK_Type * p_reg,
96+
nrf_clock_task_t task,
97+
uint8_t channel)
98+
{
99+
*((volatile uint32_t *) ((uint8_t *)p_reg+ (uint32_t)task + 0x80uL)) =
100+
((uint32_t)channel | CLOCK_SUBSCRIBE_HFCLKSTART_EN_Msk);
101+
nrf_clock_subscriber_add(task, channel);
102+
}
103+
104+
void nrf_clock_subscribe_clear(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task)
105+
{
106+
*((volatile uint32_t *) ((uint8_t *)p_reg + (uint32_t)task + 0x80uL)) = 0;
107+
nrf_clock_subscriber_remove(task);
108+
}
109+
110+
#endif // defined(DPPI_PRESENT)

0 commit comments

Comments
 (0)