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 59 PROCESS(soc_trng_process,
"CC13xx/CC26xx TRNG process");
61 static process_event_t rng_ready_event = PROCESS_EVENT_NONE;
65 #define soc_trng_isr TRNGIntHandler 71 disable_number_ready_interrupt(
void)
73 ti_lib_trng_int_disable(TRNG_NUMBER_READY);
74 ti_lib_int_disable(INT_TRNG_IRQ);
78 enable_number_ready_interrupt(
void)
80 ti_lib_trng_int_clear(TRNG_NUMBER_READY);
81 ti_lib_trng_int_enable(TRNG_NUMBER_READY);
82 ti_lib_int_enable(INT_TRNG_IRQ);
89 if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
90 != PRCM_DOMAIN_POWER_ON) {
95 if(!(HWREG(PRCM_BASE + PRCM_O_SECDMACLKGR) &
96 PRCM_SECDMACLKGDS_TRNG_CLK_EN_M)) {
107 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH);
108 while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
109 != PRCM_DOMAIN_POWER_ON));
112 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG);
113 ti_lib_prcm_load_set();
114 while(!ti_lib_prcm_load_get());
118 reset_synchronous(
void)
121 while(HWREG(TRNG_BASE + TRNG_O_SWRESET));
128 return LPM_MODE_SLEEP;
130 return LPM_MODE_MAX_SUPPORTED;
133 LPM_MODULE(rng_module, request, NULL, NULL, LPM_DOMAIN_NONE);
138 uint64_t ran = (uint64_t)HWREG(TRNG_BASE + TRNG_O_OUT1) << 32;
139 ran += ti_lib_trng_number_get(TRNG_LOW_WORD);
148 bool interrupts_disabled;
155 rands_mask[i] =
false;
156 return rands_cache[i];
171 if((ti_lib_trng_status_get() & (TRNG_NEED_CLOCK | TRNG_NUMBER_READY)) == 0) {
173 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
174 ti_lib_trng_enable();
177 interrupts_disabled = ti_lib_int_master_disable();
179 while((ti_lib_trng_status_get() & TRNG_NUMBER_READY) == 0);
183 if(!interrupts_disabled) {
184 ti_lib_int_master_enable();
194 bool interrupts_disabled;
196 if(notify_cb != NULL) {
212 if((ti_lib_trng_status_get() & (TRNG_NEED_CLOCK | TRNG_NUMBER_READY)) == 0) {
216 interrupts_disabled = ti_lib_int_master_disable();
218 ti_lib_trng_disable();
219 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
220 ti_lib_trng_enable();
224 while((ti_lib_trng_status_get() & TRNG_NUMBER_READY) == 0);
225 rands_mask[i] =
true;
226 rands_cache[i] = read_number();
230 ti_lib_trng_disable();
231 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, samples, 0);
237 ti_lib_trng_int_clear(TRNG_NUMBER_READY);
240 ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG);
241 ti_lib_prcm_load_set();
242 while(!ti_lib_prcm_load_get());
249 enable_number_ready_interrupt();
250 ti_lib_trng_enable();
252 if(!interrupts_disabled) {
253 ti_lib_int_master_enable();
267 uint64_t ran = read_number();
274 ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG);
275 ti_lib_prcm_load_set();
276 while(!ti_lib_prcm_load_get());
287 ti_lib_trng_disable();
289 disable_number_ready_interrupt();
291 ti_lib_trng_configure(MIN_REFILL_CYCLES_MAX, SOC_TRNG_REFILL_CYCLES_MIN, 0);
292 ti_lib_trng_enable();
300 if(rng_ready_event != PROCESS_EVENT_NONE) {
#define PROCESS(name, strname)
Declare a process.
void soc_trng_init()
Initialise the CC13xx/CC26xx TRNG driver.
Header file with macros which rename TI CC26xxware functions.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
Header file for the CC13xx/CC26xx TRNG driver.
Header file for the Contiki process interface.
process_event_t process_alloc_event(void)
Allocate a global event number.
#define SOC_TRNG_RAND_ASYNC_REQUEST_ERROR
Async request rejected.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
uint64_t soc_trng_rand_synchronous()
Returns a minimum entropy random number.
#define LPM_MODULE(n, m, s, w, l)
Declare a variable to be used in order to get notifications from LPM.
#define SOC_TRNG_CACHE_LEN
Size of the random number cache.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
uint8_t soc_trng_rand_asynchronous(uint32_t samples, soc_trng_callback_t cb)
Request a 64-bit, configurable-entropy random number.
#define SOC_TRNG_RAND_ASYNC_REQUEST_OK
Async request accepted.
void lpm_unregister_module(lpm_registered_module_t *module)
Unregister a module from 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() ...
void process_start(struct process *p, process_data_t data)
Start a process.
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.