zoukankan      html  css  js  c++  java
  • NRF51822之RNG

    在裸机下官方已经提供另一个RNG的例子(RF51_SDK_10.0.0_dc26b5eexamplesperipheral ng)

    好了现在我将给出在蓝牙模式下如何使用例子

    #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); 
    
    }

  • 相关阅读:
    高效沟通
    Oracle播放多条 INSERT ALL
    oracle的同义词总结
    Brute force Attack
    爱因斯坦方程与小黑洞
    dom 编程(html和xml)
    dexposed框架Android在线热修复
    从微软小冰看微软运营手段的转型
    剑指offer_面试题_从上往下打印二叉树
    外面的wifi非常精彩,外面的wifi非常不安
  • 原文地址:https://www.cnblogs.com/libra13179/p/7699581.html
Copyright © 2011-2022 走看看