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

Commit 1e64248

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

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/HW_models/NRF_RNG.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <stdbool.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 "irq_ctrl.h"
1317
#include "irq_sources.h"
1418
#include "bs_rand_main.h"
@@ -145,7 +149,17 @@ void nrf_rng_timer_triggered(){
145149
nrf_hw_find_next_timer_to_trigger();
146150

147151
NRF_RNG_regs.EVENTS_VALRDY = 1;
152+
153+
#if !defined(DPPI_PRESENT)
148154
nrf_ppi_event(RNG_EVENTS_VALRDY);
155+
#else
156+
if (NRF_RNG_regs.PUBLISH_VALRDY & RNG_PUBLISH_VALRDY_EN_Msk)
157+
{
158+
uint8_t channel = NRF_RNG_regs.PUBLISH_VALRDY & RNG_PUBLISH_VALRDY_CHIDX_Msk;
159+
nrf_dppi_publish(channel);
160+
}
161+
#endif
162+
149163
if ( RNG_INTEN ){
150164
hw_irq_ctrl_set_irq(NRF5_IRQ_RNG_IRQn);
151165
//Note: there is no real need to delay the interrupt a delta

src/nrfx/hal/nrf_rng.c

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

1215
void nrf_rng_task_trigger(NRF_RNG_Type * p_reg, nrf_rng_task_t rng_task)
1316
{
@@ -35,3 +38,52 @@ void nrf_rng_int_disable(NRF_RNG_Type * p_reg, uint32_t mask)
3538
NRF_RNG_regs.INTENCLR = mask;
3639
nrf_rng_regw_sideeffects_INTENCLEAR();
3740
}
41+
42+
#if defined(DPPI_PRESENT)
43+
void nrf_rng_subscriber_add(nrf_rng_task_t task, uint8_t channel)
44+
{
45+
switch(task)
46+
{
47+
case NRF_RNG_TASK_START:
48+
nrf_dppi_subscriber_add(channel, nrf_rng_task_start);
49+
break;
50+
case NRF_RNG_TASK_STOP:
51+
nrf_dppi_subscriber_add(channel, nrf_rng_task_stop);
52+
break;
53+
default:
54+
break;
55+
}
56+
}
57+
58+
void nrf_rng_subscriber_remove(nrf_rng_task_t task)
59+
{
60+
switch(task)
61+
{
62+
case NRF_RNG_TASK_START:
63+
nrf_dppi_subscriber_remove(nrf_rng_task_start);
64+
break;
65+
case NRF_RNG_TASK_STOP:
66+
nrf_dppi_subscriber_remove(nrf_rng_task_stop);
67+
break;
68+
default:
69+
break;
70+
}
71+
}
72+
73+
void nrf_rng_subscribe_set(NRF_RNG_Type * p_reg,
74+
nrf_rng_task_t task,
75+
uint8_t channel)
76+
{
77+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
78+
((uint32_t)channel | RNG_SUBSCRIBE_START_EN_Msk);
79+
nrf_rng_subscriber_add(task, channel);
80+
}
81+
82+
83+
void nrf_rng_subscribe_clear(NRF_RNG_Type * p_reg,
84+
nrf_rng_task_t task)
85+
{
86+
*((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
87+
nrf_rng_subscriber_remove(task);
88+
}
89+
#endif // defined(DPPI_PRESENT)

0 commit comments

Comments
 (0)