NewAskSin
 All Classes Files Functions Variables Groups Pages
CC1101.h
1 //- -----------------------------------------------------------------------------------------------------------------------
2 // AskSin driver implementation
3 // 2013-08-03 <trilu@gmx.de> Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
4 //- -----------------------------------------------------------------------------------------------------------------------
5 //- AskSin cc1101 functions -----------------------------------------------------------------------------------------------
6 //- with a lot of copy and paste from culfw firmware
7 //- -----------------------------------------------------------------------------------------------------------------------
8 
9 #ifndef _CC_H
10 #define _CC_H
11 
12 #include "HAL.h"
13 #include <util/delay.h>
14 
15 class CC {
16  friend class AS;
17  friend class SN;
18  friend class PW;
19 
20  public: //---------------------------------------------------------------------------------------------------------
21  protected: //---------------------------------------------------------------------------------------------------------
22  private: //---------------------------------------------------------------------------------------------------------
23 
24  #define CC1101_DATA_LEN 60 // maximum length of received bytes
25  uint8_t crc_ok; // CRC OK for received message
26  uint8_t rssi; // signal strength
27  uint8_t lqi; // link quality
28 
29  // CC1101 config register // Reset Description
30  #define CC1101_IOCFG2 0x00 // (0x29) GDO2 Output Pin Configuration
31  #define CC1101_IOCFG1 0x01 // (0x2E) GDO1 Output Pin Configuration
32  #define CC1101_IOCFG0 0x02 // (0x3F) GDO0 Output Pin Configuration
33  #define CC1101_FIFOTHR 0x03 // (0x07) RX FIFO and TX FIFO Thresholds
34  #define CC1101_SYNC1 0x04 // (0xD3) Sync Word, High Byte
35  #define CC1101_SYNC0 0x05 // (0x91) Sync Word, Low Byte
36  #define CC1101_PKTLEN 0x06 // (0xFF) Packet Length
37  #define CC1101_PKTCTRL1 0x07 // (0x04) Packet Automation Control
38  #define CC1101_PKTCTRL0 0x08 // (0x45) Packet Automation Control
39  #define CC1101_ADDR 0x09 // (0x00) Device Address
40  #define CC1101_CHANNR 0x0A // (0x00) Channel Number
41  #define CC1101_FSCTRL1 0x0B // (0x0F) Frequency Synthesizer Control
42  #define CC1101_FSCTRL0 0x0C // (0x00) Frequency Synthesizer Control
43  #define CC1101_FREQ2 0x0D // (0x1E) Frequency Control Word, High Byte
44  #define CC1101_FREQ1 0x0E // (0xC4) Frequency Control Word, Middle Byte
45  #define CC1101_FREQ0 0x0F // (0xEC) Frequency Control Word, Low Byte
46  #define CC1101_MDMCFG4 0x10 // (0x8C) Modem Configuration
47  #define CC1101_MDMCFG3 0x11 // (0x22) Modem Configuration
48  #define CC1101_MDMCFG2 0x12 // (0x02) Modem Configuration
49  #define CC1101_MDMCFG1 0x13 // (0x22) Modem Configuration
50  #define CC1101_MDMCFG0 0x14 // (0xF8) Modem Configuration
51  #define CC1101_DEVIATN 0x15 // (0x47) Modem Deviation Setting
52  #define CC1101_MCSM2 0x16 // (0x07) Main Radio Control State Machine Configuration
53  #define CC1101_MCSM1 0x17 // (0x30) Main Radio Control State Machine Configuration
54  #define CC1101_MCSM0 0x18 // (0x04) Main Radio Control State Machine Configuration
55  #define CC1101_FOCCFG 0x19 // (0x36) Frequency Offset Compensation Configuration
56  #define CC1101_BSCFG 0x1A // (0x6C) Bit Synchronization Configuration
57  #define CC1101_AGCCTRL2 0x1B // (0x03) AGC Control
58  #define CC1101_AGCCTRL1 0x1C // (0x40) AGC Control
59  #define CC1101_AGCCTRL0 0x1D // (0x91) AGC Control
60  #define CC1101_WOREVT1 0x1E // (0x87) High Byte Event0 Timeout
61  #define CC1101_WOREVT0 0x1F // (0x6B) Low Byte Event0 Timeout
62  #define CC1101_WORCTRL 0x20 // (0xF8) Wake On Radio Control
63  #define CC1101_FREND1 0x21 // (0x56) Front End RX Configuration
64  #define CC1101_FREND0 0x22 // (0x10) Front End RX Configuration
65  #define CC1101_FSCAL3 0x23 // (0xA9) Frequency Synthesizer Calibration
66  #define CC1101_FSCAL2 0x24 // (0x0A) Frequency Synthesizer Calibration
67  #define CC1101_FSCAL1 0x25 // (0x20) Frequency Synthesizer Calibration
68  #define CC1101_FSCAL0 0x26 // (0x0D) Frequency Synthesizer Calibration
69  #define CC1101_RCCTRL1 0x27 // (0x41) RC Oscillator Configuration
70  #define CC1101_RCCTRL2 0x28 // (0x00) RC Oscillator Configuration
71  #define CC1101_FSTEST 0x29 // (0x59) Frequency Synthesizer Calibration Control
72  #define CC1101_PTEST 0x2A // (0x7F) Production Test
73  #define CC1101_AGCTEST 0x2B // (0x3F) AGC Test
74  #define CC1101_TEST2 0x2C // (0x88) Various Test Settings
75  #define CC1101_TEST1 0x2D // (0x31) Various Test Settings
76  #define CC1101_TEST0 0x2E // (0x0B) Various Test Settings
77 
78  #define CC1101_PARTNUM 0x30 // (0x00) Readonly: Chip ID
79  #define CC1101_VERSION 0x31 // (0x04) Readonly: Chip ID
80  #define CC1101_FREQEST 0x32 // (0x00) Readonly: Frequency Offset Estimate from Demodulator
81  #define CC1101_LQI 0x33 // (0x00) Readonly: Demodulator Estimate for Link Quality
82  #define CC1101_RSSI 0x34 // (0x00) Readonly: Received Signal Strength Indication
83  #define CC1101_MARCSTATE 0x35 // (0x00) Readonly: Main Radio Control State Machine State
84  #define CC1101_WORTIME1 0x36 // (0x00) Readonly: High Byte of WOR Time
85  #define CC1101_WORTIME0 0x37 // (0x00) Readonly: Low Byte of WOR Time
86  #define CC1101_PKTSTATUS 0x38 // (0x00) Readonly: Current GDOx Status and Packet Status
87  #define CC1101_VCO_VC_DAC 0x39 // (0x00) Readonly: Current Setting from PLL Calibration Module
88  #define CC1101_TXBYTES 0x3A // (0x00) Readonly: Underflow and Number of Bytes
89  #define CC1101_RXBYTES 0x3B // (0x00) Readonly: Overflow and Number of Bytes
90  #define CC1101_RCCTRL1_STATUS 0x3C // (0x00) Readonly: Last RC Oscillator Calibration Result
91  #define CC1101_RCCTRL0_STATUS 0x3D // (0x00) Readonly: Last RC Oscillator Calibration Result
92 
93  #define CC1101_PATABLE 0x3E // PATABLE address
94  #define CC1101_TXFIFO 0x3F // TX FIFO address
95  #define CC1101_RXFIFO 0x3F // RX FIFO address
96 
97  #define CC1101_PA_TABLE0 0x40 // (0x00) PA table, entry 0
98  #define CC1101_PA_TABLE1 0x41 // (0x00) PA table, entry 1
99  #define CC1101_PA_TABLE2 0x42 // (0x00) PA table, entry 2
100  #define CC1101_PA_TABLE3 0x43 // (0x00) PA table, entry 3
101  #define CC1101_PA_TABLE4 0x44 // (0x00) PA table, entry 4
102  #define CC1101_PA_TABLE5 0x45 // (0x00) PA table, entry 5
103  #define CC1101_PA_TABLE6 0x46 // (0x00) PA table, entry 6
104  #define CC1101_PA_TABLE7 0x47 // (0x00) PA table, entry 7
105 
106  // some register definitions for TRX868 communication
107  #define READ_SINGLE 0x80 // type of transfers
108  #define READ_BURST 0xC0
109  #define WRITE_BURST 0x40
110 
111  #define CC1101_CONFIG 0x80 // type of register
112  #define CC1101_STATUS 0xC0
113 
114  #define CC1101_SRES 0x30 // reset CC1101 chip
115  #define CC1101_SFSTXON 0x31 // enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). if in RX (with CCA): Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround).
116  #define CC1101_SXOFF 0x32 // turn off crystal oscillator
117  #define CC1101_SCAL 0x33 // calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without setting manual calibration mode (MCSM0.FS_AUTOCAL=0)
118  #define CC1101_SRX 0x34 // enable RX. perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1
119  #define CC1101_STX 0x35 // in IDLE state: enable TX. perform calibration first if MCSM0.FS_AUTOCAL=1. if in RX state and CCA is enabled: only go to TX if channel is clear
120  #define CC1101_SIDLE 0x36 // exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable
121  #define CC1101_SWOR 0x38 // start automatic RX polling sequence (Wake-on-Radio) as described in Section 19.5 if WORCTRL.RC_PD=0
122  #define CC1101_SPWD 0x39 // enter power down mode when CSn goes high
123  #define CC1101_SFRX 0x3A // flush the RX FIFO buffer. only issue SFRX in IDLE or RXFIFO_OVERFLOW states
124  #define CC1101_SFTX 0x3B // flush the TX FIFO buffer. only issue SFTX in IDLE or TXFIFO_UNDERFLOW states
125  #define CC1101_SWORRST 0x3C // reset real time clock to Event1 value
126  #define CC1101_SNOP 0x3D // no operation. may be used to get access to the chip status byte
127 
128  #define MARCSTATE_SLEEP 0x00
129  #define MARCSTATE_IDLE 0x01
130  #define MARCSTATE_XOFF 0x02
131  #define MARCSTATE_VCOON_MC 0x03
132  #define MARCSTATE_REGON_MC 0x04
133  #define MARCSTATE_MANCAL 0x05
134  #define MARCSTATE_VCOON 0x06
135  #define MARCSTATE_REGON 0x07
136  #define MARCSTATE_STARTCAL 0x08
137  #define MARCSTATE_BWBOOST 0x09
138  #define MARCSTATE_FS_LOCK 0x0A
139  #define MARCSTATE_IFADCON 0x0B
140  #define MARCSTATE_ENDCAL 0x0C
141  #define MARCSTATE_RX 0x0D
142  #define MARCSTATE_RX_END 0x0E
143  #define MARCSTATE_RX_RST 0x0F
144  #define MARCSTATE_TXRX_SWITCH 0x10
145  #define MARCSTATE_RXFIFO_OFLOW 0x11
146  #define MARCSTATE_FSTXON 0x12
147  #define MARCSTATE_TX 0x13
148  #define MARCSTATE_TX_END 0x14
149  #define MARCSTATE_RXTX_SWITCH 0x15
150  #define MARCSTATE_TXFIFO_UFLOW 0x16
151 
152  #define PA_LowPower 0x03 // PATABLE values
153  #define PA_Normal 0x50 // PATABLE values
154  #define PA_MaxPower 0xC0
155 
156 
157  public: //---------------------------------------------------------------------------------------------------------
158  void setIdle(void); // put CC1101 into power-down state
159  uint8_t detectBurst(void); // detect burst signal, sleep while no signal, otherwise stay awake
160 
161  protected: //---------------------------------------------------------------------------------------------------------
162  private: //---------------------------------------------------------------------------------------------------------
163 
164  CC();
165 
166  void init(); // initialize CC1101
167  uint8_t sndData(uint8_t *buf, uint8_t burst); // send data packet via RF
168  uint8_t rcvData(uint8_t *buf); // read data packet from RX FIFO
169 
170  void strobe(uint8_t cmd); // send command strobe to the CC1101 IC via SPI
171  void readBurst(uint8_t * buf, uint8_t regAddr, uint8_t len); // read burst data from CC1101 via SPI
172  void writeBurst(uint8_t regAddr, uint8_t* buf, uint8_t len); // write multiple registers into the CC1101 IC via SPI
173  uint8_t readReg(uint8_t regAddr, uint8_t regType); // read CC1101 register via SPI
174  void writeReg(uint8_t regAddr, uint8_t val); // write single register into the CC1101 IC via SPI
175 
176 };
177 
178 
179 #endif
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 /*void ccInitChip(void); // initialize the RF chip
200 
201 uint8_t ccStrobe(uint8_t strobe);
202 uint8_t ccReadReg(uint8_t addr); // read registers of cc1101 chip
203 void ccWriteReg(uint8_t addr, uint8_t data); // write registers of cc1101 chip
204 
205 void ccSsetOn(void);
206 void ccSetOff(void);
207 
208 void ccTX(void);
209 void ccRX(void);
210 
211 
212 // Configuration Registers
213 #define CC1100_IOCFG2 0x00 // GDO2 output pin configuration
214 #define CC1100_IOCFG1 0x01 // GDO1 output pin configuration
215 #define CC1100_IOCFG0 0x02 // GDO0 output pin configuration
216 #define CC1100_FIFOTHR 0x03 // RX FIFO and TX FIFO thresholds
217 #define CC1100_SYNC1 0x04 // Sync word, high byte
218 #define CC1100_SYNC0 0x05 // Sync word, low byte
219 #define CC1100_PKTLEN 0x06 // Packet length
220 #define CC1100_PKTCTRL1 0x07 // Packet automation control
221 #define CC1100_PKTCTRL0 0x08 // Packet automation control
222 #define CC1100_ADDR 0x09 // Device address
223 #define CC1100_CHANNR 0x0A // Channel number
224 #define CC1100_FSCTRL1 0x0B // Frequency synthesizer control
225 #define CC1100_FSCTRL0 0x0C // Frequency synthesizer control
226 #define CC1100_FREQ2 0x0D // Frequency control word, high byte
227 #define CC1100_FREQ1 0x0E // Frequency control word, middle byte
228 #define CC1100_FREQ0 0x0F // Frequency control word, low byte
229 #define CC1100_MDMCFG4 0x10 // Modem configuration
230 #define CC1100_MDMCFG3 0x11 // Modem configuration
231 #define CC1100_MDMCFG2 0x12 // Modem configuration
232 #define CC1100_MDMCFG1 0x13 // Modem configuration
233 #define CC1100_MDMCFG0 0x14 // Modem configuration
234 #define CC1100_DEVIATN 0x15 // Modem deviation setting
235 #define CC1100_MCSM2 0x16 // Main Radio Cntrl State Machine config
236 #define CC1100_MCSM1 0x17 // Main Radio Cntrl State Machine config
237 #define CC1100_MCSM0 0x18 // Main Radio Cntrl State Machine config
238 #define CC1100_FOCCFG 0x19 // Frequency Offset Compensation config
239 #define CC1100_BSCFG 0x1A // Bit Synchronization configuration
240 #define CC1100_AGCCTRL2 0x1B // AGC control
241 #define CC1100_AGCCTRL1 0x1C // AGC control
242 #define CC1100_AGCCTRL0 0x1D // AGC control
243 #define CC1100_WOREVT1 0x1E // High byte Event 0 timeout
244 #define CC1100_WOREVT0 0x1F // Low byte Event 0 timeout
245 #define CC1100_WORCTRL 0x20 // Wake On Radio control
246 #define CC1100_FREND1 0x21 // Front end RX configuration
247 #define CC1100_FREND0 0x22 // Front end TX configuration
248 #define CC1100_FSCAL3 0x23 // Frequency synthesizer calibration
249 #define CC1100_FSCAL2 0x24 // Frequency synthesizer calibration
250 #define CC1100_FSCAL1 0x25 // Frequency synthesizer calibration
251 #define CC1100_FSCAL0 0x26 // Frequency synthesizer calibration
252 #define CC1100_RCCTRL1 0x27 // RC oscillator configuration
253 #define CC1100_RCCTRL0 0x28 // RC oscillator configuration
254 #define CC1100_FSTEST 0x29 // Frequency synthesizer cal control
255 #define CC1100_PTEST 0x2A // Production test
256 #define CC1100_AGCTEST 0x2B // AGC test
257 #define CC1100_TEST2 0x2C // Various test settings
258 #define CC1100_TEST1 0x2D // Various test settings
259 #define CC1100_TEST0 0x2E // Various test settings
260 
261 #define CC1100_CONFIG 0x80 // type of register
262 #define CC1100_STATUS 0xC0
263 
264 // Status registers
265 #define CC1100_PARTNUM 0x30 // Part number
266 #define CC1100_VERSION 0x31 // Current version number
267 #define CC1100_FREQEST 0x32 // Frequency offset estimate
268 #define CC1100_LQI 0x33 // Demodulator estimate for link quality
269 #define CC1100_RSSI 0x34 // Received signal strength indication
270 #define CC1100_MARCSTATE 0x35 // Control state machine state
271 #define CC1100_WORTIME1 0x36 // High byte of WOR timer
272 #define CC1100_WORTIME0 0x37 // Low byte of WOR timer
273 #define CC1100_PKTSTATUS 0x38 // Current GDOx status and packet status
274 #define CC1100_VCO_VC_DAC 0x39 // Current setting from PLL cal module
275 #define CC1100_TXBYTES 0x3A // Underflow and # of bytes in TXFIFO
276 #define CC1100_RXBYTES 0x3B // Overflow and # of bytes in RXFIFO
277 
278 // Multi byte memory locations
279 #define CC1100_PATABLE 0x3E
280 #define CC1100_TXFIFO 0x3F
281 #define CC1100_RXFIFO 0x3F
282 
283 // Definitions for burst/single access to registers
284 #define CC1100_WRITE_BURST 0x40
285 #define CC1100_READ_SINGLE 0x80
286 #define CC1100_READ_BURST 0xC0
287 
288 // Strobe commands
289 #define CC1100_SRES 0x30 // Reset chip.
290 #define CC1100_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1).
291  // If in RX/TX: Go to a wait state where only the synthesizer is
292  // running (for quick RX / TX turnaround).
293 #define CC1100_SXOFF 0x32 // Turn off crystal oscillator.
294 #define CC1100_SCAL 0x33 // Calibrate frequency synthesizer and turn it off
295  // (enables quick start).
296 #define CC1100_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and
297  // MCSM0.FS_AUTOCAL=1.
298 #define CC1100_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if
299  // MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled:
300  // Only go to TX if channel is clear.
301 #define CC1100_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit
302  // Wake-On-Radio mode if applicable.
303 #define CC1100_SAFC 0x37 // Perform AFC adjustment of the frequency synthesizer
304 #define CC1100_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio)
305 #define CC1100_SPWD 0x39 // Enter power down mode when CSn goes high.
306 #define CC1100_SFRX 0x3A // Flush the RX FIFO buffer.
307 #define CC1100_SFTX 0x3B // Flush the TX FIFO buffer.
308 #define CC1100_SWORRST 0x3C // Reset real time clock.
309 #define CC1100_SNOP 0x3D // No operation. May be used to pad strobe commands to two
310  // bytes for simpler software.
311 
312 
313 //------------------------------------------------------------------------------
314 // Chip Status Byte
315 //------------------------------------------------------------------------------
316 
317 // Bit fields in the chip status byte
318 #define CC1100_STATUS_CHIP_RDYn_BM 0x80
319 #define CC1100_STATUS_STATE_BM 0x70
320 #define CC1100_STATUS_FIFO_BYTES_A 0x0F
321 
322 // Chip states
323 #define CC1100_STATE_IDLE 0x00
324 #define CC1100_STATE_RX 0x10
325 #define CC1100_STATE_TX 0x20
326 #define CC1100_STATE_FSTXON 0x30
327 #define CC1100_STATE_CALIBRATE 0x40
328 #define CC1100_STATE_SETTLING 0x50
329 #define CC1100_STATE_RX_OVERFLOW 0x60
330 #define CC1100_STATE_TX_UNDERFLOW 0x70
331 
332 
333 //------------------------------------------------------------------------------
334 // Other register bit fields
335 //------------------------------------------------------------------------------
336 #define CC1100_LQI_CRC_OK_BM 0x80
337 #define CC1100_LQI_EST_BM 0x7F
338 
339 #define MARCSTATE_SLEEP 0x00
340 #define MARCSTATE_IDLE 0x01
341 #define MARCSTATE_XOFF 0x02
342 #define MARCSTATE_VCOON_MC 0x03
343 #define MARCSTATE_REGON_MC 0x04
344 #define MARCSTATE_MANCAL 0x05
345 #define MARCSTATE_VCOON 0x06
346 #define MARCSTATE_REGON 0x07
347 #define MARCSTATE_STARTCAL 0x08
348 #define MARCSTATE_BWBOOST 0x09
349 #define MARCSTATE_FS_LOCK 0x0A
350 #define MARCSTATE_IFADCON 0x0B
351 #define MARCSTATE_ENDCAL 0x0C
352 #define MARCSTATE_RX 0x0D
353 #define MARCSTATE_RX_END 0x0E
354 #define MARCSTATE_RX_RST 0x0F
355 #define MARCSTATE_TXRX_SWITCH 0x10
356 #define MARCSTATE_RXFIFO_OVERFLOW 0x11
357 #define MARCSTATE_FSTXON 0x12
358 #define MARCSTATE_TX 0x13
359 #define MARCSTATE_TX_END 0x14
360 #define MARCSTATE_RXTX_SWITCH 0x15
361 #define MARCSTATE_TXFIFO_UNDERFLOW 0x16
362 
363 #define PA_LowPower 0x03 // PATABLE values
364 #define PA_Normal 0x50 // PATABLE values
365 #define PA_MaxPower 0xC0
366 */
Main class for implementation of the AskSin protocol stack. Every device needs exactly one instance o...
Definition: AS.h:39
Definition: CC1101.h:15
Definition: Send.h:16
Definition: Power.h:21