initrandomgenerator.c

来自「SOS操作系统用于无线传感器网络节点的源代码」· C语言 代码 · 共 43 行

C
43
字号
#include "hal.h"
#include <stdbool.h>
#include "sos_inttypes.h"
#ifndef ADCTSTH
// if ADCTSTH not defined in ioCC2430.h, define it
#define  ADCTSTH ((unsigned char volatile __xdata *) 0)[0xDF3A]
#endif

extern bool has_set_main_clock;
void halInitRandomGenerator(void)
{
   uint8_t i;

   //turning on power to analog part of radio
   RFPWR = 0x04;

   //waiting for voltage regulator.
   while((RFPWR & 0x10)){}

   //Turning on 32 MHz crystal oscillator
   if (!has_set_main_clock)
   {
     SET_MAIN_CLOCK_SOURCE(CRYSTAL);
     has_set_main_clock=true;
   }



   // Turning on receiver to get output from IF-ADC.
   ISRXON;
   halWait(1);

   ENABLE_RANDOM_GENERATOR();

   for(i = 0 ; i < 32 ; i++)
   {
      RNDH = ADCTSTH;
      CLOCK_RANDOM_GENERATOR();
   }

   return;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?