drivers: entropy_nrf5: Use device name and IRQ priority from DTS
Instead of using Kconfig options for setting the device name and IRQ priority for the entropy_nrf5 driver, get these settings from the rng node defined in DTS for a given SoC. Provide also fixups for CONFIG_ENTROPY_NAME, until applications using entropy drivers are converted to use DTS as well. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
parent
20125076f6
commit
97e4c0cbad
6 changed files with 33 additions and 17 deletions
8
boards/posix/nrf52_bsim/dts_fixup.h
Normal file
8
boards/posix/nrf52_bsim/dts_fixup.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
/* Copyright (c) 2020 Nordic Semiconductor ASA */
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
/* Board level DTS fixup file */
|
||||
|
||||
#ifndef CONFIG_ENTROPY_NAME
|
||||
#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, nordic_nrf_rng))
|
||||
#endif
|
|
@ -16,6 +16,7 @@ menuconfig ENTROPY_NRF5_RNG
|
|||
depends on !ENTROPY_NRF_FORCE_ALT
|
||||
depends on HAS_HW_NRF_RNG
|
||||
select ENTROPY_HAS_DRIVER
|
||||
select HAS_DTS_ENTROPY
|
||||
default y
|
||||
help
|
||||
This option enables the RNG peripheral, which is a random number
|
||||
|
@ -67,13 +68,4 @@ config ENTROPY_NRF5_ISR_THRESHOLD
|
|||
buffer goes below this number hardware entropy generation will be
|
||||
started.
|
||||
|
||||
config ENTROPY_NRF5_PRI
|
||||
int "RNG interrupt priority"
|
||||
range 0 2 if SOC_SERIES_NRF51X
|
||||
range 0 5 if SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X
|
||||
default 2 if SOC_SERIES_NRF51X
|
||||
default 5 if SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X
|
||||
help
|
||||
nRF5X RNG IRQ priority.
|
||||
|
||||
endif # ENTROPY_NRF5_RNG
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
#include <soc.h>
|
||||
#include <hal/nrf_rng.h>
|
||||
|
||||
#define DT_DRV_COMPAT nordic_nrf_rng
|
||||
|
||||
#define IRQN DT_INST_IRQN(0)
|
||||
#define IRQ_PRIO DT_INST_IRQ(0, priority)
|
||||
|
||||
/*
|
||||
* The nRF5 RNG HW has several characteristics that need to be taken
|
||||
* into account by the driver to achieve energy efficient generation
|
||||
|
@ -266,8 +271,8 @@ static int entropy_nrf5_get_entropy_isr(struct device *dev, u8_t *buf, u16_t len
|
|||
int irq_enabled;
|
||||
|
||||
key = irq_lock();
|
||||
irq_enabled = irq_is_enabled(RNG_IRQn);
|
||||
irq_disable(RNG_IRQn);
|
||||
irq_enabled = irq_is_enabled(IRQN);
|
||||
irq_disable(IRQN);
|
||||
irq_unlock(key);
|
||||
|
||||
nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
|
||||
|
@ -284,7 +289,7 @@ static int entropy_nrf5_get_entropy_isr(struct device *dev, u8_t *buf, u16_t len
|
|||
}
|
||||
|
||||
byte = random_byte_get();
|
||||
NVIC_ClearPendingIRQ(RNG_IRQn);
|
||||
NVIC_ClearPendingIRQ(IRQN);
|
||||
|
||||
if (byte < 0) {
|
||||
continue;
|
||||
|
@ -294,7 +299,7 @@ static int entropy_nrf5_get_entropy_isr(struct device *dev, u8_t *buf, u16_t len
|
|||
} while (len);
|
||||
|
||||
if (irq_enabled) {
|
||||
irq_enable(RNG_IRQn);
|
||||
irq_enable(IRQN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,7 +313,7 @@ static const struct entropy_driver_api entropy_nrf5_api_funcs = {
|
|||
.get_entropy_isr = entropy_nrf5_get_entropy_isr
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(entropy_nrf5, CONFIG_ENTROPY_NAME,
|
||||
DEVICE_AND_API_INIT(entropy_nrf5, DT_INST_LABEL(0),
|
||||
entropy_nrf5_init, &entropy_nrf5_data, NULL,
|
||||
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
&entropy_nrf5_api_funcs);
|
||||
|
@ -342,9 +347,8 @@ static int entropy_nrf5_init(struct device *device)
|
|||
nrf_rng_int_enable(NRF_RNG, NRF_RNG_INT_VALRDY_MASK);
|
||||
nrf_rng_task_trigger(NRF_RNG, NRF_RNG_TASK_START);
|
||||
|
||||
IRQ_CONNECT(RNG_IRQn, CONFIG_ENTROPY_NRF5_PRI, isr,
|
||||
&entropy_nrf5_data, 0);
|
||||
irq_enable(RNG_IRQn);
|
||||
IRQ_CONNECT(IRQN, IRQ_PRIO, isr, &entropy_nrf5_data, 0);
|
||||
irq_enable(IRQN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
/* SoC level DTS fixup file */
|
||||
|
||||
#ifndef CONFIG_ENTROPY_NAME
|
||||
#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, nordic_nrf_rng))
|
||||
#endif
|
||||
|
||||
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V6M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
|
||||
|
||||
#define DT_ADC_0_NAME DT_NORDIC_NRF_ADC_ADC_0_LABEL
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
/* SoC level DTS fixup file */
|
||||
|
||||
#ifndef CONFIG_ENTROPY_NAME
|
||||
#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, nordic_nrf_rng))
|
||||
#endif
|
||||
|
||||
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V7M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
|
||||
|
||||
#define DT_ADC_0_NAME DT_NORDIC_NRF_SAADC_ADC_0_LABEL
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
/* SoC level DTS fixup file */
|
||||
|
||||
#ifndef CONFIG_ENTROPY_NAME
|
||||
#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, nordic_nrf_rng))
|
||||
#endif
|
||||
|
||||
#define DT_NUM_IRQ_PRIO_BITS \
|
||||
DT_ARM_V8M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue