RandomNumberGen.c

00001 /***************************************************************************** 00002 * * 00003 * ********** * 00004 * ************ * 00005 * *** *** * 00006 * *** +++ *** * 00007 * *** + + *** * 00008 * *** + CHIPCON CC1010 * 00009 * *** + + *** HAL - RandomNumberGen * 00010 * *** +++ *** * 00011 * *** *** * 00012 * *********** * 00013 * ********* * 00014 * * 00015 ***************************************************************************** 00016 * * 00017 ***************************************************************************** 00018 * Author: ROH * 00019 ***************************************************************************** 00020 * Revision history: * 00021 * * 00022 * $Log: RandomNumberGen.c,v $ 00023 * Revision 1.1 2002/10/14 13:04:33 tos 00024 * Initial version in CVS. 00025 * 00026 * * 00027 ****************************************************************************/ 00028 00029 #include <chipcon/hal.h> 00030 00031 //---------------------------------------------------------------------------- 00032 // halRandomNumberGen(...); 00033 // 00034 // Description: 00035 // This function activates the true RNG in the CC1010, waits long enough 00036 // for the output to be truly random and then samples individual random 00037 // bits with a period which ensures that the output is sufficiently 00038 // random. This function must never be used at the same time as RF is 00039 // in use. 00040 // A total of _length_ bytes of random data is stored at the location 00041 // pointed to by _rnd_data_. 00042 // 00043 // Arguments: 00044 // byte* rnd_data 00045 // A pointer to a buffer to receive the random bytes. 00046 // word length 00047 // The number of random bytes to generate. 00048 // 00049 // Return value: 00050 // void 00051 //---------------------------------------------------------------------------- 00052 void halRandomNumberGen(byte* rnd_data, word length) { 00053 byte b; 00054 int i; 00055 00056 //Torgeir 00057 //RANCON=0x10; // Enable random number generation 00058 RANCON = 0x02; // Enable random number generation 00059 RX_PD=0; // Turn on receive chain 00060 00061 for (i=20; i; i--); // Wait for input to stabilize 00062 00063 while (length--) { 00064 b=0; 00065 for (i=8; i; i--) 00066 b=(b<<1)|(RANCON&0x01); 00067 *rnd_data++=b; 00068 } 00069 00070 RANCON=0; // Disable random number generation 00071 RX_PD=1; // Turn off receive chain 00072 } 00073

Generated on Fri Aug 27 10:04:02 2004 for Cheap Sensor Network by doxygen 1.3.8