myRadio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #ifndef __MY_RADIO_H
  2. #define __MY_RADIO_H
  3. /* Includes ------------------------------------------------------------------*/
  4. #include <stdio.h>
  5. #include <stdbool.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #define MAX_RF_PACKET_LEN 128
  9. typedef enum
  10. {
  11. RF_TX_PWR_N_7,
  12. RF_TX_PWR_N_6,
  13. RF_TX_PWR_N_5,
  14. RF_TX_PWR_N_4,
  15. RF_TX_PWR_N_3,
  16. RF_TX_PWR_N_2,
  17. RF_TX_PWR_N_1,
  18. RF_TX_PWR_P_0,
  19. RF_TX_PWR_P_1,
  20. RF_TX_PWR_P_2,
  21. RF_TX_PWR_P_3,
  22. RF_TX_PWR_P_4,
  23. RF_TX_PWR_P_5,
  24. RF_TX_PWR_P_6,
  25. RF_TX_PWR_P_7,
  26. RF_TX_PWR_P_8,
  27. RF_TX_PWR_P_9,
  28. RF_TX_PWR_P_10,
  29. RF_TX_PWR_P_11,
  30. RF_TX_PWR_P_12,
  31. RF_TX_PWR_P_13,
  32. RF_TX_PWR_P_14,
  33. RF_TX_PWR_P_15,
  34. RF_TX_PWR_P_16,
  35. RF_TX_PWR_P_17,
  36. RF_TX_PWR_P_18,
  37. RF_TX_PWR_P_19,
  38. RF_TX_PWR_P_20,
  39. RF_TX_PWR_MAX_COUNT,
  40. }rf_txPwr_te;
  41. typedef enum
  42. {
  43. DVTP_SI4438_C2A_433,
  44. DVTP_SI4438_C2A_490,
  45. DVTP_SI4463_C2A_433,
  46. DVTP_SI4463_C2A_490,
  47. DVTP_SI4463_C2A_868,
  48. DVTP_SI4463_C2A_915,
  49. DVTP_SI4438_B1C_433,
  50. DVTP_SI4438_B1C_490,
  51. DVTP_SI4463_B1B_433,
  52. DVTP_SI4463_B1B_868,
  53. DVTP_SI4463_B1B_915,
  54. DVTP_CUSTTOM,
  55. DVTP_MAX_COUNT,
  56. }deviceType_te;
  57. typedef enum
  58. {
  59. RF_BAUDRATE_10000, //
  60. MAX_RF_BAUDRATE_COUNT, //
  61. }rfBaudrate_te;
  62. typedef enum
  63. {
  64. FREQ_BAND_315,
  65. FREQ_BAND_433,
  66. FREQ_BAND_490,
  67. FREQ_BAND_868,
  68. FREQ_BAND_915,
  69. MAX_FREQ_BAND_COUNT,
  70. }freqBand_te;
  71. typedef union
  72. {
  73. uint8_t regValue;
  74. struct
  75. {
  76. /** bit0
  77. * ...
  78. * bit7 */
  79. uint8_t GPIO_MODE : 6; //Selects the level of drive strength for those GPIO/NIRQ/SDO pins configured as outputs.
  80. // The selected level of drive strength is applied simultaneously to all output pins, with
  81. // the following exception: GPIO0 will exhibit a weaker drive strength than the other GPIO pins
  82. // but only in the lowest drive strength setting; its drive strength is the same for all other settings.
  83. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_GPIO_GPIO_MODE_ENUM_DONOTHING
  84. uint8_t PULL_CTL : 1; //The pin pull-up control.
  85. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_GPIO_PULL_CTL_ENUM_PULL_DIS
  86. uint8_t RESERVER : 1; //
  87. }unit;
  88. }gpio_pin_cfg_tu;
  89. typedef union
  90. {
  91. uint8_t regValue;
  92. struct
  93. {
  94. /** bit0
  95. * ...
  96. * bit7 */
  97. uint8_t NIRQ_MODE : 6; //Selects the level of drive strength for those GPIO/NIRQ/SDO pins configured as outputs.
  98. // The selected level of drive strength is applied simultaneously to all output pins, with
  99. // the following exception: GPIO0 will exhibit a weaker drive strength than the other GPIO pins
  100. // but only in the lowest drive strength setting; its drive strength is the same for all other settings.
  101. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_NIRQ_NIRQ_MODE_ENUM_DONOTHING
  102. uint8_t PULL_CTL : 1; //The pin pull-up control.
  103. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_NIRQ_PULL_CTL_ENUM_PULL_DIS
  104. uint8_t RESERVER : 1; //
  105. }unit;
  106. }nirq_pin_cfg_tu;
  107. typedef union
  108. {
  109. uint8_t regValue;
  110. struct
  111. {
  112. /** bit0
  113. * ...
  114. * bit7 */
  115. uint8_t SDO_MODE : 6; //Selects the level of drive strength for those GPIO/NIRQ/SDO pins configured as outputs.
  116. // The selected level of drive strength is applied simultaneously to all output pins, with
  117. // the following exception: GPIO0 will exhibit a weaker drive strength than the other GPIO pins
  118. // but only in the lowest drive strength setting; its drive strength is the same for all other settings.
  119. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_SDO_SDO_MODE_ENUM_DONOTHING
  120. uint8_t PULL_CTL : 1; //The pin pull-up control.
  121. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_SDO_PULL_CTL_ENUM_PULL_DIS
  122. uint8_t RESERVER : 1; //
  123. }unit;
  124. }sdo_pin_cfg_tu;
  125. typedef union
  126. {
  127. uint8_t regValue;
  128. struct
  129. {
  130. /** bit0
  131. * ...
  132. * bit7 */
  133. uint8_t RESERVER1 : 5; //
  134. uint8_t DRV_STRENGTH : 2; //Reads back the enumeration of the currently selected drive strength.
  135. //@ SI446X_CMD_GPIO_PIN_CFG_ARG_GEN_CONFIG_DRV_STRENGTH_ENUM_HIGH
  136. uint8_t RESERVER2 : 1; //
  137. }unit;
  138. }gen_config_tu;
  139. typedef union
  140. {
  141. uint8_t regValue;
  142. struct
  143. {
  144. /** bit0
  145. * ...
  146. * bit7 */
  147. uint8_t DST_FIELD : 3;
  148. uint8_t IN_FIFO : 1;
  149. uint8_t SIZE : 1;
  150. uint8_t ENDIAN : 1;
  151. uint8_t INFINITE_LEN : 1;
  152. uint8_t RESERVER : 1;
  153. }unit;
  154. }pkt_len_tu;
  155. typedef union
  156. {
  157. uint8_t regValue;
  158. struct
  159. {
  160. /** bit0
  161. * ...
  162. * bit7 */
  163. uint8_t SRC_FIELD : 1;
  164. uint8_t RESERVER : 7;
  165. }unit;
  166. }pkt_len_field_source_tu;
  167. typedef enum
  168. {
  169. MODTPE_CW,
  170. MODTPE_OOK,
  171. MODTPE_2FSK,
  172. MODTPE_2GFSK,
  173. MODTPE_4FSK,
  174. MODTPE_4GFSK,
  175. }mod_type_te;
  176. typedef enum
  177. {
  178. MODSRC_PACKET, //The modulation is sourced from the TX FIFO in the packet handler.
  179. MODSRC_DIRECT, //The modulation is sourced in real-time (i.e., TX Direct Mode) from a GPIO pin, as selected by the TX_DIRECT_MODE_GPIO field.
  180. MODSRC_PSEUDO, //The modulation is sourced from the internal pseudo-random generator.
  181. }mod_sourse_te;
  182. typedef enum
  183. {
  184. MODGPIO_GPIO0, //TX direct mode uses GPIO0 as data source.
  185. MODGPIO_GPIO1, //TX direct mode uses GPIO1 as data source.
  186. MODGPIO_GPIO2, //TX direct mode uses GPIO2 as data source.
  187. MODGPIO_GPIO3, //TX direct mode uses GPIO3 as data source.
  188. }mod_gpio_te;
  189. typedef enum
  190. {
  191. DRCTMODTY_SYNC, //Direct mode operates in synchronous mode, applies to TX only.
  192. DRCTMODTY_ASYNC, //Direct mode operates in asynchronous mode, applies to TX only. GFSK is not supported.
  193. }direct_mode_type_te;
  194. typedef union
  195. {
  196. uint8_t regValue;
  197. struct
  198. {
  199. /** bit0
  200. * ...
  201. * bit7 */
  202. mod_type_te MOD_TYPE : 3;//This field configures the Modem for transmission or reception of the desired type of modulation.
  203. // With the exception of CW mode (a TX-only function), this bit is applicable in both TX and RX modes.
  204. mod_sourse_te MOD_SOURCE : 2; //This bit selects the source of modulation during TX mode. It is applicable only in TX mode.
  205. mod_gpio_te TX_DIRECT_MODE_GPIO : 2; //This field determines which GPIO pin is selected by the Modem as the modulation data source during TX Direct mode. This bit is applicable only in TX mode, and only when the MOD_SOURCE field is also set for TX Direct mode.
  206. // This field does not automatically configure the selected GPIO pin as a digital input pin; it remains necessary to additionally configure the desired GPIO pin as a CMOS-compatible input pin by setting GPIO_PIN_CFG=0x04.
  207. direct_mode_type_te TX_DIRECT_MODE_TYPE : 1; //This bit determines whether a real-time TX data stream (applied to the chip on a selected GPIO input pin) is processed in synchronous or asynchronous fashion. This bit is applicable only in TX mode, and only when the MOD_SOURCE field is also set for TX Direct mode.
  208. // In TX Direct Synchronous mode, the chip controls the transmit data rate by outputting a TX bit clock (GPIO_PIN_CFG=0x10). The host MCU receives the rising edge of the TX clock and responds by outputting one bit for each clock tick; the chip clocks in this new data bit on the subsequent falling edge of the TX clock. All 2-level modulation modes (OOK, 2FSK, 2GFSK) are supported.
  209. // In TX Direct Asynchronous mode, the host MCU controls the transmit data rate; the RFIC has no knowledge of the rate of the incoming TX data stream but simply oversamples the data as fast as possible to determine the bit edge transitions. OOK and 2FSK are supported, but 2GFSK is not supported in this mode.
  210. // 4(G)FSK is not supported in either TX Direct Synchronous or TX Direct Asynchronous modes
  211. }unit;
  212. }prop_modem_mod_type_tu;
  213. typedef union
  214. {
  215. uint8_t regValue;
  216. struct
  217. {
  218. /** bit0
  219. * ...
  220. * bit7 */
  221. uint8_t PH_FIELD_SPLIT : 1;
  222. uint8_t PH_RX_DISABLE : 1;
  223. uint8_t _4FSK_EN : 1;
  224. uint8_t RESERVER : 1;
  225. uint8_t MANCH_POL : 1;
  226. uint8_t CRC_INVERT : 1;
  227. uint8_t CRC_ENDIAN : 1;
  228. uint8_t BIT_ORDER : 1;
  229. }unit;
  230. }pkt_config1_tu;
  231. //! \brief Structure for the TX Packet
  232. typedef struct
  233. {
  234. uint8_t rmvAddr[8]; //
  235. uint32_t absTime; //
  236. uint8_t len; //
  237. uint8_t payload[MAX_RF_PACKET_LEN]; //
  238. } rfTxPacket_ts;
  239. typedef struct
  240. {
  241. uint8_t rmvAddr[8]; //
  242. int16_t rssi; //
  243. uint32_t absTime; //
  244. uint32_t rxTimeout; //
  245. uint8_t len; //
  246. uint8_t payload[MAX_RF_PACKET_LEN];
  247. } rfRxPacket_ts;
  248. typedef struct
  249. {
  250. uint8_t SignalBw; // LORA [0: 7.8 kHz, 1: 10.4 kHz, 2: 15.6 kHz, 3: 20.8 kHz, 4: 31.2 kHz,
  251. // 5: 41.6 kHz, 6: 62.5 kHz, 7: 125 kHz, 8: 250 kHz, 9: 500 kHz, other: Reserved]
  252. uint8_t SpreadingFactor; // LORA [6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips]
  253. uint8_t ErrorCoding; // LORA [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  254. }loraBaudrateFrame_ts;
  255. typedef enum
  256. {
  257. RADIO_EXT_CONTROL_TX_UNMODULATED, //µ¥Ôز¨¹¦ÂʲâÊÔ
  258. RADIO_EXT_CONTROL_RX_SENSITIVITY, //½ÓÊÕÁéÃô¶È²âÊÔ
  259. RADIO_EXT_CONTROL_TX_MODULATED, //Á¬Ðøµ÷ÖƲâÊÔ
  260. }controlMode_te;
  261. typedef enum
  262. {
  263. RX_STA_SECCESS,
  264. RX_STA_TIMEOUT,
  265. RX_STA_PAYLOAD_ERROR,
  266. TX_STA_SECCESS,
  267. TX_STA_ERROR,
  268. }rxStatus_te;
  269. typedef void (*rfRxCallBack)(uint8_t status, rfRxPacket_ts packet);
  270. void myRadio_init(int agr0, void *agr1_ptr);
  271. void myRadio_abort(void);
  272. uint32_t myRadio_getFrequency(void);
  273. void myRadio_setFrequency(uint32_t freq);
  274. int8_t myRadio_getTxPower(void);
  275. void myRadio_setTxPower(int8_t power);
  276. uint32_t myRadio_getBaudrate(void);
  277. void myRadio_setBaudrate(uint32_t br);
  278. void myRadio_setChipType(uint8_t type);
  279. uint8_t myRadio_getChipType(void);
  280. int16_t myRadio_getRssi(void);
  281. void myRadio_transmit(rfTxPacket_ts *packet);
  282. void myRadio_receiver(void);
  283. void myRadio_setCtrl(controlMode_te mode, uint32_t value);
  284. #endif