26.8.2.1.2 Code

Copy-paste the following setup code to your user application:
bool volatile trng_read_done = false;

void configure_trng(void);
void configure_trng_callback(void);
void trng_complete_callback(struct trng_module *const module_inst);

/* TRNG module software instance (must not go out of scope while in use) */
static struct trng_module trng_instance;

void configure_trng(void)
{
    /* Create a new configuration structure for the TRNG settings
     * and fill with the default module settings. */
    struct trng_config config_trng;
    trng_get_config_defaults(&config_trng);

    /* Alter any TRNG configuration settings here if required */

    /* Initialize TRNG with the user settings */
    trng_init(&trng_instance, TRNG, &config_trng);
}

void trng_complete_callback(struct trng_module *const module_inst)
{
    trng_read_done = true;
}

void configure_trng_callback(void)
{
    trng_register_callback(&trng_instance, trng_complete_callback,
            TRNG_CALLBACK_READ_BUFFER);
    trng_enable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER);
}
Add to user application initialization (typically the start of main()):
system_init();
configure_trng();
configure_trng_callback();

trng_enable(&trng_instance);