drivers: entropy: Introduce ISR-specific entropy function
In order to address the requirements of the kernel boot process, an optional ISR-specific function is declared to allow entropy collection outside of thread mode and without using any kernel primitives. It also includes a parameter to optionally busy-wait for hardware entropy generation. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
29599f6d80
commit
668e31f7db
@ -36,13 +36,24 @@ extern "C" {
|
||||
typedef int (*entropy_get_entropy_t)(struct device *dev,
|
||||
u8_t *buffer,
|
||||
u16_t length);
|
||||
|
||||
/**
|
||||
* @typedef entropy_get_entropy_isr_t
|
||||
* @brief Callback API to get entropy from an ISR.
|
||||
*
|
||||
* See entropy_get_entropy_isr() for argument description
|
||||
*/
|
||||
typedef int (*entropy_get_entropy_isr_t)(struct device *dev,
|
||||
u8_t *buffer,
|
||||
u16_t length,
|
||||
u32_t flags);
|
||||
struct entropy_driver_api {
|
||||
entropy_get_entropy_t get_entropy;
|
||||
entropy_get_entropy_t get_entropy;
|
||||
entropy_get_entropy_isr_t get_entropy_isr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Fills a buffer with entropy.
|
||||
* @brief Fills a buffer with entropy. Blocks if required in order to
|
||||
* generate the necessary random data.
|
||||
*
|
||||
* @param dev Pointer to the entropy device.
|
||||
* @param buffer Buffer to fill with entropy.
|
||||
@ -64,6 +75,33 @@ static inline int _impl_entropy_get_entropy(struct device *dev,
|
||||
return api->get_entropy(dev, buffer, length);
|
||||
}
|
||||
|
||||
/* Busy-wait for random data to be ready */
|
||||
#define ENTROPY_BUSYWAIT BIT(0)
|
||||
|
||||
/**
|
||||
* @brief Fills a buffer with entropy in a non-blocking or busy-wait manner.
|
||||
* Callable from ISRs.
|
||||
*
|
||||
* @param dev Pointer to the device structure.
|
||||
* @param buffer Buffer to fill with entropy.
|
||||
* @param length Buffer length.
|
||||
* @param flags Flags to modify the behavior of the call.
|
||||
* @retval number of bytes filled with entropy or -error.
|
||||
*/
|
||||
static inline int entropy_get_entropy_isr(struct device *dev,
|
||||
u8_t *buffer,
|
||||
u16_t length,
|
||||
u32_t flags)
|
||||
{
|
||||
const struct entropy_driver_api *api = dev->driver_api;
|
||||
|
||||
if (!api->get_entropy_isr) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
return api->get_entropy_isr(dev, buffer, length, flags);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user