void nrf_drv_rng_uninit(void) { ASSERT(m_rng_cb.state == NRF_DRV_STATE_INITIALIZED); m_rng_cb.state = NRF_DRV_STATE_UNINITIALIZED; #ifndef SOFTDEVICE_PRESENT rng_stop(); nrf_drv_common_irq_disable(RNG_IRQn); #endif // SOFTDEVICE_PRESENT }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // uint8_t rng_get_one_byte_and_turn_off() // // Description: // Turns on the RNG, waits for a random number, then turns the RNG back off. You do not have to call rng_configure() prior // to calling this function, as this function does that itself. // // Parameters: // None // // Return value: // A random number // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// uint8_t rng_get_one_byte_and_turn_off() { uint8_t rand_val; rng_configure(RNG_CONFIG_OPTION_RUN | RNG_CONFIG_CORRECTOR_ENABLE); rand_val = rng_get_next_byte(); rng_stop(); return rand_val; }
void RNG_IRQHandler(void) { if (nrf_rng_event_get(NRF_RNG_EVENT_VALRDY) && nrf_rng_int_get(NRF_RNG_INT_VALRDY_MASK)) { nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY); uint32_t nrf_error = app_fifo_put(&m_rng_cb.rand_pool, nrf_rng_random_value_get()); if ((FIFO_LENGTH(m_rng_cb.rand_pool) > m_rng_cb.rand_pool.buf_size_mask) || (nrf_error == NRF_ERROR_NO_MEM)) { rng_stop(); } } }