cc1200.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * cc1200.h
  3. *
  4. * Created on: Feb 5, 2022
  5. * Author: curiousmuch
  6. */
  7. #ifndef INC_CC1200_H_
  8. #define INC_CC1200_H_
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. /* configuration registers */
  12. #define CC120X_IOCFG3 0x0000
  13. #define CC120X_IOCFG2 0x0001
  14. #define CC120X_IOCFG1 0x0002
  15. #define CC120X_IOCFG0 0x0003
  16. #define CC120X_SYNC3 0x0004
  17. #define CC120X_SYNC2 0x0005
  18. #define CC120X_SYNC1 0x0006
  19. #define CC120X_SYNC0 0x0007
  20. #define CC120X_SYNC_CFG1 0x0008
  21. #define CC120X_SYNC_CFG0 0x0009
  22. #define CC120X_DEVIATION_M 0x000A
  23. #define CC120X_MODCFG_DEV_E 0x000B
  24. #define CC120X_DCFILT_CFG 0x000C
  25. #define CC120X_PREAMBLE_CFG1 0x000D
  26. #define CC120X_PREAMBLE_CFG0 0x000E
  27. #define CC120X_IQIC 0x000F
  28. #define CC120X_CHAN_BW 0x0010
  29. #define CC120X_MDMCFG1 0x0011
  30. #define CC120X_MDMCFG0 0x0012
  31. #define CC120X_SYMBOL_RATE2 0x0013
  32. #define CC120X_SYMBOL_RATE1 0x0014
  33. #define CC120X_SYMBOL_RATE0 0x0015
  34. #define CC120X_AGC_REF 0x0016
  35. #define CC120X_AGC_CS_THR 0x0017
  36. #define CC120X_AGC_GAIN_ADJUST 0x0018
  37. #define CC120X_AGC_CFG3 0x0019
  38. #define CC120X_AGC_CFG2 0x001A
  39. #define CC120X_AGC_CFG1 0x001B
  40. #define CC120X_AGC_CFG0 0x001C
  41. #define CC120X_FIFO_CFG 0x001D
  42. #define CC120X_DEV_ADDR 0x001E
  43. #define CC120X_SETTLING_CFG 0x001F
  44. #define CC120X_FS_CFG 0x0020
  45. #define CC120X_WOR_CFG1 0x0021
  46. #define CC120X_WOR_CFG0 0x0022
  47. #define CC120X_WOR_EVENT0_MSB 0x0023
  48. #define CC120X_WOR_EVENT0_LSB 0x0024
  49. #define CC120X_RXDCM_TIME 0x0025
  50. #define CC120X_PKT_CFG2 0x0026
  51. #define CC120X_PKT_CFG1 0x0027
  52. #define CC120X_PKT_CFG0 0x0028
  53. #define CC120X_RFEND_CFG1 0x0029
  54. #define CC120X_RFEND_CFG0 0x002A
  55. #define CC120X_PA_CFG1 0x002B
  56. #define CC120X_PA_CFG0 0x002C
  57. #define CC120X_ASK_CFG 0x002D
  58. #define CC120X_PKT_LEN 0x002E
  59. /* Extended Configuration Registers */
  60. #define CC120X_IF_MIX_CFG 0x2F00
  61. #define CC120X_FREQOFF_CFG 0x2F01
  62. #define CC120X_TOC_CFG 0x2F02
  63. #define CC120X_MARC_SPARE 0x2F03
  64. #define CC120X_ECG_CFG 0x2F04
  65. #define CC120X_MDMCFG2 0x2F05
  66. #define CC120X_EXT_CTRL 0x2F06
  67. #define CC120X_RCCAL_FINE 0x2F07
  68. #define CC120X_RCCAL_COARSE 0x2F08
  69. #define CC120X_RCCAL_OFFSET 0x2F09
  70. #define CC120X_FREQOFF1 0x2F0A
  71. #define CC120X_FREQOFF0 0x2F0B
  72. #define CC120X_FREQ2 0x2F0C
  73. #define CC120X_FREQ1 0x2F0D
  74. #define CC120X_FREQ0 0x2F0E
  75. #define CC120X_IF_ADC2 0x2F0F
  76. #define CC120X_IF_ADC1 0x2F10
  77. #define CC120X_IF_ADC0 0x2F11
  78. #define CC120X_FS_DIG1 0x2F12
  79. #define CC120X_FS_DIG0 0x2F13
  80. #define CC120X_FS_CAL3 0x2F14
  81. #define CC120X_FS_CAL2 0x2F15
  82. #define CC120X_FS_CAL1 0x2F16
  83. #define CC120X_FS_CAL0 0x2F17
  84. #define CC120X_FS_CHP 0x2F18
  85. #define CC120X_FS_DIVTWO 0x2F19
  86. #define CC120X_FS_DSM1 0x2F1A
  87. #define CC120X_FS_DSM0 0x2F1B
  88. #define CC120X_FS_DVC1 0x2F1C
  89. #define CC120X_FS_DVC0 0x2F1D
  90. #define CC120X_FS_LBI 0x2F1E
  91. #define CC120X_FS_PFD 0x2F1F
  92. #define CC120X_FS_PRE 0x2F20
  93. #define CC120X_FS_REG_DIV_CML 0x2F21
  94. #define CC120X_FS_SPARE 0x2F22
  95. #define CC120X_FS_VCO4 0x2F23
  96. #define CC120X_FS_VCO3 0x2F24
  97. #define CC120X_FS_VCO2 0x2F25
  98. #define CC120X_FS_VCO1 0x2F26
  99. #define CC120X_FS_VCO0 0x2F27
  100. #define CC120X_GBIAS6 0x2F28
  101. #define CC120X_GBIAS5 0x2F29
  102. #define CC120X_GBIAS4 0x2F2A
  103. #define CC120X_GBIAS3 0x2F2B
  104. #define CC120X_GBIAS2 0x2F2C
  105. #define CC120X_GBIAS1 0x2F2D
  106. #define CC120X_GBIAS0 0x2F2E
  107. #define CC120X_IFAMP 0x2F2F
  108. #define CC120X_LNA 0x2F30
  109. #define CC120X_RXMIX 0x2F31
  110. #define CC120X_XOSC5 0x2F32
  111. #define CC120X_XOSC4 0x2F33
  112. #define CC120X_XOSC3 0x2F34
  113. #define CC120X_XOSC2 0x2F35
  114. #define CC120X_XOSC1 0x2F36
  115. #define CC120X_XOSC0 0x2F37
  116. #define CC120X_ANALOG_SPARE 0x2F38
  117. #define CC120X_PA_CFG3 0x2F39
  118. #define CC120X_IRQ0M 0x2F3F
  119. #define CC120X_IRQ0F 0x2F40
  120. /* Status Registers */
  121. #define CC120X_WOR_TIME1 0x2F64
  122. #define CC120X_WOR_TIME0 0x2F65
  123. #define CC120X_WOR_CAPTURE1 0x2F66
  124. #define CC120X_WOR_CAPTURE0 0x2F67
  125. #define CC120X_BIST 0x2F68
  126. #define CC120X_DCFILTOFFSET_I1 0x2F69
  127. #define CC120X_DCFILTOFFSET_I0 0x2F6A
  128. #define CC120X_DCFILTOFFSET_Q1 0x2F6B
  129. #define CC120X_DCFILTOFFSET_Q0 0x2F6C
  130. #define CC120X_IQIE_I1 0x2F6D
  131. #define CC120X_IQIE_I0 0x2F6E
  132. #define CC120X_IQIE_Q1 0x2F6F
  133. #define CC120X_IQIE_Q0 0x2F70
  134. #define CC120X_RSSI1 0x2F71
  135. #define CC120X_RSSI0 0x2F72
  136. #define CC120X_MARCSTATE 0x2F73
  137. #define CC120X_LQI_VAL 0x2F74
  138. #define CC120X_PQT_SYNC_ERR 0x2F75
  139. #define CC120X_DEM_STATUS 0x2F76
  140. #define CC120X_FREQOFF_EST1 0x2F77
  141. #define CC120X_FREQOFF_EST0 0x2F78
  142. #define CC120X_AGC_GAIN3 0x2F79
  143. #define CC120X_AGC_GAIN2 0x2F7A
  144. #define CC120X_AGC_GAIN1 0x2F7B
  145. #define CC120X_AGC_GAIN0 0x2F7C
  146. #define CC120X_CFM_RX_DATA_OUT 0x2F7D
  147. #define CC120X_CFM_TX_DATA_IN 0x2F7E
  148. #define CC120X_ASK_SOFT_RX_DATA 0x2F7F
  149. #define CC120X_RNDGEN 0x2F80
  150. #define CC120X_MAGN2 0x2F81
  151. #define CC120X_MAGN1 0x2F82
  152. #define CC120X_MAGN0 0x2F83
  153. #define CC120X_ANG1 0x2F84
  154. #define CC120X_ANG0 0x2F85
  155. #define CC120X_CHFILT_I2 0x2F86
  156. #define CC120X_CHFILT_I1 0x2F87
  157. #define CC120X_CHFILT_I0 0x2F88
  158. #define CC120X_CHFILT_Q2 0x2F89
  159. #define CC120X_CHFILT_Q1 0x2F8A
  160. #define CC120X_CHFILT_Q0 0x2F8B
  161. #define CC120X_GPIO_STATUS 0x2F8C
  162. #define CC120X_FSCAL_CTRL 0x2F8D
  163. #define CC120X_PHASE_ADJUST 0x2F8E
  164. #define CC120X_PARTNUMBER 0x2F8F
  165. #define CC120X_PARTVERSION 0x2F90
  166. #define CC120X_SERIAL_STATUS 0x2F91
  167. #define CC120X_MODEM_STATUS1 0x2F92
  168. #define CC120X_MODEM_STATUS0 0x2F93
  169. #define CC120X_MARC_STATUS1 0x2F94
  170. #define CC120X_MARC_STATUS0 0x2F95
  171. #define CC120X_PA_IFAMP_TEST 0x2F96
  172. #define CC120X_FSRF_TEST 0x2F97
  173. #define CC120X_PRE_TEST 0x2F98
  174. #define CC120X_PRE_OVR 0x2F99
  175. #define CC120X_ADC_TEST 0x2F9A
  176. #define CC120X_DVC_TEST 0x2F9B
  177. #define CC120X_ATEST 0x2F9C
  178. #define CC120X_ATEST_LVDS 0x2F9D
  179. #define CC120X_ATEST_MODE 0x2F9E
  180. #define CC120X_XOSC_TEST1 0x2F9F
  181. #define CC120X_XOSC_TEST0 0x2FA0
  182. #define CC120X_AES 0x2FA1
  183. #define CC120X_MDM_TEST 0x2FA2
  184. #define CC120X_RXFIRST 0x2FD2
  185. #define CC120X_TXFIRST 0x2FD3
  186. #define CC120X_RXLAST 0x2FD4
  187. #define CC120X_TXLAST 0x2FD5
  188. #define CC120X_NUM_TXBYTES 0x2FD6 /* Number of bytes in TXFIFO */
  189. #define CC120X_NUM_RXBYTES 0x2FD7 /* Number of bytes in RXFIFO */
  190. #define CC120X_FIFO_NUM_TXBYTES 0x2FD8
  191. #define CC120X_FIFO_NUM_RXBYTES 0x2FD9
  192. #define CC120X_RXFIFO_PRE_BUF 0x2FDA
  193. /* DATA FIFO Access */
  194. #define CC120X_SINGLE_TXFIFO 0x003F /* TXFIFO - Single accecss to Transmit FIFO */
  195. #define CC120X_BURST_TXFIFO 0x007F /* TXFIFO - Burst accecss to Transmit FIFO */
  196. #define CC120X_SINGLE_RXFIFO 0x00BF /* RXFIFO - Single accecss to Receive FIFO */
  197. #define CC120X_BURST_RXFIFO 0x00FF /* RXFIFO - Busrrst ccecss to Receive FIFO */
  198. /* AES Workspace */
  199. /* AES Key */
  200. #define CC120X_AES_KEY 0x2FE0 /* AES_KEY - Address for AES key input */
  201. #define CC120X_AES_KEY15 0x2FE0
  202. #define CC120X_AES_KEY14 0x2FE1
  203. #define CC120X_AES_KEY13 0x2FE2
  204. #define CC120X_AES_KEY12 0x2FE3
  205. #define CC120X_AES_KEY11 0x2FE4
  206. #define CC120X_AES_KEY10 0x2FE5
  207. #define CC120X_AES_KEY9 0x2FE6
  208. #define CC120X_AES_KEY8 0x2FE7
  209. #define CC120X_AES_KEY7 0x2FE8
  210. #define CC120X_AES_KEY6 0x2FE9
  211. #define CC120X_AES_KEY5 0x2FE10
  212. #define CC120X_AES_KEY4 0x2FE11
  213. #define CC120X_AES_KEY3 0x2FE12
  214. #define CC120X_AES_KEY2 0x2FE13
  215. #define CC120X_AES_KEY1 0x2FE14
  216. #define CC120X_AES_KEY0 0x2FE15
  217. /* AES Buffer */
  218. #define CC120X_AES_BUFFER 0x2FF0 /* AES_BUFFER - Address for AES Buffer */
  219. #define CC120X_AES_BUFFER15 0x2FF0
  220. #define CC120X_AES_BUFFER14 0x2FF1
  221. #define CC120X_AES_BUFFER13 0x2FF2
  222. #define CC120X_AES_BUFFER12 0x2FF3
  223. #define CC120X_AES_BUFFER11 0x2FF4
  224. #define CC120X_AES_BUFFER10 0x2FF5
  225. #define CC120X_AES_BUFFER9 0x2FF6
  226. #define CC120X_AES_BUFFER8 0x2FF7
  227. #define CC120X_AES_BUFFER7 0x2FF8
  228. #define CC120X_AES_BUFFER6 0x2FF9
  229. #define CC120X_AES_BUFFER5 0x2FF10
  230. #define CC120X_AES_BUFFER4 0x2FF11
  231. #define CC120X_AES_BUFFER3 0x2FF12
  232. #define CC120X_AES_BUFFER2 0x2FF13
  233. #define CC120X_AES_BUFFER1 0x2FF14
  234. #define CC120X_AES_BUFFER0 0x2FF15
  235. #define CC120X_LQI_CRC_OK_BM 0x80
  236. #define CC120X_LQI_EST_BM 0x7F
  237. /* Command strobe registers */
  238. #define CC120X_SRES 0x30 /* SRES - Reset chip. */
  239. #define CC120X_SFSTXON 0x31 /* SFSTXON - Enable and calibrate frequency synthesizer. */
  240. #define CC120X_SXOFF 0x32 /* SXOFF - Turn off crystal oscillator. */
  241. #define CC120X_SCAL 0x33 /* SCAL - Calibrate frequency synthesizer and turn it off. */
  242. #define CC120X_SRX 0x34 /* SRX - Enable RX. Perform calibration if enabled. */
  243. #define CC120X_STX 0x35 /* STX - Enable TX. If in RX state, only enable TX if CCA passes. */
  244. #define CC120X_SIDLE 0x36 /* SIDLE - Exit RX / TX, turn off frequency synthesizer. */
  245. #define CC120X_SAFC 0x37 /* AFC - Automatic Frequency Correction */
  246. #define CC120X_SWOR 0x38 /* SWOR - Start automatic RX polling sequence (Wake-on-Radio) */
  247. #define CC120X_SPWD 0x39 /* SPWD - Enter power down mode when CSn goes high. */
  248. #define CC120X_SFRX 0x3A /* SFRX - Flush the RX FIFO buffer. */
  249. #define CC120X_SFTX 0x3B /* SFTX - Flush the TX FIFO buffer. */
  250. #define CC120X_SWORRST 0x3C /* SWORRST - Reset real time clock. */
  251. #define CC120X_SNOP 0x3D /* SNOP - No operation. Returns status byte. */
  252. /* Chip states returned in status byte */
  253. #define CC120X_STATE_IDLE 0x00
  254. #define CC120X_STATE_RX 0x10
  255. #define CC120X_STATE_TX 0x20
  256. #define CC120X_STATE_FSTXON 0x30
  257. #define CC120X_STATE_CALIBRATE 0x40
  258. #define CC120X_STATE_SETTLING 0x50
  259. #define CC120X_STATE_RXFIFO_ERROR 0x60
  260. #define CC120X_STATE_TXFIFO_ERROR 0x70
  261. #define CC120X_RDYn_BIT BIT(7)
  262. /* FIFO Address */
  263. #define CC120X_FIFO 0x3F
  264. /* Data Structures */
  265. typedef uint8_t rf_status_t;
  266. typedef struct {
  267. uint16_t addr;
  268. uint8_t data;
  269. } cc1200_reg_settings_t;
  270. /* Public Functions */
  271. // Configuration
  272. void cc1200_radio_init(const cc1200_reg_settings_t* rf_settings, uint8_t len);
  273. void cc1200_radio_frequency(uint32_t);
  274. void cc1200_radio_config(const cc1200_reg_settings_t* , uint8_t );
  275. rf_status_t cc1200_radio_reset(void);
  276. // Mode
  277. void cc1200_radio_tx(void);
  278. void cc1200_radio_rx(void);
  279. void cc1200_radio_idle(void);
  280. void cc1200_radio_sleep(void);
  281. // Data
  282. uint8_t cc1200_radio_read_RSSI(void);
  283. uint8_t cc1200_radio_read_CFM(void);
  284. void cc1200_radio_write_CFM(int8_t);
  285. #endif /* INC_CC1200_H_ */