📄 randomnumbergen.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** HAL - RandomNumberGen *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* *
*****************************************************************************
* Author: ROH *
*****************************************************************************
* Revision history: *
* *
* $Log: RandomNumberGen.c,v $
* Revision 1.1 2002/10/14 13:04:33 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/hal.h>
//----------------------------------------------------------------------------
// halRandomNumberGen(...);
//
// Description:
// This function activates the true RNG in the CC1010, waits long enough
// for the output to be truly random and then samples individual random
// bits with a period which ensures that the output is sufficiently
// random. This function must never be used at the same time as RF is
// in use.
// A total of _length_ bytes of random data is stored at the location
// pointed to by _rnd_data_.
//
// Arguments:
// byte* rnd_data
// A pointer to a buffer to receive the random bytes.
// word length
// The number of random bytes to generate.
//
// Return value:
// void
//----------------------------------------------------------------------------
void halRandomNumberGen(byte* rnd_data, word length) {
byte b;
int i;
//Torgeir
//RANCON=0x10; // Enable random number generation
RANCON = 0x02; // Enable random number generation
RX_PD=0; // Turn on receive chain
for (i=20; i; i--); // Wait for input to stabilize
while (length--) {
b=0;
for (i=8; i; i--)
b=(b<<1)|(RANCON&0x01);
*rnd_data++=b;
}
RANCON=0; // Disable random number generation
RX_PD=1; // Turn off receive chain
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -