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 = ;
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[]; randombytes(rng_result,sizeof(rng_result)); #ifdef RTT_LOG_ENABLED loge("rng_result[8] %x %x %x %x %x %x %x %x",rng_result[],\
rng_result[],\
rng_result[],\
rng_result[],\
rng_result[],\
rng_result[],\
rng_result[],\
rng_result[] ); #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

上一篇:android技术牛人的博客[转]


下一篇:Springboot 中配置文件的优先级和加载顺序