cc1101_regs.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* Frequency Synthesizer constants */
  8. #define CC1101_QUARTZ 26000000
  9. #define CC1101_FMASK 0xFFFFFF
  10. #define CC1101_FDIV 0x10000
  11. #define CC1101_IFDIV 0x400
  12. /* IO Bus constants */
  13. #define CC1101_TIMEOUT 500
  14. /* Bits and pieces */
  15. #define CC1101_READ (1 << 7) /** Read Bit */
  16. #define CC1101_BURST (1 << 6) /** Burst Bit */
  17. /* Common registers, CC1101_BURST and CC1101_WRITE behaves as expected */
  18. #define CC1101_IOCFG2 0x00 /** GDO2 output pin configuration */
  19. #define CC1101_IOCFG1 0x01 /** GDO1 output pin configuration */
  20. #define CC1101_IOCFG0 0x02 /** GDO0 output pin configuration */
  21. #define CC1101_FIFOTHR 0x03 /** RX FIFO and TX FIFO thresholds */
  22. #define CC1101_SYNC1 0x04 /** Sync word, high byte */
  23. #define CC1101_SYNC0 0x05 /** Sync word, low byte */
  24. #define CC1101_PKTLEN 0x06 /** Packet length */
  25. #define CC1101_PKTCTRL1 0x07 /** Packet automation control */
  26. #define CC1101_PKTCTRL0 0x08 /** Packet automation control */
  27. #define CC1101_ADDR 0x09 /** Device address */
  28. #define CC1101_CHANNR 0x0A /** Channel number */
  29. #define CC1101_FSCTRL1 0x0B /** Frequency synthesizer control */
  30. #define CC1101_FSCTRL0 0x0C /** Frequency synthesizer control */
  31. #define CC1101_FREQ2 0x0D /** Frequency control word, high byte */
  32. #define CC1101_FREQ1 0x0E /** Frequency control word, middle byte */
  33. #define CC1101_FREQ0 0x0F /** Frequency control word, low byte */
  34. #define CC1101_MDMCFG4 0x10 /** Modem configuration */
  35. #define CC1101_MDMCFG3 0x11 /** Modem configuration */
  36. #define CC1101_MDMCFG2 0x12 /** Modem configuration */
  37. #define CC1101_MDMCFG1 0x13 /** Modem configuration */
  38. #define CC1101_MDMCFG0 0x14 /** Modem configuration */
  39. #define CC1101_DEVIATN 0x15 /** Modem deviation setting */
  40. #define CC1101_MCSM2 0x16 /** Main Radio Control State Machine configuration */
  41. #define CC1101_MCSM1 0x17 /** Main Radio Control State Machine configuration */
  42. #define CC1101_MCSM0 0x18 /** Main Radio Control State Machine configuration */
  43. #define CC1101_FOCCFG 0x19 /** Frequency Offset Compensation configuration */
  44. #define CC1101_BSCFG 0x1A /** Bit Synchronization configuration */
  45. #define CC1101_AGCCTRL2 0x1B /** AGC control */
  46. #define CC1101_AGCCTRL1 0x1C /** AGC control */
  47. #define CC1101_AGCCTRL0 0x1D /** AGC control */
  48. #define CC1101_WOREVT1 0x1E /** High byte Event 0 timeout */
  49. #define CC1101_WOREVT0 0x1F /** Low byte Event 0 timeout */
  50. #define CC1101_WORCTRL 0x20 /** Wake On Radio control */
  51. #define CC1101_FREND1 0x21 /** Front end RX configuration */
  52. #define CC1101_FREND0 0x22 /** Front end TX configuration */
  53. #define CC1101_FSCAL3 0x23 /** Frequency synthesizer calibration */
  54. #define CC1101_FSCAL2 0x24 /** Frequency synthesizer calibration */
  55. #define CC1101_FSCAL1 0x25 /** Frequency synthesizer calibration */
  56. #define CC1101_FSCAL0 0x26 /** Frequency synthesizer calibration */
  57. #define CC1101_RCCTRL1 0x27 /** RC oscillator configuration */
  58. #define CC1101_RCCTRL0 0x28 /** RC oscillator configuration */
  59. #define CC1101_FSTEST 0x29 /** Frequency synthesizer calibration control */
  60. #define CC1101_PTEST 0x2A /** Production test */
  61. #define CC1101_AGCTEST 0x2B /** AGC test */
  62. #define CC1101_TEST2 0x2C /** Various test settings */
  63. #define CC1101_TEST1 0x2D /** Various test settings */
  64. #define CC1101_TEST0 0x2E /** Various test settings */
  65. /* Strobe registers, CC1101_BURST is not available, CC1101_WRITE ignored */
  66. #define CC1101_STROBE_SRES 0x30 /** Reset chip. */
  67. #define CC1101_STROBE_SFSTXON \
  68. 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). */
  69. #define CC1101_STROBE_SXOFF 0x32 /** Turn off crystal oscillator. */
  70. #define CC1101_STROBE_SCAL \
  71. 0x33 /** Calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without setting manual calibration mode (MCSM0.FS_AUTOCAL=0) */
  72. #define CC1101_STROBE_SRX \
  73. 0x34 /** Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. */
  74. #define CC1101_STROBE_STX \
  75. 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. */
  76. #define CC1101_STROBE_SIDLE \
  77. 0x36 /** Exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable. */
  78. #define CC1101_STROBE_SWOR \
  79. 0x38 /** Start automatic RX polling sequence (Wake-on-Radio) as described in Section 19.5 if WORCTRL.RC_PD=0. */
  80. /* 0x37 is unused */
  81. #define CC1101_STROBE_SPWD 0x39 /** Enter power down mode when CSn goes high. */
  82. #define CC1101_STROBE_SFRX \
  83. 0x3A /** Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states. */
  84. #define CC1101_STROBE_SFTX \
  85. 0x3B /** Flush the TX FIFO buffer. Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states. */
  86. #define CC1101_STROBE_SWORRST 0x3C /** Reset real time clock to Event1 value. */
  87. #define CC1101_STROBE_SNOP \
  88. 0x3D /** No operation. May be used to get access to the chip status byte.*/
  89. /* Status registers, must be accessed with CC1101_BURST, but one by one */
  90. #define CC1101_STATUS_PARTNUM 0x30 /** Chip ID Part Number */
  91. #define CC1101_STATUS_VERSION 0x31 /** Chip ID Version */
  92. #define CC1101_STATUS_FREQEST 0x32 /** Frequency Offset Estimate from Demodulator */
  93. #define CC1101_STATUS_LQI 0x33 /** Demodulator Estimate for Link Quality, 7bit-CRC, 6..0-LQI*/
  94. #define CC1101_STATUS_RSSI 0x34 /** Received Signal Strength Indication */
  95. #define CC1101_STATUS_MARCSTATE 0x35 /** Main Radio Control State Machine State */
  96. #define CC1101_STATUS_WORTIME1 0x36 /** High Byte of WOR Time */
  97. #define CC1101_STATUS_WORTIME0 0x37 /** Low Byte of WOR Time */
  98. #define CC1101_STATUS_PKTSTATUS 0x38 /** Current GDOx Status and Packet Status */
  99. #define CC1101_STATUS_VCO_VC_DAC 0x39 /** Current Setting from PLL Calibration Module */
  100. #define CC1101_STATUS_TXBYTES \
  101. 0x3A /** Underflow and Number of Bytes, 7bit-Underflow, 6..0-Number of Bytes*/
  102. #define CC1101_STATUS_RXBYTES \
  103. 0x3B /** Overflow and Number of Bytes, 7bit-Overflow*, 6..0-Number of Bytes*/
  104. #define CC1101_STATUS_RCCTRL1_STATUS 0x3C /** Last RC Oscillator Calibration Result */
  105. #define CC1101_STATUS_RCCTRL0_STATUS 0x3D /** Last RC Oscillator Calibration Result */
  106. /* Some special registers, use CC1101_BURST to read/write data */
  107. #define CC1101_PATABLE \
  108. 0x3E /** PATABLE register number, an 8-byte table that defines the PA control settings */
  109. #define CC1101_FIFO \
  110. 0x3F /** FIFO register nunmber, can be combined with CC1101_WRITE and/or CC1101_BURST */
  111. #define CC1101_IOCFG_INV (1 << 6) /** IOCFG inversion */
  112. typedef enum {
  113. CC1101IocfgRxFifoThreshold = 0x00,
  114. CC1101IocfgRxFifoThresholdOrPacket = 0x01,
  115. CC1101IocfgTxFifoThreshold = 0x02,
  116. CC1101IocfgTxFifoFull = 0x03,
  117. CC1101IocfgRxOverflow = 0x04,
  118. CC1101IocfgTxUnderflow = 0x05,
  119. CC1101IocfgSyncWord = 0x06,
  120. CC1101IocfgPacket = 0x07,
  121. CC1101IocfgPreamble = 0x08,
  122. CC1101IocfgClearChannel = 0x09,
  123. CC1101IocfgLockDetector = 0x0A,
  124. CC1101IocfgSerialClock = 0x0B,
  125. CC1101IocfgSerialSynchronousDataOutput = 0x0C,
  126. CC1101IocfgSerialDataOutput = 0x0D,
  127. CC1101IocfgCarrierSense = 0x0E,
  128. CC1101IocfgCrcOk = 0x0F,
  129. /* Reserved range: 0x10 - 0x15 */
  130. CC1101IocfgRxHardData1 = 0x16,
  131. CC1101IocfgRxHardData0 = 0x17,
  132. /* Reserved range: 0x18 - 0x1A */
  133. CC1101IocfgPaPd = 0x1B,
  134. CC1101IocfgLnaPd = 0x1C,
  135. CC1101IocfgRxSymbolTick = 0x1D,
  136. /* Reserved range: 0x1E - 0x23 */
  137. CC1101IocfgWorEvnt0 = 0x24,
  138. CC1101IocfgWorEvnt1 = 0x25,
  139. CC1101IocfgClk256 = 0x26,
  140. CC1101IocfgClk32k = 0x27,
  141. /* Reserved: 0x28 */
  142. CC1101IocfgChpRdyN = 0x29,
  143. /* Reserved: 0x2A */
  144. CC1101IocfgXoscStable = 0x2B,
  145. /* Reserved range: 0x2C - 0x2D */
  146. CC1101IocfgHighImpedance = 0x2E,
  147. CC1101IocfgHW = 0x2F,
  148. /* Only one CC1101IocfgClkXoscN can be selected as an output at any time */
  149. CC1101IocfgClkXosc1 = 0x30,
  150. CC1101IocfgClkXosc1_5 = 0x31,
  151. CC1101IocfgClkXosc2 = 0x32,
  152. CC1101IocfgClkXosc3 = 0x33,
  153. CC1101IocfgClkXosc4 = 0x34,
  154. CC1101IocfgClkXosc6 = 0x35,
  155. CC1101IocfgClkXosc8 = 0x36,
  156. CC1101IocfgClkXosc12 = 0x37,
  157. CC1101IocfgClkXosc16 = 0x38,
  158. CC1101IocfgClkXosc24 = 0x39,
  159. CC1101IocfgClkXosc32 = 0x3A,
  160. CC1101IocfgClkXosc48 = 0x3B,
  161. CC1101IocfgClkXosc64 = 0x3C,
  162. CC1101IocfgClkXosc96 = 0x3D,
  163. CC1101IocfgClkXosc128 = 0x3E,
  164. CC1101IocfgClkXosc192 = 0x3F,
  165. } CC1101Iocfg;
  166. typedef enum {
  167. CC1101StateIDLE = 0b000, /** IDLE state */
  168. CC1101StateRX = 0b001, /** Receive mode */
  169. CC1101StateTX = 0b010, /** Transmit mode */
  170. CC1101StateFSTXON = 0b011, /** Fast TX ready */
  171. CC1101StateCALIBRATE = 0b100, /** Frequency synthesizer calibration is running */
  172. CC1101StateSETTLING = 0b101, /** PLL is settling */
  173. CC1101StateRXFIFO_OVERFLOW =
  174. 0b110, /** RX FIFO has overflowed. Read out any useful data, then flush the FIFO with SFRX */
  175. CC1101StateTXFIFO_UNDERFLOW = 0b111, /** TX FIFO has underflowed. Acknowledge with SFTX */
  176. } CC1101State;
  177. typedef struct {
  178. uint8_t FIFO_BYTES_AVAILABLE : 4;
  179. CC1101State STATE : 3;
  180. bool CHIP_RDYn : 1;
  181. } CC1101Status;
  182. typedef union {
  183. CC1101Status status;
  184. uint8_t status_raw;
  185. } CC1101StatusRaw;
  186. typedef struct {
  187. uint8_t NUM_TXBYTES : 7;
  188. bool TXFIFO_UNDERFLOW : 1;
  189. } CC1101TxBytes;
  190. typedef struct {
  191. uint8_t NUM_RXBYTES : 7;
  192. bool RXFIFO_OVERFLOW : 1;
  193. } CC1101RxBytes;
  194. #ifdef __cplusplus
  195. }
  196. #endif