UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
cc112x_spi.h
1 /*****************************************************************************/
2 // @file CC112x_spi.h
3 //
4 // @brief header file that defines a minimum set of neccessary functions
5 // to communicate with CC112X over SPI as well as the regsister
6 // mapping.
7 //
8 // Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
12 // are met:
13 //
14 // Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // Neither the name of Texas Instruments Incorporated nor the names of
22 // its contributors may be used to endorse or promote products derived
23 // from this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /****************************************************************************/
37 
38 #ifndef CC112x_SPI_H
39 #define CC112x_SPI_H
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 /******************************************************************************
45  * INCLUDES
46  */
47 //#include "hal_types.h"
48 #include <stdint.h>
49 #ifdef MSP_EXP430G2
50  #include "hal_msp_exp430g2_spi.h"
51 #else
52  #include "hal_spi_rf_trxeb.h"
53 #endif
54 
55 /******************************************************************************
56  * CONSTANTS
57  */
58 
59 /* configuration registers */
60 #define CC112X_IOCFG3 0x0000
61 #define CC112X_IOCFG2 0x0001
62 #define CC112X_IOCFG1 0x0002
63 #define CC112X_IOCFG0 0x0003
64 #define CC112X_SYNC3 0x0004
65 #define CC112X_SYNC2 0x0005
66 #define CC112X_SYNC1 0x0006
67 #define CC112X_SYNC0 0x0007
68 #define CC112X_SYNC_CFG1 0x0008
69 #define CC112X_SYNC_CFG0 0x0009
70 #define CC112X_DEVIATION_M 0x000A
71 #define CC112X_MODCFG_DEV_E 0x000B
72 #define CC112X_DCFILT_CFG 0x000C
73 #define CC112X_PREAMBLE_CFG1 0x000D
74 #define CC112X_PREAMBLE_CFG0 0x000E
75 #define CC112X_FREQ_IF_CFG 0x000F
76 #define CC112X_IQIC 0x0010
77 #define CC112X_CHAN_BW 0x0011
78 #define CC112X_MDMCFG1 0x0012
79 #define CC112X_MDMCFG0 0x0013
80 #define CC112X_SYMBOL_RATE2 0x0014
81 #define CC112X_SYMBOL_RATE1 0x0015
82 #define CC112X_SYMBOL_RATE0 0x0016
83 #define CC112X_AGC_REF 0x0017
84 #define CC112X_AGC_CS_THR 0x0018
85 #define CC112X_AGC_GAIN_ADJUST 0x0019
86 #define CC112X_AGC_CFG3 0x001A
87 #define CC112X_AGC_CFG2 0x001B
88 #define CC112X_AGC_CFG1 0x001C
89 #define CC112X_AGC_CFG0 0x001D
90 #define CC112X_FIFO_CFG 0x001E
91 #define CC112X_DEV_ADDR 0x001F
92 #define CC112X_SETTLING_CFG 0x0020
93 #define CC112X_FS_CFG 0x0021
94 #define CC112X_WOR_CFG1 0x0022
95 #define CC112X_WOR_CFG0 0x0023
96 #define CC112X_WOR_EVENT0_MSB 0x0024
97 #define CC112X_WOR_EVENT0_LSB 0x0025
98 #define CC112X_PKT_CFG2 0x0026
99 #define CC112X_PKT_CFG1 0x0027
100 #define CC112X_PKT_CFG0 0x0028
101 #define CC112X_RFEND_CFG1 0x0029
102 #define CC112X_RFEND_CFG0 0x002A
103 #define CC112X_PA_CFG2 0x002B
104 #define CC112X_PA_CFG1 0x002C
105 #define CC112X_PA_CFG0 0x002D
106 #define CC112X_PKT_LEN 0x002E
107 
108 /* Extended Configuration Registers */
109 #define CC112X_IF_MIX_CFG 0x2F00
110 #define CC112X_FREQOFF_CFG 0x2F01
111 #define CC112X_TOC_CFG 0x2F02
112 #define CC112X_MARC_SPARE 0x2F03
113 #define CC112X_ECG_CFG 0x2F04
114 #define CC112X_CFM_DATA_CFG 0x2F05
115 #define CC112X_EXT_CTRL 0x2F06
116 #define CC112X_RCCAL_FINE 0x2F07
117 #define CC112X_RCCAL_COARSE 0x2F08
118 #define CC112X_RCCAL_OFFSET 0x2F09
119 #define CC112X_FREQOFF1 0x2F0A
120 #define CC112X_FREQOFF0 0x2F0B
121 #define CC112X_FREQ2 0x2F0C
122 #define CC112X_FREQ1 0x2F0D
123 #define CC112X_FREQ0 0x2F0E
124 #define CC112X_IF_ADC2 0x2F0F
125 #define CC112X_IF_ADC1 0x2F10
126 #define CC112X_IF_ADC0 0x2F11
127 #define CC112X_FS_DIG1 0x2F12
128 #define CC112X_FS_DIG0 0x2F13
129 #define CC112X_FS_CAL3 0x2F14
130 #define CC112X_FS_CAL2 0x2F15
131 #define CC112X_FS_CAL1 0x2F16
132 #define CC112X_FS_CAL0 0x2F17
133 #define CC112X_FS_CHP 0x2F18
134 #define CC112X_FS_DIVTWO 0x2F19
135 #define CC112X_FS_DSM1 0x2F1A
136 #define CC112X_FS_DSM0 0x2F1B
137 #define CC112X_FS_DVC1 0x2F1C
138 #define CC112X_FS_DVC0 0x2F1D
139 #define CC112X_FS_LBI 0x2F1E
140 #define CC112X_FS_PFD 0x2F1F
141 #define CC112X_FS_PRE 0x2F20
142 #define CC112X_FS_REG_DIV_CML 0x2F21
143 #define CC112X_FS_SPARE 0x2F22
144 #define CC112X_FS_VCO4 0x2F23
145 #define CC112X_FS_VCO3 0x2F24
146 #define CC112X_FS_VCO2 0x2F25
147 #define CC112X_FS_VCO1 0x2F26
148 #define CC112X_FS_VCO0 0x2F27
149 #define CC112X_GBIAS6 0x2F28
150 #define CC112X_GBIAS5 0x2F29
151 #define CC112X_GBIAS4 0x2F2A
152 #define CC112X_GBIAS3 0x2F2B
153 #define CC112X_GBIAS2 0x2F2C
154 #define CC112X_GBIAS1 0x2F2D
155 #define CC112X_GBIAS0 0x2F2E
156 #define CC112X_IFAMP 0x2F2F
157 #define CC112X_LNA 0x2F30
158 #define CC112X_RXMIX 0x2F31
159 #define CC112X_XOSC5 0x2F32
160 #define CC112X_XOSC4 0x2F33
161 #define CC112X_XOSC3 0x2F34
162 #define CC112X_XOSC2 0x2F35
163 #define CC112X_XOSC1 0x2F36
164 #define CC112X_XOSC0 0x2F37
165 #define CC112X_ANALOG_SPARE 0x2F38
166 #define CC112X_PA_CFG3 0x2F39
167 #define CC112X_IRQ0M 0x2F3F
168 #define CC112X_IRQ0F 0x2F40
169 
170 /* Status Registers */
171 #define CC112X_WOR_TIME1 0x2F64
172 #define CC112X_WOR_TIME0 0x2F65
173 #define CC112X_WOR_CAPTURE1 0x2F66
174 #define CC112X_WOR_CAPTURE0 0x2F67
175 #define CC112X_BIST 0x2F68
176 #define CC112X_DCFILTOFFSET_I1 0x2F69
177 #define CC112X_DCFILTOFFSET_I0 0x2F6A
178 #define CC112X_DCFILTOFFSET_Q1 0x2F6B
179 #define CC112X_DCFILTOFFSET_Q0 0x2F6C
180 #define CC112X_IQIE_I1 0x2F6D
181 #define CC112X_IQIE_I0 0x2F6E
182 #define CC112X_IQIE_Q1 0x2F6F
183 #define CC112X_IQIE_Q0 0x2F70
184 #define CC112X_RSSI1 0x2F71
185 #define CC112X_RSSI0 0x2F72
186 #define CC112X_MARCSTATE 0x2F73
187 #define CC112X_LQI_VAL 0x2F74
188 #define CC112X_PQT_SYNC_ERR 0x2F75
189 #define CC112X_DEM_STATUS 0x2F76
190 #define CC112X_FREQOFF_EST1 0x2F77
191 #define CC112X_FREQOFF_EST0 0x2F78
192 #define CC112X_AGC_GAIN3 0x2F79
193 #define CC112X_AGC_GAIN2 0x2F7A
194 #define CC112X_AGC_GAIN1 0x2F7B
195 #define CC112X_AGC_GAIN0 0x2F7C
196 #define CC112X_CFM_RX_DATA_OUT 0x2F7D
197 #define CC112X_CFM_TX_DATA_IN 0x2F7E
198 #define CC112X_ASK_SOFT_RX_DATA 0x2F7F
199 #define CC112X_RNDGEN 0x2F80
200 #define CC112X_MAGN2 0x2F81
201 #define CC112X_MAGN1 0x2F82
202 #define CC112X_MAGN0 0x2F83
203 #define CC112X_ANG1 0x2F84
204 #define CC112X_ANG0 0x2F85
205 #define CC112X_CHFILT_I2 0x2F86
206 #define CC112X_CHFILT_I1 0x2F87
207 #define CC112X_CHFILT_I0 0x2F88
208 #define CC112X_CHFILT_Q2 0x2F89
209 #define CC112X_CHFILT_Q1 0x2F8A
210 #define CC112X_CHFILT_Q0 0x2F8B
211 #define CC112X_GPIO_STATUS 0x2F8C
212 #define CC112X_FSCAL_CTRL 0x2F8D
213 #define CC112X_PHASE_ADJUST 0x2F8E
214 #define CC112X_PARTNUMBER 0x2F8F
215 #define CC112X_PARTVERSION 0x2F90
216 #define CC112X_SERIAL_STATUS 0x2F91
217 #define CC112X_MODEM_STATUS1 0x2F92
218 #define CC112X_MODEM_STATUS0 0x2F93
219 #define CC112X_MARC_STATUS1 0x2F94
220 #define CC112X_MARC_STATUS0 0x2F95
221 #define CC112X_PA_IFAMP_TEST 0x2F96
222 #define CC112X_FSRF_TEST 0x2F97
223 #define CC112X_PRE_TEST 0x2F98
224 #define CC112X_PRE_OVR 0x2F99
225 #define CC112X_ADC_TEST 0x2F9A
226 #define CC112X_DVC_TEST 0x2F9B
227 #define CC112X_ATEST 0x2F9C
228 #define CC112X_ATEST_LVDS 0x2F9D
229 #define CC112X_ATEST_MODE 0x2F9E
230 #define CC112X_XOSC_TEST1 0x2F9F
231 #define CC112X_XOSC_TEST0 0x2FA0
232 
233 #define CC112X_RXFIRST 0x2FD2
234 #define CC112X_TXFIRST 0x2FD3
235 #define CC112X_RXLAST 0x2FD4
236 #define CC112X_TXLAST 0x2FD5
237 #define CC112X_NUM_TXBYTES 0x2FD6 /* Number of bytes in TXFIFO */
238 #define CC112X_NUM_RXBYTES 0x2FD7 /* Number of bytes in RXFIFO */
239 #define CC112X_FIFO_NUM_TXBYTES 0x2FD8
240 #define CC112X_FIFO_NUM_RXBYTES 0x2FD9
241 
242 
243 /* DATA FIFO Access */
244 #define CC112X_SINGLE_TXFIFO 0x003F /* TXFIFO - Single accecss to Transmit FIFO */
245 #define CC112X_BURST_TXFIFO 0x007F /* TXFIFO - Burst accecss to Transmit FIFO */
246 #define CC112X_SINGLE_RXFIFO 0x00BF /* RXFIFO - Single accecss to Receive FIFO */
247 #define CC112X_BURST_RXFIFO 0x00FF /* RXFIFO - Busrrst ccecss to Receive FIFO */
248 
249 #define CC112X_LQI_CRC_OK_BM 0x80
250 #define CC112X_LQI_EST_BM 0x7F
251 
252 
253 
254 /* Command strobe registers */
255 #define CC112X_SRES 0x30 /* SRES - Reset chip. */
256 #define CC112X_SFSTXON 0x31 /* SFSTXON - Enable and calibrate frequency synthesizer. */
257 #define CC112X_SXOFF 0x32 /* SXOFF - Turn off crystal oscillator. */
258 #define CC112X_SCAL 0x33 /* SCAL - Calibrate frequency synthesizer and turn it off. */
259 #define CC112X_SRX 0x34 /* SRX - Enable RX. Perform calibration if enabled. */
260 #define CC112X_STX 0x35 /* STX - Enable TX. If in RX state, only enable TX if CCA passes. */
261 #define CC112X_SIDLE 0x36 /* SIDLE - Exit RX / TX, turn off frequency synthesizer. */
262 #define CC112X_SWOR 0x38 /* SWOR - Start automatic RX polling sequence (Wake-on-Radio) */
263 #define CC112X_SPWD 0x39 /* SPWD - Enter power down mode when CSn goes high. */
264 #define CC112X_SFRX 0x3A /* SFRX - Flush the RX FIFO buffer. */
265 #define CC112X_SFTX 0x3B /* SFTX - Flush the TX FIFO buffer. */
266 #define CC112X_SWORRST 0x3C /* SWORRST - Reset real time clock. */
267 #define CC112X_SNOP 0x3D /* SNOP - No operation. Returns status byte. */
268 #define CC112X_AFC 0x37 /* AFC - Automatic Frequency Correction */
269 
270 /* Chip states returned in status byte */
271 #define CC112X_STATE_IDLE 0x00
272 #define CC112X_STATE_RX 0x10
273 #define CC112X_STATE_TX 0x20
274 #define CC112X_STATE_FSTXON 0x30
275 #define CC112X_STATE_CALIBRATE 0x40
276 #define CC112X_STATE_SETTLING 0x50
277 #define CC112X_STATE_RXFIFO_ERROR 0x60
278 #define CC112X_STATE_TXFIFO_ERROR 0x70
279 
280 
281 
282 
283 
284 /******************************************************************************
285  * PROTPTYPES
286  */
287 
288 /* basic set of access functions */
289 rfStatus_t cc112xSpiReadReg(uint16_t addr, uint8_t *data, uint8_t len);
290 rfStatus_t cc112xGetTxStatus(void);
291 rfStatus_t cc112xGetRxStatus(void);
292 rfStatus_t cc112xSpiWriteReg(uint16_t addr, uint8_t *data, uint8_t len);
293 rfStatus_t cc112xSpiWriteTxFifo(uint8_t *pWriteData, uint8_t len);
294 rfStatus_t cc112xSpiReadRxFifo(uint8_t *pReadData, uint8_t len);
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif// CC112x_SPI_H