RNG: Use common templates
To save code and avoid silly errors Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
75a6cb4fd0
commit
eaa89dab76
|
@ -28,6 +28,7 @@
|
|||
#include "NHW_config.h"
|
||||
#include "NHW_peri_types.h"
|
||||
#include "NHW_common_types.h"
|
||||
#include "NHW_templates.h"
|
||||
#include "NHW_RNG.h"
|
||||
#include "NHW_xPPI.h"
|
||||
#include "nsi_hw_scheduler.h"
|
||||
|
@ -42,11 +43,9 @@ static bs_time_t Timer_RNG = TIME_NEVER; //Time when the next random number will
|
|||
static bool RNG_hw_started = false;
|
||||
static bool RNG_INTEN = false; //interrupt enable
|
||||
|
||||
/* Mapping of peripheral instance to {int controller instance, int number} */
|
||||
static struct nhw_irq_mapping nhw_rng_irq_map[NHW_RNG_TOTAL_INST] = NHW_RNG_INT_MAP;
|
||||
#if (NHW_HAS_DPPI)
|
||||
/* Mapping of peripheral instance to DPPI instance */
|
||||
static uint nhw_rng_dppi_map[NHW_RNG_TOTAL_INST] = NHW_RNG_DPPI_MAP;
|
||||
static uint nhw_RNG_dppi_map[NHW_RNG_TOTAL_INST] = NHW_RNG_DPPI_MAP;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -79,29 +78,25 @@ static void nhw_rng_schedule_next(bool first_time){
|
|||
nsi_hws_find_next_event();
|
||||
}
|
||||
|
||||
static void nhw_rng_eval_interrupt(uint inst) {
|
||||
static void nhw_RNG_eval_interrupt(uint inst) {
|
||||
static bool rng_int_line[NHW_RNG_TOTAL_INST]; /* Is the RNG currently driving its interrupt line high */
|
||||
/* Mapping of peripheral instance to {int controller instance, int number} */
|
||||
static struct nhw_irq_mapping nhw_rng_irq_map[NHW_RNG_TOTAL_INST] = NHW_RNG_INT_MAP;
|
||||
bool new_int_line = false;
|
||||
|
||||
if (NRF_RNG_regs.EVENTS_VALRDY && (RNG_INTEN & RNG_INTENCLR_VALRDY_Msk)){
|
||||
new_int_line = true;
|
||||
}
|
||||
|
||||
if (rng_int_line[inst] == false && new_int_line == true) {
|
||||
rng_int_line[inst] = true;
|
||||
hw_irq_ctrl_raise_level_irq_line(nhw_rng_irq_map[inst].cntl_inst,
|
||||
nhw_rng_irq_map[inst].int_nbr);
|
||||
} else if (rng_int_line[inst] == true && new_int_line == false) {
|
||||
rng_int_line[inst] = false;
|
||||
hw_irq_ctrl_lower_level_irq_line(nhw_rng_irq_map[inst].cntl_inst,
|
||||
nhw_rng_irq_map[inst].int_nbr);
|
||||
}
|
||||
hw_irq_ctrl_toggle_level_irq_line_if(&rng_int_line[inst],
|
||||
new_int_line,
|
||||
&nhw_rng_irq_map[inst]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TASK_START triggered handler
|
||||
*/
|
||||
void nhw_rng_task_start(void) {
|
||||
void nhw_RNG_TASK_START(void) {
|
||||
if (RNG_hw_started) {
|
||||
return;
|
||||
}
|
||||
|
@ -112,85 +107,33 @@ void nhw_rng_task_start(void) {
|
|||
/**
|
||||
* TASK_STOP triggered handler
|
||||
*/
|
||||
void nhw_rng_task_stop(void) {
|
||||
void nhw_RNG_TASK_STOP(void) {
|
||||
RNG_hw_started = false;
|
||||
Timer_RNG = TIME_NEVER;
|
||||
nsi_hws_find_next_event();
|
||||
}
|
||||
|
||||
|
||||
void nhw_rng_regw_sideeffects_TASK_START(void) {
|
||||
if (NRF_RNG_regs.TASKS_START) { /* LCOV_EXCL_BR_LINE */
|
||||
NRF_RNG_regs.TASKS_START = 0;
|
||||
nhw_rng_task_start();
|
||||
}
|
||||
}
|
||||
|
||||
void nhw_rng_regw_sideeffects_TASK_STOP(void) {
|
||||
if (NRF_RNG_regs.TASKS_STOP) { /* LCOV_EXCL_BR_LINE */
|
||||
NRF_RNG_regs.TASKS_STOP = 0;
|
||||
nhw_rng_task_stop();
|
||||
}
|
||||
}
|
||||
NHW_SIDEEFFECTS_TASKS_si(RNG, START)
|
||||
NHW_SIDEEFFECTS_TASKS_si(RNG, STOP)
|
||||
|
||||
#if (NHW_HAS_DPPI)
|
||||
void nhw_rng_regw_sideeffects_SUBSCRIBE_START(unsigned int inst) {
|
||||
static struct nhw_subsc_mem START_subscribed[NHW_RNG_TOTAL_INST];
|
||||
|
||||
nhw_dppi_common_subscribe_sideeffect(nhw_rng_dppi_map[inst],
|
||||
NRF_RNG_regs.SUBSCRIBE_START,
|
||||
&START_subscribed[inst],
|
||||
(dppi_callback_t)nhw_rng_task_start,
|
||||
DPPI_CB_NO_PARAM);
|
||||
}
|
||||
|
||||
void nhw_rng_regw_sideeffects_SUBSCRIBE_STOP(unsigned int inst) {
|
||||
static struct nhw_subsc_mem STOP_subscribed[NHW_RNG_TOTAL_INST];
|
||||
|
||||
nhw_dppi_common_subscribe_sideeffect(nhw_rng_dppi_map[inst],
|
||||
NRF_RNG_regs.SUBSCRIBE_STOP,
|
||||
&STOP_subscribed[inst],
|
||||
(dppi_callback_t)nhw_rng_task_stop,
|
||||
DPPI_CB_NO_PARAM);
|
||||
}
|
||||
NHW_SIDEEFFECTS_SUBSCRIBE_si(RNG, START)
|
||||
NHW_SIDEEFFECTS_SUBSCRIBE_si(RNG, STOP)
|
||||
#endif /* NHW_HAS_DPPI */
|
||||
|
||||
void nhw_rng_regw_sideeffects_INTENSET(void) {
|
||||
if (NRF_RNG_regs.INTENSET) { /* LCOV_EXCL_BR_LINE */
|
||||
RNG_INTEN |= NRF_RNG_regs.INTENSET;
|
||||
NRF_RNG_regs.INTENSET = RNG_INTEN;
|
||||
nhw_rng_eval_interrupt(0);
|
||||
}
|
||||
}
|
||||
NHW_SIDEEFFECTS_INTSET_si(RNG, NRF_RNG_regs., RNG_INTEN)
|
||||
NHW_SIDEEFFECTS_INTCLR_si(RNG, NRF_RNG_regs., RNG_INTEN)
|
||||
|
||||
void nhw_rng_regw_sideeffects_INTENCLEAR(void) {
|
||||
if (NRF_RNG_regs.INTENCLR) { /* LCOV_EXCL_BR_LINE */
|
||||
RNG_INTEN &= ~NRF_RNG_regs.INTENCLR;
|
||||
NRF_RNG_regs.INTENSET = RNG_INTEN;
|
||||
NRF_RNG_regs.INTENCLR = 0;
|
||||
nhw_rng_eval_interrupt(0);
|
||||
}
|
||||
}
|
||||
NHW_SIDEEFFECTS_EVENTS(RNG)
|
||||
|
||||
void nhw_rng_regw_sideeffects_EVENTS_all(void) {
|
||||
nhw_rng_eval_interrupt(0);
|
||||
}
|
||||
NHW_SIGNAL_EVENT_si(RNG, VALRDY)
|
||||
|
||||
static void nhw_rng_signal_VALRDY(uint periph_inst) {
|
||||
static void nhw_RNG_signal_VALRDY(uint periph_inst) {
|
||||
if (NRF_RNG_regs.SHORTS & RNG_SHORTS_VALRDY_STOP_Msk) {
|
||||
nhw_rng_task_stop();
|
||||
nhw_RNG_TASK_STOP();
|
||||
}
|
||||
|
||||
NRF_RNG_regs.EVENTS_VALRDY = 1;
|
||||
|
||||
nhw_rng_eval_interrupt(periph_inst);
|
||||
|
||||
#if (NHW_HAS_PPI)
|
||||
nrf_ppi_event(RNG_EVENTS_VALRDY);
|
||||
#elif (NHW_HAS_DPPI)
|
||||
nhw_dppi_event_signal_if(nhw_rng_dppi_map[periph_inst],
|
||||
NRF_RNG_regs.PUBLISH_VALRDY);
|
||||
#endif
|
||||
nhw_RNG_signal_EVENTS_VALRDY(periph_inst);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +145,7 @@ static void nhw_rng_timer_triggered(void) {
|
|||
|
||||
nhw_rng_schedule_next(false);
|
||||
|
||||
nhw_rng_signal_VALRDY(0);
|
||||
nhw_RNG_signal_VALRDY(0);
|
||||
}
|
||||
|
||||
NSI_HW_EVENT(Timer_RNG, nhw_rng_timer_triggered, 50);
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
extern "C"{
|
||||
#endif
|
||||
|
||||
void nhw_rng_regw_sideeffects_TASK_START(void);
|
||||
void nhw_rng_regw_sideeffects_TASK_STOP(void);
|
||||
void nhw_rng_regw_sideeffects_INTENSET(void);
|
||||
void nhw_rng_regw_sideeffects_INTENCLEAR(void);
|
||||
void nhw_rng_regw_sideeffects_EVENTS_all(void);
|
||||
void nhw_rng_regw_sideeffects_SUBSCRIBE_START(unsigned int inst);
|
||||
void nhw_rng_regw_sideeffects_SUBSCRIBE_STOP(unsigned int inst);
|
||||
void nhw_rng_task_start(void);
|
||||
void nhw_rng_task_stop(void);
|
||||
void nhw_RNG_regw_sideeffects_TASKS_START(void);
|
||||
void nhw_RNG_regw_sideeffects_TASKS_STOP(void);
|
||||
void nhw_RNG_regw_sideeffects_INTENSET(void);
|
||||
void nhw_RNG_regw_sideeffects_INTENCLR(void);
|
||||
void nhw_RNG_regw_sideeffects_EVENTS_all(unsigned int inst);
|
||||
void nhw_RNG_regw_sideeffects_SUBSCRIBE_START(unsigned int inst);
|
||||
void nhw_RNG_regw_sideeffects_SUBSCRIBE_STOP(unsigned int inst);
|
||||
void nhw_RNG_TASK_START(void);
|
||||
void nhw_RNG_TASK_STOP(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -218,8 +218,8 @@ static const ppi_tasks_table_t ppi_tasks_table[]={ //just the ones we may use
|
|||
//{ (void*)&(NRF_RTC_regs[2]).TASKS_TRIGOVRFLW , nhw_rtc2_TASKS_TRIGOVRFLW},
|
||||
|
||||
//RNG:
|
||||
{ (void*)&NRF_RNG_regs.TASKS_START, nhw_rng_task_start},
|
||||
{ (void*)&NRF_RNG_regs.TASKS_STOP , nhw_rng_task_stop},
|
||||
{ (void*)&NRF_RNG_regs.TASKS_START, nhw_RNG_TASK_START},
|
||||
{ (void*)&NRF_RNG_regs.TASKS_STOP , nhw_RNG_TASK_STOP},
|
||||
|
||||
//ECB
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ void nrf_rng_task_trigger(NRF_RNG_Type * p_reg, nrf_rng_task_t rng_task)
|
|||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)rng_task)) = 0x1UL;
|
||||
|
||||
if ( rng_task == NRF_RNG_TASK_START ) {
|
||||
nhw_rng_regw_sideeffects_TASK_START();
|
||||
nhw_RNG_regw_sideeffects_TASKS_START();
|
||||
} else if ( rng_task == NRF_RNG_TASK_STOP ) {
|
||||
nhw_rng_regw_sideeffects_TASK_STOP();
|
||||
nhw_RNG_regw_sideeffects_TASKS_STOP();
|
||||
} else {
|
||||
bs_trace_error_line_time("Not supported task started in nrf_rng\n");
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ void nrf_rng_task_trigger(NRF_RNG_Type * p_reg, nrf_rng_task_t rng_task)
|
|||
void nrf_rng_int_enable(NRF_RNG_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
NRF_RNG_regs.INTENSET = mask;
|
||||
nhw_rng_regw_sideeffects_INTENSET();
|
||||
nhw_RNG_regw_sideeffects_INTENSET();
|
||||
}
|
||||
|
||||
void nrf_rng_int_disable(NRF_RNG_Type * p_reg, uint32_t mask)
|
||||
{
|
||||
NRF_RNG_regs.INTENCLR = mask;
|
||||
nhw_rng_regw_sideeffects_INTENCLEAR();
|
||||
nhw_RNG_regw_sideeffects_INTENCLR();
|
||||
}
|
||||
|
||||
void nrf_rng_event_clear(NRF_RNG_Type * p_reg, nrf_rng_event_t rng_event)
|
||||
{
|
||||
*((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)rng_event)) = 0x0UL;
|
||||
nhw_rng_regw_sideeffects_EVENTS_all();
|
||||
nhw_RNG_regw_sideeffects_EVENTS_all(0);
|
||||
}
|
||||
|
||||
#if defined(DPPI_PRESENT)
|
||||
|
@ -48,9 +48,9 @@ static void nrf_rng_subscribe_common(NRF_RNG_Type * p_reg,
|
|||
nrf_rng_task_t task)
|
||||
{
|
||||
if (task == NRF_RNG_TASK_START) {
|
||||
nhw_rng_regw_sideeffects_SUBSCRIBE_START(0);
|
||||
nhw_RNG_regw_sideeffects_SUBSCRIBE_START(0);
|
||||
} else if ( task == NRF_RNG_TASK_STOP ) {
|
||||
nhw_rng_regw_sideeffects_SUBSCRIBE_STOP(0);
|
||||
nhw_RNG_regw_sideeffects_SUBSCRIBE_STOP(0);
|
||||
} else {
|
||||
bs_trace_error_line_time("Attempted to subscribe to an not-supported task in the nrf_rng (%i)\n",
|
||||
task);
|
||||
|
|
Loading…
Reference in New Issue