50#ifdef SOC_TRNG_CONF_CACHE_LEN
51#define SOC_TRNG_CACHE_LEN SOC_TRNG_CONF_CACHE_LEN
54#define SOC_TRNG_CACHE_LEN 4
57#define MIN_REFILL_CYCLES_MAX 0x00000000
59PROCESS(soc_trng_process,
"CC13xx/CC26xx TRNG process");
63#define soc_trng_isr TRNGIntHandler
69disable_number_ready_interrupt(
void)
71 ti_lib_trng_int_disable(TRNG_NUMBER_READY);
72 ti_lib_int_disable(INT_TRNG_IRQ);
76enable_number_ready_interrupt(
void)
78 ti_lib_trng_int_clear(TRNG_NUMBER_READY);
79 ti_lib_trng_int_enable(TRNG_NUMBER_READY);
80 ti_lib_int_enable(INT_TRNG_IRQ);
87 if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
88 != PRCM_DOMAIN_POWER_ON) {
93 if(!(HWREG(PRCM_BASE + PRCM_O_SECDMACLKGR) &
94 PRCM_SECDMACLKGDS_TRNG_CLK_EN_M)) {
105 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH);
106 while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
107 != PRCM_DOMAIN_POWER_ON));
110 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG);
111 ti_lib_prcm_load_set();
112 while(!ti_lib_prcm_load_get());
116reset_synchronous(
void)
119 while(HWREG(TRNG_BASE + TRNG_O_SWRESET));
126 return LPM_MODE_SLEEP;
128 return LPM_MODE_MAX_SUPPORTED;
131LPM_MODULE(rng_module, request, NULL, NULL, LPM_DOMAIN_NONE);
136 uint64_t ran = (uint64_t)HWREG(TRNG_BASE + TRNG_O_OUT1) << 32;
137 ran += ti_lib_trng_number_get(TRNG_LOW_WORD);
146 bool interrupts_disabled;
153 rands_mask[i] =
false;
154 return rands_cache[i];
169 if((ti_lib_trng_status_get() & (TRNG_NEED_CLOCK | TRNG_NUMBER_READY)) == 0) {
171 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
172 ti_lib_trng_enable();
175 interrupts_disabled = ti_lib_int_master_disable();
177 while((ti_lib_trng_status_get() & TRNG_NUMBER_READY) == 0);
181 if(!interrupts_disabled) {
182 ti_lib_int_master_enable();
192 bool interrupts_disabled;
194 if(notify_cb != NULL) {
210 if((ti_lib_trng_status_get() & (TRNG_NEED_CLOCK | TRNG_NUMBER_READY)) == 0) {
214 interrupts_disabled = ti_lib_int_master_disable();
216 ti_lib_trng_disable();
217 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
218 ti_lib_trng_enable();
222 while((ti_lib_trng_status_get() & TRNG_NUMBER_READY) == 0);
223 rands_mask[i] =
true;
224 rands_cache[i] = read_number();
228 ti_lib_trng_disable();
229 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, samples, 0);
235 ti_lib_trng_int_clear(TRNG_NUMBER_READY);
238 ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG);
239 ti_lib_prcm_load_set();
240 while(!ti_lib_prcm_load_get());
247 enable_number_ready_interrupt();
248 ti_lib_trng_enable();
250 if(!interrupts_disabled) {
251 ti_lib_int_master_enable();
265 uint64_t ran = read_number();
272 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG);
273 ti_lib_prcm_load_set();
274 while(!ti_lib_prcm_load_get());
285 ti_lib_trng_disable();
287 disable_number_ready_interrupt();
289 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
290 ti_lib_trng_enable();
#define LPM_MODULE(n, m, s, w, l)
Declare a variable to be used in order to get notifications from LPM.
void lpm_unregister_module(lpm_registered_module_t *module)
Unregister a module from LPM notifications.
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
void(* soc_trng_callback_t)(uint64_t rand)
Pointer to a callback to be provided as an argument to soc_trng_rand_asynchronous()
#define SOC_TRNG_RAND_ASYNC_REQUEST_OK
Async request accepted.
void soc_trng_init()
Initialise the CC13xx/CC26xx TRNG driver.
#define SOC_TRNG_CACHE_LEN
Size of the random number cache.
uint8_t soc_trng_rand_asynchronous(uint32_t samples, soc_trng_callback_t cb)
Request a 64-bit, configurable-entropy random number.
uint64_t soc_trng_rand_synchronous()
Returns a minimum entropy random number.
#define SOC_TRNG_RAND_ASYNC_REQUEST_ERROR
Async request rejected.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
void process_poll(struct process *p)
Request a process to be polled.
Header file for the Contiki process interface.
Header file for the CC13xx/CC26xx TRNG driver.
Header file with macros which rename TI CC26xxware functions.