NRF51822之RNG
Posted 陌鉎こ城sHi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NRF51822之RNG相关的知识,希望对你有一定的参考价值。
在裸机下官方已经提供另一个RNG的例子(RF51_SDK_10.0.0_dc26b5e\\examples\\peripheral\\rng)
好了现在我将给出在蓝牙模式下如何使用例子
#include "random.h" void random_create(uint8_t* p_result, uint8_t length) { uint32_t err_code; while (length) { uint8_t available = 0; err_code = sd_rand_application_bytes_available_get(&available); APP_ERROR_CHECK(err_code); if (available) { available = available < length ? available : length; err_code = sd_rand_application_vector_get(p_result, available); APP_ERROR_CHECK(err_code); p_result += available; length -= available; } } } void randombytes(uint8_t* p_result, uint64_t length) { random_create(p_result, (uint8_t)length); }
/* * random.h * * Created on: Oct 20, 2017 * Author: libra */ #ifndef HOMEKIT_RANDOM_H_ #define HOMEKIT_RANDOM_H_ #include <stdint.h> #include "nrf_soc.h" #include "app_error.h" extern void random_create(uint8_t* p_result, uint8_t length); extern void randombytes(uint8_t* p_result, uint64_t length); #endif /* HOMEKIT_RANDOM_H_ */
好了现在我们在ble_app_template基础上进行修改(下面给出主要的测试部分带)
APP_TIMER_DEF(m_app_timer_id); #define TIMER_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) static void timer_timeout_handler(void * p_context) { uint8_t rng_result[8]; randombytes(rng_result,sizeof(rng_result)); #ifdef RTT_LOG_ENABLED loge("rng_result[8] %x %x %x %x %x %x %x %x",rng_result[0],\\ rng_result[1],\\ rng_result[2],\\ rng_result[3],\\ rng_result[4],\\ rng_result[5],\\ rng_result[6],\\ rng_result[7] ); #endif //RTT_LOG_ENABLED } /**@brief Function for the Timer initialization. * * @details Initializes the timer module. This creates and starts application timers. */ static void timers_init(void) { // Initialize timer module. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false); // Create timers. /* YOUR_JOB: Create any timers to be used by the application. Below is an example of how to create a timer. For every new timer needed, increase the value of the macro APP_TIMER_MAX_TIMERS by one.*/ uint32_t err_code; err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler); APP_ERROR_CHECK(err_code); } static void application_timers_start(void) { /* YOUR_JOB: Start your timers. below is an example of how to start a timer.*/ uint32_t err_code; err_code = app_timer_start(m_app_timer_id, TIMER_INTERVAL, NULL); APP_ERROR_CHECK(err_code); }
以上是关于NRF51822之RNG的主要内容,如果未能解决你的问题,请参考以下文章
相比于nrf51822蓝牙模块,nrf52832蓝牙模块性能怎么样?
[nRF51822] 6基于nRF51822平台的flash读写研究
nRF51822 配对之device_manager_init 调用,以及保证 用户数据存储 的Flash 操作不与device manager 模块冲突