Workflow

  1. 1.
    Create a TRNG device instance struct, which will be associated with a TRNG peripheral hardware instance.
    static struct trng_module trng_instance;
    
    Note: Device instance structures shall never go out of scope when in use.
  2. 2.
    Create a new function configure_trng(), which will be used to configure the overall TRNG peripheral.
    void configure_trng(void)
    
  3. 3.
    Create a TRNG peripheral configuration structure that will be filled out to set the module configuration.
    struct trng_config config_trng;
    
  4. 4.
    Fill the TRNG peripheral configuration structure with the default module configuration values.
    trng_get_config_defaults(&config_trng);
    
  5. 5.
    Initialize the TRNG peripheral and associate it with the software instance structure that was defined previously.
    trng_init(&trng_instance, TRNG, &config_trng);
    
  6. 6.
    Create a new callback function.
    void trng_complete_callback(struct trng_module *const module_inst)
    {
        trng_read_done = true;
    }
    
  7. 7.
    Create a callback status software flag.
    bool volatile trng_read_done = false;
    
  8. 8.
    Let the callback function set the flag to true when read job done.
    trng_read_done = true;
    
  9. 9.
    Create a new function configure_trng_callback(), which will be used to configure the callbacks.
    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);
    }
    
  10. 10.
    Register callback function.
    trng_register_callback(&trng_instance, trng_complete_callback,
            TRNG_CALLBACK_READ_BUFFER);
    
  11. 11.
    Enable the callbacks.
    trng_enable_callback(&trng_instance, TRNG_CALLBACK_READ_BUFFER);
    
  12. 12.
    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.