00001 /***************************************************************************** 00002 * * 00003 * ********** * 00004 * ************ * 00005 * *** *** * 00006 * *** +++ *** * 00007 * *** + + *** * 00008 * *** + CHIPCON CC1010 * 00009 * *** + + *** HAL - RFReadRSSIlevel * 00010 * *** +++ *** * 00011 * *** *** * 00012 * *********** * 00013 * ********* * 00014 * * 00015 ***************************************************************************** 00016 * Configures/sets up and reads the current CC1010 RSSI level. * 00017 ***************************************************************************** 00018 * Author: TOS * 00019 ***************************************************************************** 00020 * Revision history: * 00021 * * 00022 * $Log: RFReadRSSIlevel.c,v $ 00023 * Revision 1.1 2004/01/08 19:15:32 tos 00024 * Initial version in CVS. 00025 * 00026 * 00027 * * 00028 ****************************************************************************/ 00029 00030 #include <chipcon/hal.h> 00031 #include <chipcon/cc1010eb.h> 00032 00033 00034 //---------------------------------------------------------------------------- 00035 // char halRFReadRSSIlevel(...) 00036 // 00037 // Description: 00038 // This function activates RSSI output on the AD2 pin, activates the ADC 00039 // for channel 2 reads, the RSSI output voltage and converts it to an 00040 // approximation of the incoming signal's strength in dBm (range is appr. 00041 // -110 to -50 dBm.) The value obtained is approximate and most valid for 00042 // a signal @ 600 MHz. The accuracy should be no worse than +/- 10 dBm at 00043 // any frequency. 00044 // An RSSI filter circuit of one capacitor and one resistor is required to 00045 // be connected to the AD2 pin externally (see datasheet for details). 00046 // This function disrupts user ADC operation and does not restore the ADC 00047 // to its former state. This function differs from the "old" function in 00048 // the sense that it can operate in two modes, RSSI_INIT and RSSI_RUN. 00049 // The ADC is not powered down after each read in order to save execution 00050 // time. The function can be used as a carrier sense if the returned value 00051 // is compared to some relatively low threshold. 00052 // Arguments: 00053 // byte mode 00054 // Selects function mode, RSSI_INIT or RSSI_RUN. 00055 // Return value: 00056 // char 00057 // The converted AD2 value = RSSI value 00058 // 00059 //---------------------------------------------------------------------------- 00060 signed char halRFReadRSSIlevel(byte rssi_mode) { 00061 byte val = 0; 00062 00063 // If RSSI mode = run/continuous 00064 if(rssi_mode == RSSI_MODE_RUN){ 00065 // Configure ADC for RSSI reading 00066 halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_INTERNAL_1_25, CC1010EB_CLKFREQ, 0); 00067 00068 // Turn on ADC 00069 ADC_POWER(TRUE); 00070 00071 // Wait until ADC stabilized 00072 halWait(1, CC1010EB_CLKFREQ); 00073 00074 // Select RSSI input and read sample 00075 ADC_SELECT_INPUT(ADC_INPUT_AD2); 00076 ADC_SAMPLE_SINGLE(); 00077 val=ADC_GET_SAMPLE_8BIT(); // Get 8 MSB of sample 00078 00079 // Convert value into dBm 00080 val = -50-((val*55)>>8); 00081 // Else (RSSI mode = initialisation) 00082 } else { 00083 // Activate RSSI output 00084 FREND|=0x02; 00085 00086 // Configure ADC for RSSI reading 00087 halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_INTERNAL_1_25, CC1010EB_CLKFREQ, 0); 00088 00089 // Turn on ADC 00090 ADC_POWER(TRUE); 00091 00092 // Wait until ADC stabilized 00093 halWait(200, CC1010EB_CLKFREQ); 00094 } 00095 00096 return val; 00097 }