Driver API for TRNG (plib_trng.h)
More...
|
| typedef void(* | TRNG_CALLBACK) (uint32_t random_value) |
| | Function pointer type for the TRNG Data Ready callback.
|
| |
Driver API for TRNG (plib_trng.h)
Usage Example
The following example demonstrates typical usage of the TRNG peripheral:
#include <stdint.h>
#include <stdbool.h>
volatile bool trng_data_ready = false;
volatile uint32_t trng_last_value = 0U;
void TRNG_DataReadyCallback(uint32_t random_value)
{
trng_last_value = random_value;
trng_data_ready = true;
}
int32_t configure_trng(void)
{
return 0;
}
void TRNG_SetCallbackHandler(TRNG_CALLBACK callback)
Registers the callback invoked from TRNG_Handler() on Data Ready.
void TRNG_DisableInterrupt(void)
Disables the TRNG Data Ready interrupt.
void TRNG_Enable(void)
Enables the TRNG peripheral.
void TRNG_Disable(void)
Disables the TRNG peripheral.
void TRNG_EnableInterrupt(void)
Enables the TRNG Data Ready interrupt.
◆ TRNG_CALLBACK
| typedef void(* TRNG_CALLBACK) (uint32_t random_value) |
Function pointer type for the TRNG Data Ready callback.
- Parameters
-
| random_value | The 32-bit random value read from TRNG_ODATA. |
◆ TRNG_DataIsReady()
| bool TRNG_DataIsReady |
( |
void | | ) |
|
Checks whether a new random value is available.
- Returns
- true if a random value is ready to be read, false otherwise.
- Note
- TRNG_ISR.DATRDY is cleared by hardware on read. TRNG_DataIsReady() and TRNG_GetRandomNumber() share an internal latch so a pending value is never lost between them.
◆ TRNG_Disable()
| void TRNG_Disable |
( |
void | | ) |
|
Disables the TRNG peripheral.
- Returns
- None.
◆ TRNG_DisableInterrupt()
| void TRNG_DisableInterrupt |
( |
void | | ) |
|
Disables the TRNG Data Ready interrupt.
- Returns
- None.
◆ TRNG_Enable()
| void TRNG_Enable |
( |
void | | ) |
|
Enables the TRNG peripheral.
- Returns
- None.
- Note
- Wait for the TRNG Warm-Up Time (TRNGWUP), per the AC electrical timings, before reading random data.
◆ TRNG_EnableInterrupt()
| void TRNG_EnableInterrupt |
( |
void | | ) |
|
Enables the TRNG Data Ready interrupt.
- Returns
- None.
- Note
- Fires every 84 clock cycles until disabled; TRNG_Handler() does not disable it automatically. Register a callback first, or each word is discarded. Do not call TRNG_GetRandomNumber() while enabled; both read TRNG_ISR destructively.
◆ TRNG_GetRandomNumber()
| bool TRNG_GetRandomNumber |
( |
uint32_t * | data | ) |
|
Reads a random 32-bit value from the TRNG peripheral.
- Parameters
-
| [out] | data | Pointer to store the random value. |
- Returns
- true if a value was read into *data, false if data is NULL or no value was ready.
◆ TRNG_InterruptIsEnabled()
| bool TRNG_InterruptIsEnabled |
( |
void | | ) |
|
Checks whether the Data Ready interrupt is enabled.
- Returns
- true if TRNG_IMR.DATRDY is set, false otherwise.
◆ TRNG_SetCallbackHandler()
Registers the callback invoked from TRNG_Handler() on Data Ready.
- Parameters
-
| callback | Pointer to the callback function (NULL to clear). |
- Returns
- None.