00001
00005
00006 #ifndef RFCC_H
00007 #define RFCC_H
00008
00009 #include <stdint.h>
00010 #include <avr/io.h>
00011 #include <util/delay.h>
00012
00013 #include "settings.h"
00014
00015 #include "spi.h"
00016
00018
00019 #define RFCC_IOCFG2 0x00 // GDO2 output pin configuration
00020 #define RFCC_IOCFG1 0x01 // GDO1 output pin configuration
00021 #define RFCC_IOCFG0 0x02 // GDO0 output pin configuration
00022 #define RFCC_FIFOTHR 0x03 // RX FIFO and TX FIFO thresholds
00023 #define RFCC_SYNC1 0x04 // Sync word, high byte
00024 #define RFCC_SYNC0 0x05 // Sync word, low byte
00025 #define RFCC_PKTLEN 0x06 // Packet length
00026 #define RFCC_PKTCTRL1 0x07 // Packet automation control
00027 #define RFCC_PKTCTRL0 0x08 // Packet automation control
00028 #define RFCC_ADDR 0x09 // Device address
00029 #define RFCC_CHANNR 0x0A // Channel number
00030 #define RFCC_FSCTRL1 0x0B // Frequency synthesizer control
00031 #define RFCC_FSCTRL0 0x0C // Frequency synthesizer control
00032 #define RFCC_FREQ2 0x0D // Frequency control word, high byte
00033 #define RFCC_FREQ1 0x0E // Frequency control word, middle byte
00034 #define RFCC_FREQ0 0x0F // Frequency control word, low byte
00035 #define RFCC_MDMCFG4 0x10 // Modem configuration
00036 #define RFCC_MDMCFG3 0x11 // Modem configuration
00037 #define RFCC_MDMCFG2 0x12 // Modem configuration
00038 #define RFCC_MDMCFG1 0x13 // Modem configuration
00039 #define RFCC_MDMCFG0 0x14 // Modem configuration
00040 #define RFCC_DEVIATN 0x15 // Modem deviation setting
00041 #define RFCC_MCSM2 0x16 // Main Radio Cntrl State Machine config
00042 #define RFCC_MCSM1 0x17 // Main Radio Cntrl State Machine config
00043 #define RFCC_MCSM0 0x18 // Main Radio Cntrl State Machine config
00044 #define RFCC_FOCCFG 0x19 // Frequency Offset Compensation config
00045 #define RFCC_BSCFG 0x1A // Bit Synchronization configuration
00046 #define RFCC_AGCCTRL2 0x1B // AGC control
00047 #define RFCC_AGCCTRL1 0x1C // AGC control
00048 #define RFCC_AGCCTRL0 0x1D // AGC control
00049 #define RFCC_WOREVT1 0x1E // High byte Event 0 timeout
00050 #define RFCC_WOREVT0 0x1F // Low byte Event 0 timeout
00051 #define RFCC_WORCTRL 0x20 // Wake On Radio control
00052 #define RFCC_FREND1 0x21 // Front end RX configuration
00053 #define RFCC_FREND0 0x22 // Front end TX configuration
00054 #define RFCC_FSCAL3 0x23 // Frequency synthesizer calibration
00055 #define RFCC_FSCAL2 0x24 // Frequency synthesizer calibration
00056 #define RFCC_FSCAL1 0x25 // Frequency synthesizer calibration
00057 #define RFCC_FSCAL0 0x26 // Frequency synthesizer calibration
00058 #define RFCC_RCCTRL1 0x27 // RC oscillator configuration
00059 #define RFCC_RCCTRL0 0x28 // RC oscillator configuration
00060 #define RFCC_FSTEST 0x29 // Frequency synthesizer cal control
00061 #define RFCC_PTEST 0x2A // Production test
00062 #define RFCC_AGCTEST 0x2B // AGC test
00063 #define RFCC_TEST2 0x2C // Various test settings
00064 #define RFCC_TEST1 0x2D // Various test settings
00065 #define RFCC_TEST0 0x2E // Various test settings
00066
00067
00069
00070 #define RFCC_SRES 0x30 // Reset chip.
00071 #define RFCC_SFSTXON 0x31 // Enable/calibrate freq synthesizer
00072 #define RFCC_SXOFF 0x32 // Turn off crystal oscillator.
00073 #define RFCC_SCAL 0x33 // Calibrate freq synthesizer & disable
00074 #define RFCC_SRX 0x34 // Enable RX.
00075 #define RFCC_STX 0x35 // Enable TX.
00076 #define RFCC_SIDLE 0x36 // Exit RX / TX
00077 #define RFCC_SAFC 0x37 // AFC adjustment of freq synthesizer
00078 #define RFCC_SWOR 0x38 // Start automatic RX polling sequence
00079 #define RFCC_SPWD 0x39 // Enter pwr down mode when CSn goes hi
00080 #define RFCC_SFRX 0x3A // Flush the RX FIFO buffer.
00081 #define RFCC_SFTX 0x3B // Flush the TX FIFO buffer.
00082 #define RFCC_SWORRST 0x3C // Reset real time clock.
00083 #define RFCC_SNOP 0x3D // No operation.
00084
00085
00087
00088 #define RFCC_PARTNUM 0x30 // Part number
00089 #define RFCC_VERSION 0x31 // Current version number
00090 #define RFCC_FREQEST 0x32 // Frequency offset estimate
00091 #define RFCC_LQI 0x33 // Demodulator estimate for link quality
00092 #define RFCC_RSSI 0x34 // Received signal strength indication
00093 #define RFCC_MARCSTATE 0x35 // Control state machine state
00094 #define RFCC_WORTIME1 0x36 // High byte of WOR timer
00095 #define RFCC_WORTIME0 0x37 // Low byte of WOR timer
00096 #define RFCC_PKTSTATUS 0x38 // Current GDOx status and packet status
00097 #define RFCC_VCO_VC_DAC 0x39 // Current setting from PLL cal module
00098 #define RFCC_TXBYTES 0x3A // Underflow and # of bytes in TXFIFO
00099 #define RFCC_RXBYTES 0x3B // Overflow and # of bytes in RXFIFO
00100 #define RFCC_NUM_RXBYTES 0x7F // Mask "# of bytes" field in _RXBYTES
00101
00102
00104
00105 #define RFCC_PATABLE 0x3E
00106 #define RFCC_TXFIFO 0x3F
00107 #define RFCC_RXFIFO 0x3F
00108
00109
00111
00112 #define RFCC_LQI_RX 0x01 // Position of LQI byte
00113 #define RFCC_CRC_OK 0x80 // Mask "CRC_OK" bit within LQI byte
00114
00115
00117
00118 #define RFCC_WRITE_BURST 0x40
00119 #define RFCC_READ_SINGLE 0x80
00120 #define RFCC_READ_BURST 0xC0
00121
00122
00123
00124
00125
00126
00127
00128 namespace rfcc
00129 {
00130 typedef struct settings_s
00131 {
00132 char FSCTRL0;
00133 char FREQ2;
00134 char FREQ1;
00135 char FREQ0;
00136 char MDMCFG4;
00137 char MDMCFG3;
00138 char MDMCFG2;
00139 char MDMCFG1;
00140 char MDMCFG0;
00141 char CHANNR;
00142 char DEVIATN;
00143 char FREND1;
00144 char FREND0;
00145 char MCSM2;
00146 char MCSM1;
00147 char MCSM0;
00148 char FOCCFG;
00149 char BSCFG;
00150 char AGCCTRL2;
00151 char AGCCTRL1;
00152 char AGCCTRL0;
00153 char FSCAL3;
00154 char FSCAL2;
00155 char FSCAL1;
00156 char FSCAL0;
00157 char FSTEST;
00158 char TEST2;
00159 char TEST1;
00160 char TEST0;
00161 char IOCFG2;
00162 char IOCFG0;
00163 char PKTCTRL1;
00164 char PKTCTRL0;
00165 char ADDR;
00166 char PKTLEN;
00167 char FIFOTHR;
00168 } settings_t;
00169
00170
00171 char paTable[] = {0xff};
00172 char paTableLen = 1;
00173 char LQI, RSSI;
00174
00179 void init(settings_t *settings);
00180
00181 void powerupReset();
00182
00193 void sendPacket(char *txBuffer, char size);
00194
00213 char receivePacket(char *rxBuffer, char *length);
00214
00215 namespace rfspi
00216 {
00221 void init();
00222
00228 void writeReg(char addr, char value);
00229
00239 void writeBurstReg(char addr, char *buffer, char count);
00240
00247 char readReg(char addr);
00248
00257 void readBurstReg(char addr, char *buffer, char count);
00258
00265 char readStatus(char addr);
00266
00272 void strobe(char strobe_);
00273 };
00274 };
00275
00276 #endif // RF_CC_H