26.8.2.1.3 Workflow
- Create a TRNG device instance struct, which will be associated with a TRNG peripheral hardware instance.
staticstructtrng_module trng_instance;Note: Device instance structures shall never go out of scope when in use. - Create a new function configure_trng(), which will be used to configure the overall TRNG peripheral.
voidconfigure_trng(void) - Create a TRNG peripheral configuration structure that will be filled out to set the module configuration.
structtrng_config config_trng; - Fill the TRNG peripheral configuration structure with the default module configuration values.
trng_get_config_defaults(&config_trng); - Initialize the TRNG peripheral and associate it with the software instance structure that was defined previously.
trng_init(&trng_instance, TRNG, &config_trng); - Create a new callback function.
voidtrng_complete_callback(structtrng_module *constmodule_inst){trng_read_done =true;} - Create a callback status software flag.
boolvolatiletrng_read_done =false; - Let the callback function set the flag to true when read job done.
trng_read_done =true; - Create a new function configure_trng_callback(), which will be used to configure the callbacks.
voidconfigure_trng_callback(void){trng_register_callback(&trng_instance, trng_complete_callback,TRNG_CALLBACK_READ_BUFFER);trng_enable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER);} - Register callback function.
trng_register_callback(&trng_instance, trng_complete_callback,TRNG_CALLBACK_READ_BUFFER); - Enable the callbacks.
trng_enable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER); - Enable the now initialized TRNG peripheral.
trng_enable(&trng_instance);Note: This should not be done until after the TRNG is set up and ready to be used.
