sx1280.h 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. /*
  2. ______ _
  3. / _____) _ | |
  4. ( (____ _____ ____ _| |_ _____ ____| |__
  5. \____ \| ___ | (_ _) ___ |/ ___) _ \
  6. _____) ) ____| | | || |_| ____( (___| | | |
  7. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  8. (C)2016 Semtech
  9. Description: Driver for SX1280 devices
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. Maintainer: Miguel Luis, Gregory Cristian and Matthieu Verdy
  12. */
  13. #ifndef __SX1280_H__
  14. #define __SX1280_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include <math.h>
  18. /*!
  19. * \brief Enables/disables driver debug features
  20. */
  21. #define SX1280_DEBUG 0
  22. /*!
  23. * \brief Hardware IO IRQ callback function definition
  24. */
  25. typedef void ( DioIrqHandler )( void );
  26. /*!
  27. * \brief Provides the frequency of the chip running on the radio and the frequency step
  28. *
  29. * \remark These defines are used for computing the frequency divider to set the RF frequency
  30. */
  31. #define XTAL_FREQ 52000000
  32. #define FREQ_STEP ( ( double )( XTAL_FREQ / pow( 2.0, 18.0 ) ) )
  33. /*!
  34. * \brief Compensation delay for SetAutoTx/Rx functions in microseconds
  35. */
  36. #define AUTO_RX_TX_OFFSET 33
  37. /*!
  38. * \brief The address of the register holding the firmware version MSB
  39. */
  40. #define REG_LR_FIRMWARE_VERSION_MSB 0x0153
  41. /*!
  42. * \brief The address of the register holding the first byte defining the CRC seed
  43. *
  44. * \remark Only used for packet types GFSK and Flrc
  45. */
  46. #define REG_LR_CRCSEEDBASEADDR 0x09C8
  47. /*!
  48. * \brief The address of the register holding the first byte defining the CRC polynomial
  49. *
  50. * \remark Only used for packet types GFSK and Flrc
  51. */
  52. #define REG_LR_CRCPOLYBASEADDR 0x09C6
  53. /*!
  54. * \brief The address of the register holding the first byte defining the whitening seed
  55. *
  56. * \remark Only used for packet types GFSK, FLRC and BLE
  57. */
  58. #define REG_LR_WHITSEEDBASEADDR 0x09C5
  59. /*!
  60. * \brief The address of the register holding the ranging id check length
  61. *
  62. * \remark Only used for packet type Ranging
  63. */
  64. #define REG_LR_RANGINGIDCHECKLENGTH 0x0931
  65. /*!
  66. * \brief The address of the register holding the device ranging id
  67. *
  68. * \remark Only used for packet type Ranging
  69. */
  70. #define REG_LR_DEVICERANGINGADDR 0x0916
  71. /*!
  72. * \brief The address of the register holding the device ranging id
  73. *
  74. * \remark Only used for packet type Ranging
  75. */
  76. #define REG_LR_REQUESTRANGINGADDR 0x0912
  77. /*!
  78. * \brief The address of the register holding ranging results configuration
  79. * and the corresponding mask
  80. *
  81. * \remark Only used for packet type Ranging
  82. */
  83. #define REG_LR_RANGINGRESULTCONFIG 0x0924
  84. #define MASK_RANGINGMUXSEL 0xCF
  85. /*!
  86. * \brief The address of the register holding the first byte of ranging results
  87. * Only used for packet type Ranging
  88. */
  89. #define REG_LR_RANGINGRESULTBASEADDR 0x0961
  90. /*!
  91. * \brief The address of the register allowing to read ranging results
  92. *
  93. * \remark Only used for packet type Ranging
  94. */
  95. #define REG_LR_RANGINGRESULTSFREEZE 0x097F
  96. /*!
  97. * \brief The address of the register holding the first byte of ranging calibration
  98. *
  99. * \remark Only used for packet type Ranging
  100. */
  101. #define REG_LR_RANGINGRERXTXDELAYCAL 0x092C
  102. /*!
  103. *\brief The address of the register holding the ranging filter window size
  104. *
  105. * \remark Only used for packet type Ranging
  106. */
  107. #define REG_LR_RANGINGFILTERWINDOWSIZE 0x091E
  108. /*!
  109. *\brief The address of the register to reset for clearing ranging filter
  110. *
  111. * \remark Only used for packet type Ranging
  112. */
  113. #define REG_LR_RANGINGRESULTCLEARREG 0x0923
  114. /*!
  115. * \brief The default number of samples considered in built-in ranging filter
  116. */
  117. #define DEFAULT_RANGING_FILTER_SIZE 127
  118. /*!
  119. * \brief The address of the register holding LORA packet parameters
  120. */
  121. #define REG_LR_PACKETPARAMS 0x903
  122. /*!
  123. * \brief The address of the register holding payload length
  124. *
  125. * \remark Do NOT try to read it directly. Use GetRxBuffer( ) instead.
  126. */
  127. #define REG_LR_PAYLOADLENGTH 0x901
  128. /*!
  129. * \brief The address of the instruction RAM and its size
  130. */
  131. #define IRAM_START_ADDRESS 0x8000
  132. #define IRAM_SIZE 0x4000
  133. /*!
  134. * \brief The addresses of the registers holding SyncWords values
  135. *
  136. * \remark The addresses depends on the Packet Type in use, and not all
  137. * SyncWords are available for every Packet Type
  138. */
  139. #define REG_LR_SYNCWORDBASEADDRESS1 0x09CE
  140. #define REG_LR_SYNCWORDBASEADDRESS2 0x09D3
  141. #define REG_LR_SYNCWORDBASEADDRESS3 0x09D8
  142. /*!
  143. * \brief The MSB address and mask used to read the estimated frequency
  144. * error
  145. */
  146. #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MSB 0x0954
  147. #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MASK 0x0FFFFF
  148. /*!
  149. * \brief Defines how many bit errors are tolerated in sync word detection
  150. */
  151. #define REG_LR_SYNCWORDTOLERANCE 0x09CD
  152. /*!
  153. * \brief Register for MSB Access Address (BLE)
  154. */
  155. #define REG_LR_BLE_ACCESS_ADDRESS 0x09CF
  156. #define BLE_ADVERTIZER_ACCESS_ADDRESS 0x8E89BED6
  157. /*!
  158. * \brief Structure describing the radio status
  159. */
  160. typedef union
  161. {
  162. /*!
  163. * \brief Structure of the radio status
  164. */
  165. struct
  166. {
  167. uint8_t CpuBusy : 1; //!< Flag for CPU radio busy
  168. uint8_t DmaBusy : 1; //!< Flag for DMA busy
  169. uint8_t CmdStatus : 3; //!< Command status
  170. uint8_t ChipMode : 3; //!< Chip mode
  171. }Fields;
  172. /*!
  173. * \brief Serialized radio status
  174. */
  175. uint8_t Value;
  176. }RadioStatus_t;
  177. /*!
  178. * \brief Represents the states of the radio
  179. */
  180. typedef enum
  181. {
  182. RF_IDLE = 0x00, //!< The radio is idle
  183. RF_RX_RUNNING, //!< The radio is in reception state
  184. RF_TX_RUNNING, //!< The radio is in transmission state
  185. RF_CAD, //!< The radio is doing channel activity detection
  186. }RadioStates_t;
  187. /*!
  188. * \brief Represents the operating mode the radio is actually running
  189. */
  190. typedef enum
  191. {
  192. MODE_SLEEP = 0x00, //! The radio is in sleep mode
  193. MODE_STDBY_RC, //! The radio is in standby mode with RC oscillator
  194. MODE_STDBY_XOSC, //! The radio is in standby mode with XOSC oscillator
  195. MODE_FS, //! The radio is in frequency synthesis mode
  196. MODE_TX, //! The radio is in transmit mode
  197. MODE_RX, //! The radio is in receive mode
  198. MODE_CAD //! The radio is in channel activity detection mode
  199. }RadioOperatingModes_t;
  200. /*!
  201. * \brief Declares the oscillator in use while in standby mode
  202. *
  203. * Using the STDBY_RC standby mode allow to reduce the energy consumption
  204. * STDBY_XOSC should be used for time critical applications
  205. */
  206. typedef enum
  207. {
  208. STDBY_RC = 0x00,
  209. STDBY_XOSC = 0x01,
  210. }RadioStandbyModes_t;
  211. /*!
  212. * \brief Declares the power regulation used to power the device
  213. *
  214. * This command allows the user to specify if DC-DC or LDO is used for power regulation.
  215. * Using only LDO implies that the Rx or Tx current is doubled
  216. */
  217. typedef enum
  218. {
  219. USE_LDO = 0x00, //! Use LDO (default value)
  220. USE_DCDC = 0x01, //! Use DCDC
  221. }RadioRegulatorModes_t;
  222. /*!
  223. * \brief Represents the possible packet type (i.e. modem) used
  224. */
  225. typedef enum
  226. {
  227. PACKET_TYPE_GFSK = 0x00,
  228. PACKET_TYPE_LORA,
  229. PACKET_TYPE_RANGING,
  230. PACKET_TYPE_FLRC,
  231. PACKET_TYPE_BLE,
  232. PACKET_TYPE_NONE = 0x0F,
  233. }RadioPacketTypes_t;
  234. /*!
  235. * \brief Represents the ramping time for power amplifier
  236. */
  237. typedef enum
  238. {
  239. RADIO_RAMP_02_US = 0x00,
  240. RADIO_RAMP_04_US = 0x20,
  241. RADIO_RAMP_06_US = 0x40,
  242. RADIO_RAMP_08_US = 0x60,
  243. RADIO_RAMP_10_US = 0x80,
  244. RADIO_RAMP_12_US = 0xA0,
  245. RADIO_RAMP_16_US = 0xC0,
  246. RADIO_RAMP_20_US = 0xE0,
  247. }RadioRampTimes_t;
  248. /*!
  249. * \brief Represents the number of symbols to be used for channel activity detection operation
  250. */
  251. typedef enum
  252. {
  253. LORA_CAD_01_SYMBOL = 0x00,
  254. LORA_CAD_02_SYMBOL = 0x20,
  255. LORA_CAD_04_SYMBOL = 0x40,
  256. LORA_CAD_08_SYMBOL = 0x60,
  257. LORA_CAD_16_SYMBOL = 0x80,
  258. }RadioLoRaCadSymbols_t;
  259. /*!
  260. * \brief Represents the possible combinations of bitrate and bandwidth for
  261. * GFSK and BLE packet types
  262. *
  263. * The bitrate is expressed in Mb/s and the bandwidth in MHz
  264. */
  265. typedef enum
  266. {
  267. GFS_BLE_BR_2_000_BW_2_4 = 0x04,
  268. GFS_BLE_BR_1_600_BW_2_4 = 0x28,
  269. GFS_BLE_BR_1_000_BW_2_4 = 0x4C,
  270. GFS_BLE_BR_1_000_BW_1_2 = 0x45,
  271. GFS_BLE_BR_0_800_BW_2_4 = 0x70,
  272. GFS_BLE_BR_0_800_BW_1_2 = 0x69,
  273. GFS_BLE_BR_0_500_BW_1_2 = 0x8D,
  274. GFS_BLE_BR_0_500_BW_0_6 = 0x86,
  275. GFS_BLE_BR_0_400_BW_1_2 = 0xB1,
  276. GFS_BLE_BR_0_400_BW_0_6 = 0xAA,
  277. GFS_BLE_BR_0_250_BW_0_6 = 0xCE,
  278. GFS_BLE_BR_0_250_BW_0_3 = 0xC7,
  279. GFS_BLE_BR_0_125_BW_0_3 = 0xEF,
  280. }RadioGfskBleBitrates_t;
  281. /*!
  282. * \brief Represents the modulation index used in GFSK and BLE packet
  283. * types
  284. */
  285. typedef enum
  286. {
  287. GFS_BLE_MOD_IND_0_35 = 0,
  288. GFS_BLE_MOD_IND_0_50 = 1,
  289. GFS_BLE_MOD_IND_0_75 = 2,
  290. GFS_BLE_MOD_IND_1_00 = 3,
  291. GFS_BLE_MOD_IND_1_25 = 4,
  292. GFS_BLE_MOD_IND_1_50 = 5,
  293. GFS_BLE_MOD_IND_1_75 = 6,
  294. GFS_BLE_MOD_IND_2_00 = 7,
  295. GFS_BLE_MOD_IND_2_25 = 8,
  296. GFS_BLE_MOD_IND_2_50 = 9,
  297. GFS_BLE_MOD_IND_2_75 = 10,
  298. GFS_BLE_MOD_IND_3_00 = 11,
  299. GFS_BLE_MOD_IND_3_25 = 12,
  300. GFS_BLE_MOD_IND_3_50 = 13,
  301. GFS_BLE_MOD_IND_3_75 = 14,
  302. GFS_BLE_MOD_IND_4_00 = 15,
  303. }RadioGfskBleModIndexes_t;
  304. /*!
  305. * \brief Represents the possible combination of bitrate and bandwidth for FLRC
  306. * packet type
  307. *
  308. * The bitrate is in Mb/s and the bitrate in MHz
  309. */
  310. typedef enum
  311. {
  312. FLRC_BR_2_600_BW_2_4 = 0x04,
  313. FLRC_BR_2_080_BW_2_4 = 0x28,
  314. FLRC_BR_1_300_BW_1_2 = 0x45,
  315. FLRC_BR_1_040_BW_1_2 = 0x69,
  316. FLRC_BR_0_650_BW_0_6 = 0x86,
  317. FLRC_BR_0_520_BW_0_6 = 0xAA,
  318. FLRC_BR_0_325_BW_0_3 = 0xC7,
  319. FLRC_BR_0_260_BW_0_3 = 0xEB,
  320. }RadioFlrcBitrates_t;
  321. /*!
  322. * \brief Represents the possible values for coding rate parameter in FLRC
  323. * packet type
  324. */
  325. typedef enum
  326. {
  327. FLRC_CR_1_2 = 0x00,
  328. FLRC_CR_3_4 = 0x02,
  329. FLRC_CR_1_0 = 0x04,
  330. }RadioFlrcCodingRates_t;
  331. /*!
  332. * \brief Represents the modulation shaping parameter for GFSK, FLRC and BLE
  333. * packet types
  334. */
  335. typedef enum
  336. {
  337. RADIO_MOD_SHAPING_BT_OFF = 0x00, //! No filtering
  338. RADIO_MOD_SHAPING_BT_1_0 = 0x10,
  339. RADIO_MOD_SHAPING_BT_0_5 = 0x20,
  340. }RadioModShapings_t;
  341. /*!
  342. * \brief Represents the possible spreading factor values in LORA packet types
  343. */
  344. typedef enum
  345. {
  346. LORA_SF5 = 0x50,
  347. LORA_SF6 = 0x60,
  348. LORA_SF7 = 0x70,
  349. LORA_SF8 = 0x80,
  350. LORA_SF9 = 0x90,
  351. LORA_SF10 = 0xA0,
  352. LORA_SF11 = 0xB0,
  353. LORA_SF12 = 0xC0,
  354. }RadioLoRaSpreadingFactors_t;
  355. /*!
  356. * \brief Represents the bandwidth values for LORA packet type
  357. */
  358. typedef enum
  359. {
  360. LORA_BW_0200 = 0x34,
  361. LORA_BW_0400 = 0x26,
  362. LORA_BW_0800 = 0x18,
  363. LORA_BW_1600 = 0x0A,
  364. }RadioLoRaBandwidths_t;
  365. /*!
  366. * \brief Represents the coding rate values for LORA packet type
  367. */
  368. typedef enum
  369. {
  370. LORA_CR_4_5 = 0x01,
  371. LORA_CR_4_6 = 0x02,
  372. LORA_CR_4_7 = 0x03,
  373. LORA_CR_4_8 = 0x04,
  374. LORA_CR_LI_4_5 = 0x05,
  375. LORA_CR_LI_4_6 = 0x06,
  376. LORA_CR_LI_4_7 = 0x07,
  377. }RadioLoRaCodingRates_t;
  378. /*!
  379. * \brief Represents the preamble length values for GFSK and FLRC packet
  380. * types
  381. */
  382. typedef enum
  383. {
  384. PREAMBLE_LENGTH_04_BITS = 0x00, //!< Preamble length: 04 bits
  385. PREAMBLE_LENGTH_08_BITS = 0x10, //!< Preamble length: 08 bits
  386. PREAMBLE_LENGTH_12_BITS = 0x20, //!< Preamble length: 12 bits
  387. PREAMBLE_LENGTH_16_BITS = 0x30, //!< Preamble length: 16 bits
  388. PREAMBLE_LENGTH_20_BITS = 0x40, //!< Preamble length: 20 bits
  389. PREAMBLE_LENGTH_24_BITS = 0x50, //!< Preamble length: 24 bits
  390. PREAMBLE_LENGTH_28_BITS = 0x60, //!< Preamble length: 28 bits
  391. PREAMBLE_LENGTH_32_BITS = 0x70, //!< Preamble length: 32 bits
  392. }RadioPreambleLengths_t;
  393. /*!
  394. * \brief Represents the SyncWord length for FLRC packet type
  395. */
  396. typedef enum
  397. {
  398. FLRC_NO_SYNCWORD = 0x00,
  399. FLRC_SYNCWORD_LENGTH_4_BYTE = 0x04,
  400. }RadioFlrcSyncWordLengths_t;
  401. /*!
  402. * \brief The length of sync words for GFSK packet type
  403. */
  404. typedef enum
  405. {
  406. GFS_SYNCWORD_LENGTH_1_BYTE = 0x00, //!< Sync word length: 1 byte
  407. GFS_SYNCWORD_LENGTH_2_BYTE = 0x02, //!< Sync word length: 2 bytes
  408. GFS_SYNCWORD_LENGTH_3_BYTE = 0x04, //!< Sync word length: 3 bytes
  409. GFS_SYNCWORD_LENGTH_4_BYTE = 0x06, //!< Sync word length: 4 bytes
  410. GFS_SYNCWORD_LENGTH_5_BYTE = 0x08, //!< Sync word length: 5 bytes
  411. }RadioSyncWordLengths_t;
  412. /*!
  413. * \brief Represents the possible combinations of SyncWord correlators
  414. * activated for GFSK and FLRC packet types
  415. */
  416. typedef enum
  417. {
  418. RADIO_RX_MATCH_SYNCWORD_OFF = 0x00, //!< No correlator turned on, i.e. do not search for SyncWord
  419. RADIO_RX_MATCH_SYNCWORD_1 = 0x10,
  420. RADIO_RX_MATCH_SYNCWORD_2 = 0x20,
  421. RADIO_RX_MATCH_SYNCWORD_1_2 = 0x30,
  422. RADIO_RX_MATCH_SYNCWORD_3 = 0x40,
  423. RADIO_RX_MATCH_SYNCWORD_1_3 = 0x50,
  424. RADIO_RX_MATCH_SYNCWORD_2_3 = 0x60,
  425. RADIO_RX_MATCH_SYNCWORD_1_2_3 = 0x70,
  426. }RadioSyncWordRxMatchs_t;
  427. /*!
  428. * \brief Radio packet length mode for GFSK and FLRC packet types
  429. */
  430. typedef enum
  431. {
  432. RADIO_PACKET_FIXED_LENGTH = 0x00, //!< The packet is known on both sides, no header included in the packet
  433. RADIO_PACKET_VARIABLE_LENGTH = 0x20, //!< The packet is on variable size, header included
  434. }RadioPacketLengthModes_t;
  435. /*!
  436. * \brief Represents the CRC length for GFSK and FLRC packet types
  437. *
  438. * \warning Not all configurations are available for both GFSK and FLRC
  439. * packet type. Refer to the datasheet for possible configuration.
  440. */
  441. typedef enum
  442. {
  443. RADIO_CRC_OFF = 0x00, //!< No CRC in use
  444. RADIO_CRC_1_BYTES = 0x10,
  445. RADIO_CRC_2_BYTES = 0x20,
  446. RADIO_CRC_3_BYTES = 0x30,
  447. }RadioCrcTypes_t;
  448. /*!
  449. * \brief Radio whitening mode activated or deactivated for GFSK, FLRC and
  450. * BLE packet types
  451. */
  452. typedef enum
  453. {
  454. RADIO_WHITENING_ON = 0x00,
  455. RADIO_WHITENING_OFF = 0x08,
  456. }RadioWhiteningModes_t;
  457. /*!
  458. * \brief Holds the packet length mode of a LORA packet type
  459. */
  460. typedef enum
  461. {
  462. LORA_PACKET_VARIABLE_LENGTH = 0x00, //!< The packet is on variable size, header included
  463. LORA_PACKET_FIXED_LENGTH = 0x80, //!< The packet is known on both sides, no header included in the packet
  464. LORA_PACKET_EXPLICIT = LORA_PACKET_VARIABLE_LENGTH,
  465. LORA_PACKET_IMPLICIT = LORA_PACKET_FIXED_LENGTH,
  466. }RadioLoRaPacketLengthsModes_t;
  467. /*!
  468. * \brief Represents the CRC mode for LORA packet type
  469. */
  470. typedef enum
  471. {
  472. LORA_CRC_ON = 0x20, //!< CRC activated
  473. LORA_CRC_OFF = 0x00, //!< CRC not used
  474. }RadioLoRaCrcModes_t;
  475. /*!
  476. * \brief Represents the IQ mode for LORA packet type
  477. */
  478. typedef enum
  479. {
  480. LORA_IQ_NORMAL = 0x40,
  481. LORA_IQ_INVERTED = 0x00,
  482. }RadioLoRaIQModes_t;
  483. /*!
  484. * \brief Represents the length of the ID to check in ranging operation
  485. */
  486. typedef enum
  487. {
  488. RANGING_IDCHECK_LENGTH_08_BITS = 0x00,
  489. RANGING_IDCHECK_LENGTH_16_BITS,
  490. RANGING_IDCHECK_LENGTH_24_BITS,
  491. RANGING_IDCHECK_LENGTH_32_BITS,
  492. }RadioRangingIdCheckLengths_t;
  493. /*!
  494. * \brief Represents the result type to be used in ranging operation
  495. */
  496. typedef enum
  497. {
  498. RANGING_RESULT_RAW = 0x00,
  499. RANGING_RESULT_AVERAGED = 0x01,
  500. RANGING_RESULT_DEBIASED = 0x02,
  501. RANGING_RESULT_FILTERED = 0x03,
  502. }RadioRangingResultTypes_t;
  503. /*!
  504. * \brief Represents the connection state for BLE packet type
  505. */
  506. typedef enum
  507. {
  508. BLE_MASTER_SLAVE = 0x00,
  509. BLE_ADVERTISER = 0x20,
  510. BLE_TX_TEST_MODE = 0x40,
  511. BLE_RX_TEST_MODE = 0x60,
  512. BLE_RXTX_TEST_MODE = 0x80,
  513. }RadioBleConnectionStates_t;
  514. /*!
  515. * \brief Represents the CRC field length for BLE packet type
  516. */
  517. typedef enum
  518. {
  519. BLE_CRC_OFF = 0x00,
  520. BLE_CRC_3B = 0x10,
  521. }RadioBleCrcFields_t;
  522. /*!
  523. * \brief Represents the specific packets to use in BLE packet type
  524. */
  525. typedef enum
  526. {
  527. BLE_PRBS_9 = 0x00, //!< Pseudo Random Binary Sequence based on 9th degree polynomial
  528. BLE_PRBS_15 = 0x0C, //!< Pseudo Random Binary Sequence based on 15th degree polynomial
  529. BLE_EYELONG_1_0 = 0x04, //!< Repeated '11110000' sequence
  530. BLE_EYELONG_0_1 = 0x18, //!< Repeated '00001111' sequence
  531. BLE_EYESHORT_1_0 = 0x08, //!< Repeated '10101010' sequence
  532. BLE_EYESHORT_0_1 = 0x1C, //!< Repeated '01010101' sequence
  533. BLE_ALL_1 = 0x10, //!< Repeated '11111111' sequence
  534. BLE_ALL_0 = 0x14, //!< Repeated '00000000' sequence
  535. }RadioBlePacketTypes_t;
  536. /*!
  537. * \brief Represents the interruption masks available for the radio
  538. *
  539. * \remark Note that not all these interruptions are available for all packet types
  540. */
  541. typedef enum
  542. {
  543. IRQ_RADIO_NONE = 0x0000,
  544. IRQ_TX_DONE = 0x0001,
  545. IRQ_RX_DONE = 0x0002,
  546. IRQ_SYNCWORD_VALID = 0x0004,
  547. IRQ_SYNCWORD_ERROR = 0x0008,
  548. IRQ_HEADER_VALID = 0x0010,
  549. IRQ_HEADER_ERROR = 0x0020,
  550. IRQ_CRC_ERROR = 0x0040,
  551. IRQ_RANGING_SLAVE_RESPONSE_DONE = 0x0080,
  552. IRQ_RANGING_SLAVE_REQUEST_DISCARDED = 0x0100,
  553. IRQ_RANGING_MASTER_RESULT_VALID = 0x0200,
  554. IRQ_RANGING_MASTER_RESULT_TIMEOUT = 0x0400,
  555. IRQ_RANGING_SLAVE_REQUEST_VALID = 0x0800,
  556. IRQ_CAD_DONE = 0x1000,
  557. IRQ_CAD_ACTIVITY_DETECTED = 0x2000,
  558. IRQ_RX_TX_TIMEOUT = 0x4000,
  559. IRQ_PREAMBLE_DETECTED = 0x8000,
  560. IRQ_RADIO_ALL = 0xFFFF,
  561. }RadioIrqMasks_t;
  562. /*!
  563. * \brief Represents the digital input/output of the radio
  564. */
  565. typedef enum
  566. {
  567. RADIO_DIO1 = 0x02,
  568. RADIO_DIO2 = 0x04,
  569. RADIO_DIO3 = 0x08,
  570. }RadioDios_t;
  571. /*!
  572. * \brief Represents the tick size available for Rx/Tx timeout operations
  573. */
  574. typedef enum
  575. {
  576. RADIO_TICK_SIZE_0015_US = 0x00,
  577. RADIO_TICK_SIZE_0062_US = 0x01,
  578. RADIO_TICK_SIZE_1000_US = 0x02,
  579. RADIO_TICK_SIZE_4000_US = 0x03,
  580. }RadioTickSizes_t;
  581. /*!
  582. * \brief Represents the role of the radio during ranging operations
  583. */
  584. typedef enum
  585. {
  586. RADIO_RANGING_ROLE_SLAVE = 0x00,
  587. RADIO_RANGING_ROLE_MASTER = 0x01,
  588. }RadioRangingRoles_t;
  589. /*!
  590. * \brief Represents all possible opcode understood by the radio
  591. */
  592. typedef enum RadioCommands_u
  593. {
  594. RADIO_GET_STATUS = 0xC0,
  595. RADIO_WRITE_REGISTER = 0x18,
  596. RADIO_READ_REGISTER = 0x19,
  597. RADIO_WRITE_BUFFER = 0x1A,
  598. RADIO_READ_BUFFER = 0x1B,
  599. RADIO_SET_SLEEP = 0x84,
  600. RADIO_SET_STANDBY = 0x80,
  601. RADIO_SET_FS = 0xC1,
  602. RADIO_SET_TX = 0x83,
  603. RADIO_SET_RX = 0x82,
  604. RADIO_SET_RXDUTYCYCLE = 0x94,
  605. RADIO_SET_CAD = 0xC5,
  606. RADIO_SET_TXCONTINUOUSWAVE = 0xD1,
  607. RADIO_SET_TXCONTINUOUSPREAMBLE = 0xD2,
  608. RADIO_SET_PACKETTYPE = 0x8A,
  609. RADIO_GET_PACKETTYPE = 0x03,
  610. RADIO_SET_RFFREQUENCY = 0x86,
  611. RADIO_SET_TXPARAMS = 0x8E,
  612. RADIO_SET_CADPARAMS = 0x88,
  613. RADIO_SET_BUFFERBASEADDRESS = 0x8F,
  614. RADIO_SET_MODULATIONPARAMS = 0x8B,
  615. RADIO_SET_PACKETPARAMS = 0x8C,
  616. RADIO_GET_RXBUFFERSTATUS = 0x17,
  617. RADIO_GET_PACKETSTATUS = 0x1D,
  618. RADIO_GET_RSSIINST = 0x1F,
  619. RADIO_SET_DIOIRQPARAMS = 0x8D,
  620. RADIO_GET_IRQSTATUS = 0x15,
  621. RADIO_CLR_IRQSTATUS = 0x97,
  622. RADIO_CALIBRATE = 0x89,
  623. RADIO_SET_REGULATORMODE = 0x96,
  624. RADIO_SET_SAVECONTEXT = 0xD5,
  625. RADIO_SET_AUTOTX = 0x98,
  626. RADIO_SET_AUTOFS = 0x9E,
  627. RADIO_SET_LONGPREAMBLE = 0x9B,
  628. RADIO_SET_UARTSPEED = 0x9D,
  629. RADIO_SET_RANGING_ROLE = 0xA3,
  630. }RadioCommands_t;
  631. /*!
  632. * \brief Represents an amount of time measurable by the radio clock
  633. *
  634. * @code
  635. * Time = Step * NbSteps
  636. * Example:
  637. * Step = RADIO_TICK_SIZE_4000_US( 4 ms )
  638. * NbSteps = 1000
  639. * Time = 4e-3 * 1000 = 4 seconds
  640. * @endcode
  641. */
  642. typedef struct TickTime_s
  643. {
  644. RadioTickSizes_t Step; //!< The step of ticktime
  645. /*!
  646. * \brief The number of steps for ticktime
  647. * Special values are:
  648. * - 0x0000 for single mode
  649. * - 0xFFFF for continuous mode
  650. */
  651. uint16_t NbSteps;
  652. }TickTime_t;
  653. /*!
  654. * \brief RX_TX_CONTINUOUS and RX_TX_SINGLE are two particular values for TickTime.
  655. * The former keep the radio in Rx or Tx mode, even after successfull reception
  656. * or transmission. It should never generate Timeout interrupt.
  657. * The later let the radio enought time to make one reception or transmission.
  658. * No Timeout interrupt is generated, and the radio fall in StandBy mode after
  659. * reception or transmission.
  660. */
  661. #define RX_TX_CONTINUOUS ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0xFFFF }
  662. #define RX_TX_SINGLE ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0 }
  663. /*!
  664. * \brief The type describing the modulation parameters for every packet types
  665. */
  666. typedef struct
  667. {
  668. RadioPacketTypes_t PacketType; //!< Packet to which the modulation parameters are referring to.
  669. // union
  670. struct
  671. {
  672. /*!
  673. * \brief Holds the GFSK modulation parameters
  674. *
  675. * In GFSK modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
  676. */
  677. struct
  678. {
  679. RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations
  680. RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations
  681. RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations
  682. }Gfsk;
  683. /*!
  684. * \brief Holds the LORA modulation parameters
  685. *
  686. * LORA modulation is defined by Spreading Factor (SF), Bandwidth and Coding Rate
  687. */
  688. struct
  689. {
  690. RadioLoRaSpreadingFactors_t SpreadingFactor; //!< Spreading Factor for the LORA modulation
  691. RadioLoRaBandwidths_t Bandwidth; //!< Bandwidth for the LORA modulation
  692. RadioLoRaCodingRates_t CodingRate; //!< Coding rate for the LORA modulation
  693. }LoRa;
  694. /*!
  695. * \brief Holds the FLRC modulation parameters
  696. *
  697. * In FLRC modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
  698. */
  699. struct
  700. {
  701. RadioFlrcBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for FLRC modulation
  702. RadioFlrcCodingRates_t CodingRate; //!< The coding rate for FLRC modulation
  703. RadioModShapings_t ModulationShaping; //!< The modulation shaping for FLRC modulation
  704. }Flrc;
  705. /*!
  706. * \brief Holds the BLE modulation parameters
  707. *
  708. * In BLE modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
  709. */
  710. struct
  711. {
  712. RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations
  713. RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations
  714. RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations
  715. }Ble;
  716. }Params; //!< Holds the modulation parameters structure
  717. }ModulationParams_t;
  718. /*!
  719. * \brief Structure describing the error codes for callback functions
  720. */
  721. typedef enum
  722. {
  723. IRQ_HEADER_ERROR_CODE = 0x00,
  724. IRQ_SYNCWORD_ERROR_CODE,
  725. IRQ_CRC_ERROR_CODE,
  726. IRQ_RANGING_ON_LORA_ERROR_CODE,
  727. }IrqErrorCode_t;
  728. /*!
  729. * \brief Structure describing the ranging codes for callback functions
  730. */
  731. typedef enum
  732. {
  733. IRQ_RANGING_SLAVE_ERROR_CODE = 0x00,
  734. IRQ_RANGING_SLAVE_VALID_CODE,
  735. IRQ_RANGING_MASTER_ERROR_CODE,
  736. IRQ_RANGING_MASTER_VALID_CODE,
  737. }IrqRangingCode_t;
  738. /*!
  739. * \brief The radio callbacks structure
  740. * Holds function pointers to be called on radio interrupts
  741. */
  742. typedef struct
  743. {
  744. void ( *txDone )( void ); //!< Pointer to a function run on successful transmission
  745. void ( *rxDone )( void ); //!< Pointer to a function run on successful reception
  746. void ( *rxSyncWordDone )( void ); //!< Pointer to a function run on successful SyncWord reception
  747. void ( *rxHeaderDone )( void ); //!< Pointer to a function run on successful Header reception
  748. void ( *txTimeout )( void ); //!< Pointer to a function run on transmission timeout
  749. void ( *rxTimeout )( void ); //!< Pointer to a function run on reception timeout
  750. void ( *rxError )( IrqErrorCode_t errCode ); //!< Pointer to a function run on reception error
  751. void ( *rangingDone )( IrqRangingCode_t val ); //!< Pointer to a function run on ranging terminated
  752. void ( *cadDone )( bool cadFlag ); //!< Pointer to a function run on channel activity detected
  753. }RadioCallbacks_t;
  754. /*!
  755. * \brief The type describing the packet parameters for every packet types
  756. */
  757. typedef struct
  758. {
  759. RadioPacketTypes_t PacketType; //!< Packet to which the packet parameters are referring to.
  760. // union
  761. struct
  762. {
  763. /*!
  764. * \brief Holds the GFSK packet parameters
  765. */
  766. struct
  767. {
  768. RadioPreambleLengths_t PreambleLength; //!< The preamble length for GFSK packet type
  769. RadioSyncWordLengths_t SyncWordLength; //!< The synchronization word length for GFSK packet type
  770. RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word
  771. RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the GFSK packet. If the header is implicit, it will not be transmitted
  772. uint8_t PayloadLength; //!< Size of the payload in the GFSK packet
  773. RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the GFSK packet
  774. RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable
  775. }Gfsk;
  776. /*!
  777. * \brief Holds the LORA packet parameters
  778. */
  779. struct
  780. {
  781. uint8_t PreambleLength; //!< The preamble length is the number of LORA symbols in the preamble. To set it, use the following formula @code Number of symbols = PreambleLength[3:0] * ( 2^PreambleLength[7:4] ) @endcode
  782. RadioLoRaPacketLengthsModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the LORA packet. If the header is implicit, it will not be transmitted
  783. uint8_t PayloadLength; //!< Size of the payload in the LORA packet
  784. RadioLoRaCrcModes_t CrcMode; //!< Size of CRC block in LORA packet
  785. RadioLoRaIQModes_t InvertIQ; //!< Allows to swap IQ for LORA packet
  786. }LoRa;
  787. /*!
  788. * \brief Holds the FLRC packet parameters
  789. */
  790. struct
  791. {
  792. RadioPreambleLengths_t PreambleLength; //!< The preamble length for FLRC packet type
  793. RadioFlrcSyncWordLengths_t SyncWordLength; //!< The synchronization word length for FLRC packet type
  794. RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word
  795. RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the FLRC packet. If the header is implicit, it will not be transmitted.
  796. uint8_t PayloadLength; //!< Size of the payload in the FLRC packet
  797. RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the FLRC packet
  798. RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable
  799. }Flrc;
  800. /*!
  801. * \brief Holds the BLE packet parameters
  802. */
  803. struct
  804. {
  805. RadioBleConnectionStates_t ConnectionState; //!< The BLE state
  806. RadioBleCrcFields_t CrcField; //!< Size of the CRC block in the BLE packet
  807. RadioBlePacketTypes_t BlePacketType; //!< Special BLE packet types
  808. RadioWhiteningModes_t Whitening; //!< Usage of whitening on PDU and CRC blocks of BLE packet
  809. }Ble;
  810. }Params; //!< Holds the packet parameters structure
  811. }PacketParams_t;
  812. /*!
  813. * \brief Represents the packet status for every packet type
  814. */
  815. typedef struct
  816. {
  817. RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to.
  818. union
  819. {
  820. struct
  821. {
  822. int8_t RssiAvg; //!< The averaged RSSI
  823. int8_t RssiSync; //!< The RSSI measured on last packet
  824. struct
  825. {
  826. bool SyncError :1; //!< SyncWord error on last packet
  827. bool LengthError :1; //!< Length error on last packet
  828. bool CrcError :1; //!< CRC error on last packet
  829. bool AbortError :1; //!< Abort error on last packet
  830. bool HeaderReceived :1; //!< Header received on last packet
  831. bool PacketReceived :1; //!< Packet received
  832. bool PacketControlerBusy :1; //!< Packet controller busy
  833. }ErrorStatus; //!< The error status Byte
  834. struct
  835. {
  836. bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets
  837. bool PacketSent :1; //!< Packet sent, only relevant in Tx mode
  838. }TxRxStatus; //!< The Tx/Rx status Byte
  839. uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet
  840. }Gfsk;
  841. struct
  842. {
  843. int8_t RssiPkt; //!< The RSSI of the last packet
  844. int8_t SnrPkt; //!< The SNR of the last packet
  845. struct
  846. {
  847. bool SyncError :1; //!< SyncWord error on last packet
  848. bool LengthError :1; //!< Length error on last packet
  849. bool CrcError :1; //!< CRC error on last packet
  850. bool AbortError :1; //!< Abort error on last packet
  851. bool HeaderReceived :1; //!< Header received on last packet
  852. bool PacketReceived :1; //!< Packet received
  853. bool PacketControlerBusy :1; //!< Packet controller busy
  854. }ErrorStatus; //!< The error status Byte
  855. struct
  856. {
  857. bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets
  858. bool PacketSent :1; //!< Packet sent, only relevant in Tx mode
  859. }TxRxStatus; //!< The Tx/Rx status Byte
  860. uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet
  861. }LoRa;
  862. struct
  863. {
  864. int8_t RssiAvg; //!< The averaged RSSI
  865. int8_t RssiSync; //!< The RSSI of the last packet
  866. struct
  867. {
  868. bool SyncError :1; //!< SyncWord error on last packet
  869. bool LengthError :1; //!< Length error on last packet
  870. bool CrcError :1; //!< CRC error on last packet
  871. bool AbortError :1; //!< Abort error on last packet
  872. bool HeaderReceived :1; //!< Header received on last packet
  873. bool PacketReceived :1; //!< Packet received
  874. bool PacketControlerBusy :1; //!< Packet controller busy
  875. }ErrorStatus; //!< The error status Byte
  876. struct
  877. {
  878. uint8_t RxPid :2; //!< PID of the Rx
  879. bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets
  880. bool RxPidErr :1; //!< Received PID error
  881. bool PacketSent :1; //!< Packet sent, only relevant in Tx mode
  882. }TxRxStatus; //!< The Tx/Rx status Byte
  883. uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet
  884. }Flrc;
  885. struct
  886. {
  887. int8_t RssiAvg; //!< The averaged RSSI
  888. int8_t RssiSync; //!< The RSSI of the last packet
  889. struct
  890. {
  891. bool SyncError :1; //!< SyncWord error on last packet
  892. bool LengthError :1; //!< Length error on last packet
  893. bool CrcError :1; //!< CRC error on last packet
  894. bool AbortError :1; //!< Abort error on last packet
  895. bool HeaderReceived :1; //!< Header received on last packet
  896. bool PacketReceived :1; //!< Packet received
  897. bool PacketControlerBusy :1; //!< Packet controller busy
  898. }ErrorStatus; //!< The error status Byte
  899. struct
  900. {
  901. bool PacketSent :1; //!< Packet sent, only relevant in Tx mode
  902. }TxRxStatus; //!< The Tx/Rx status Byte
  903. uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet
  904. }Ble;
  905. }Params;
  906. }PacketStatus_t;
  907. /*!
  908. * \brief Represents the Rx internal counters values when GFSK or LORA packet type is used
  909. */
  910. typedef struct
  911. {
  912. RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to.
  913. union
  914. {
  915. struct
  916. {
  917. uint16_t PacketReceived; //!< Number of received packets
  918. uint16_t CrcError; //!< Number of CRC errors
  919. uint16_t LengthError; //!< Number of length errors
  920. uint16_t SyncwordError; //!< Number of sync-word errors
  921. }Gfsk;
  922. struct
  923. {
  924. uint16_t PacketReceived; //!< Number of received packets
  925. uint16_t CrcError; //!< Number of CRC errors
  926. uint16_t HeaderValid; //!< Number of valid headers
  927. }LoRa;
  928. }Params;
  929. }RxCounter_t;
  930. /*!
  931. * \brief Represents a calibration configuration
  932. */
  933. typedef struct
  934. {
  935. uint8_t RC64KEnable : 1; //!< Calibrate RC64K clock
  936. uint8_t RC13MEnable : 1; //!< Calibrate RC13M clock
  937. uint8_t PLLEnable : 1; //!< Calibrate PLL
  938. uint8_t ADCPulseEnable : 1; //!< Calibrate ADC Pulse
  939. uint8_t ADCBulkNEnable : 1; //!< Calibrate ADC bulkN
  940. uint8_t ADCBulkPEnable : 1; //!< Calibrate ADC bulkP
  941. }CalibrationParams_t;
  942. /*!
  943. * \brief Represents a sleep mode configuration
  944. */
  945. typedef struct
  946. {
  947. uint8_t WakeUpRTC : 1; //!< Get out of sleep mode if wakeup signal received from RTC
  948. uint8_t InstructionRamRetention : 1; //!< InstructionRam is conserved during sleep
  949. uint8_t DataBufferRetention : 1; //!< Data buffer is conserved during sleep
  950. uint8_t DataRamRetention : 1; //!< Data ram is conserved during sleep
  951. }SleepParams_t;
  952. /*!
  953. * \brief Compute the two's complement for a register of size lower than
  954. * 32bits
  955. *
  956. * \param [in] num The register to be two's complemented
  957. * \param [in] bitCnt The position of the sign bit
  958. */
  959. static int32_t SX1280complement2( const uint32_t num, const uint8_t bitCnt );
  960. /*!
  961. * \brief Returns the value of LoRa bandwidth from driver's value
  962. *
  963. * The value is returned in Hz so that it can be represented as an integer
  964. * type. Most computation should be done as integer to reduce floating
  965. * point related errors.
  966. *
  967. * \retval loRaBw The value of the current bandwidth in Hz
  968. */
  969. int32_t SX1280GetLoRaBandwidth( void );
  970. /*!
  971. * \brief DIOs interrupt callback
  972. *
  973. * \remark Called to handle all 3 DIOs pins
  974. */
  975. void SX1280OnDioIrq( void );
  976. /*!
  977. * \brief Set the role of the radio during ranging operations
  978. *
  979. * \param [in] role Role of the radio
  980. */
  981. void SX1280SetRangingRole( RadioRangingRoles_t role );
  982. /*!
  983. * \brief Initializes the radio driver
  984. */
  985. void SX1280Init( RadioCallbacks_t *callbacks );
  986. /*!
  987. * \brief Set the driver in polling mode.
  988. *
  989. * In polling mode the application is responsible to call ProcessIrqs( ) to
  990. * execute callbacks functions.
  991. * The default mode is Interrupt Mode.
  992. * @code
  993. * // Initializations and callbacks declaration/definition
  994. * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks );
  995. * radio.Init( );
  996. * radio.SetPollingMode( );
  997. *
  998. * while( true )
  999. * {
  1000. * // IRQ processing is automatically done
  1001. * radio.ProcessIrqs( ); // <-- here, as well as callback functions
  1002. * // calls
  1003. * // Do some applicative work
  1004. * }
  1005. * @endcode
  1006. *
  1007. * \see SX1280SetInterruptMode
  1008. */
  1009. void SX1280SetPollingMode( void );
  1010. /*!
  1011. * \brief Set the driver in interrupt mode.
  1012. *
  1013. * In interrupt mode, the driver communicate with the radio during the
  1014. * interruption by direct calls to ProcessIrqs( ). The main advantage is
  1015. * the possibility to have low power application architecture.
  1016. * This is the default mode.
  1017. * @code
  1018. * // Initializations and callbacks declaration/definition
  1019. * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks );
  1020. * radio.Init( );
  1021. * radio.SetInterruptMode( ); // Optionnal. Driver default behavior
  1022. *
  1023. * while( true )
  1024. * {
  1025. * // Do some applicative work
  1026. * }
  1027. * @endcode
  1028. *
  1029. * \see SX1280SetPollingMode
  1030. */
  1031. void SX1280SetInterruptMode( void );
  1032. /*!
  1033. * \brief Initializes the radio registers to the recommended default values
  1034. */
  1035. void SX1280SetRegistersDefault( void );
  1036. /*!
  1037. * \brief Returns the current device firmware version
  1038. *
  1039. * \retval version Firmware version
  1040. */
  1041. uint16_t SX1280GetFirmwareVersion( void );
  1042. /*!
  1043. * \brief Gets the current Operation Mode of the Radio
  1044. *
  1045. * \retval RadioOperatingModes_t last operating mode
  1046. */
  1047. RadioOperatingModes_t SX1280GetOpMode( void );
  1048. /*!
  1049. * \brief Gets the current radio status
  1050. *
  1051. * \retval status Radio status
  1052. */
  1053. RadioStatus_t SX1280GetStatus( void );
  1054. /*!
  1055. * \brief Sets the radio in sleep mode
  1056. *
  1057. * \param [in] sleepConfig The sleep configuration describing data
  1058. * retention and RTC wake-up
  1059. */
  1060. void SX1280SetSleep( SleepParams_t sleepConfig );
  1061. /*!
  1062. * \brief Sets the radio in configuration mode
  1063. *
  1064. * \param [in] mode The standby mode to put the radio into
  1065. */
  1066. void SX1280SetStandby( RadioStandbyModes_t mode );
  1067. /*!
  1068. * \brief Sets the radio in FS mode
  1069. */
  1070. void SX1280SetFs( void );
  1071. /*!
  1072. * \brief Sets the radio in transmission mode
  1073. *
  1074. * \param [in] timeout Structure describing the transmission timeout value
  1075. */
  1076. void SX1280SetTx( TickTime_t timeout );
  1077. /*!
  1078. * \brief Sets the radio in reception mode
  1079. *
  1080. * \param [in] timeout Structure describing the reception timeout value
  1081. */
  1082. void SX1280SetRx( TickTime_t timeout );
  1083. /*!
  1084. * \brief Sets the Rx duty cycle management parameters
  1085. *
  1086. * \param [in] rxTime Structure describing reception timeout value
  1087. * \param [in] sleepTime Structure describing sleep timeout value
  1088. */
  1089. void SX1280SetRxDutyCycle( RadioTickSizes_t Step, uint16_t NbStepRx, uint16_t RxNbStepSleep );
  1090. /*!
  1091. * \brief Sets the radio in CAD mode
  1092. *
  1093. * \see SX1280::SetCadParams
  1094. */
  1095. void SX1280SetCad( void );
  1096. /*!
  1097. * \brief Sets the radio in continuous wave transmission mode
  1098. */
  1099. void SX1280SetTxContinuousWave( void );
  1100. /*!
  1101. * \brief Sets the radio in continuous preamble transmission mode
  1102. */
  1103. void SX1280SetTxContinuousPreamble( void );
  1104. /*!
  1105. * \brief Sets the radio for the given protocol
  1106. *
  1107. * \param [in] packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA,
  1108. * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC,
  1109. * PACKET_TYPE_BLE]
  1110. *
  1111. * \remark This method has to be called before SetRfFrequency,
  1112. * SetModulationParams and SetPacketParams
  1113. */
  1114. void SX1280SetPacketType( RadioPacketTypes_t packetType );
  1115. /*!
  1116. * \brief Gets the current radio protocol
  1117. *
  1118. * \retval packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA,
  1119. * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC,
  1120. * PACKET_TYPE_BLE, PACKET_TYPE_NONE]
  1121. */
  1122. RadioPacketTypes_t SX1280GetPacketType( void );
  1123. /*!
  1124. * \brief Sets the RF frequency
  1125. *
  1126. * \param [in] frequency RF frequency [Hz]
  1127. */
  1128. void SX1280SetRfFrequency( uint32_t frequency );
  1129. /*!
  1130. * \brief Sets the transmission parameters
  1131. *
  1132. * \param [in] power RF output power [-18..13] dBm
  1133. * \param [in] rampTime Transmission ramp up time
  1134. */
  1135. void SX1280SetTxParams( int8_t power, RadioRampTimes_t rampTime );
  1136. /*!
  1137. * \brief Sets the number of symbols to be used for Channel Activity
  1138. * Detection operation
  1139. *
  1140. * \param [in] cadSymbolNum The number of symbol to use for Channel Activity
  1141. * Detection operations [LORA_CAD_01_SYMBOL, LORA_CAD_02_SYMBOL,
  1142. * LORA_CAD_04_SYMBOL, LORA_CAD_08_SYMBOL, LORA_CAD_16_SYMBOL]
  1143. */
  1144. void SX1280SetCadParams( RadioLoRaCadSymbols_t cadSymbolNum );
  1145. /*!
  1146. * \brief Sets the data buffer base address for transmission and reception
  1147. *
  1148. * \param [in] txBaseAddress Transmission base address
  1149. * \param [in] rxBaseAddress Reception base address
  1150. */
  1151. void SX1280SetBufferBaseAddresses( uint8_t txBaseAddress, uint8_t rxBaseAddress );
  1152. /*!
  1153. * \brief Set the modulation parameters
  1154. *
  1155. * \param [in] modParams A structure describing the modulation parameters
  1156. */
  1157. void SX1280SetModulationParams( ModulationParams_t *modParams );
  1158. /*!
  1159. * \brief Sets the packet parameters
  1160. *
  1161. * \param [in] packetParams A structure describing the packet parameters
  1162. */
  1163. void SX1280SetPacketParams( PacketParams_t *packetParams );
  1164. /*!
  1165. * \brief Gets the last received packet buffer status
  1166. *
  1167. * \param [out] payloadLength Last received packet payload length
  1168. * \param [out] rxStartBuffer Last received packet buffer address pointer
  1169. */
  1170. void SX1280GetRxBufferStatus( uint8_t *payloadLength, uint8_t *rxStartBuffer );
  1171. /*!
  1172. * \brief Gets the last received packet payload length
  1173. *
  1174. * \param [out] pktStatus A structure of packet status
  1175. */
  1176. void SX1280GetPacketStatus( PacketStatus_t *pktStatus );
  1177. /*!
  1178. * \brief Returns the instantaneous RSSI value for the last packet received
  1179. *
  1180. * \retval rssiInst Instantaneous RSSI
  1181. */
  1182. int8_t SX1280GetRssiInst( void );
  1183. /*!
  1184. * \brief Sets the IRQ mask and DIO masks
  1185. *
  1186. * \param [in] irqMask General IRQ mask
  1187. * \param [in] dio1Mask DIO1 mask
  1188. * \param [in] dio2Mask DIO2 mask
  1189. * \param [in] dio3Mask DIO3 mask
  1190. */
  1191. void SX1280SetDioIrqParams( uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask );
  1192. /*!
  1193. * \brief Returns the current IRQ status
  1194. *
  1195. * \retval irqStatus IRQ status
  1196. */
  1197. uint16_t SX1280GetIrqStatus( void );
  1198. /*!
  1199. * \brief Clears the IRQs
  1200. *
  1201. * \param [in] irq IRQ(s) to be cleared
  1202. */
  1203. void SX1280ClearIrqStatus( uint16_t irq );
  1204. /*!
  1205. * \brief Calibrates the given radio block
  1206. *
  1207. * \param [in] calibParam The description of blocks to be calibrated
  1208. */
  1209. void SX1280Calibrate( CalibrationParams_t calibParam );
  1210. /*!
  1211. * \brief Sets the power regulators operating mode
  1212. *
  1213. * \param [in] mode [0: LDO, 1:DC_DC]
  1214. */
  1215. void SX1280SetRegulatorMode( RadioRegulatorModes_t mode );
  1216. /*!
  1217. * \brief Saves the current selected modem configuration into data RAM
  1218. */
  1219. void SX1280SetSaveContext( void );
  1220. /*!
  1221. * \brief Sets the chip to automatically send a packet after the end of a packet reception
  1222. *
  1223. * \remark The offset is automatically compensated inside the function
  1224. *
  1225. * \param [in] time The delay in us after which a Tx is done
  1226. */
  1227. void SX1280SetAutoTx( uint16_t time );
  1228. /*!
  1229. * \brief Sets the chip to automatically receive a packet after the end of a packet transmission
  1230. *
  1231. * \remark The offset is automatically compensated inside the function
  1232. *
  1233. * \param [in] time The delay in us after which a Rx is done
  1234. */
  1235. void SX1280SetAutoFS( uint8_t enable );
  1236. /*!
  1237. * \brief Enables or disables long preamble detection mode
  1238. *
  1239. * \param [in] enable [0: Disable, 1: Enable]
  1240. */
  1241. void SX1280SetLongPreamble( uint8_t enable );
  1242. /*!
  1243. * \brief Saves the payload to be send in the radio buffer
  1244. *
  1245. * \param [in] payload A pointer to the payload
  1246. * \param [in] size The size of the payload
  1247. */
  1248. void SX1280SetPayload( uint8_t *payload, uint8_t size );
  1249. /*!
  1250. * \brief Reads the payload received. If the received payload is longer
  1251. * than maxSize, then the method returns 1 and do not set size and payload.
  1252. *
  1253. * \param [out] payload A pointer to a buffer into which the payload will be copied
  1254. * \param [out] size A pointer to the size of the payload received
  1255. * \param [in] maxSize The maximal size allowed to copy into the buffer
  1256. */
  1257. uint8_t SX1280GetPayload( uint8_t *payload, uint8_t *size, uint8_t maxSize );
  1258. /*!
  1259. * \brief Sends a payload
  1260. *
  1261. * \param [in] payload A pointer to the payload to send
  1262. * \param [in] size The size of the payload to send
  1263. * \param [in] timeout The timeout for Tx operation
  1264. */
  1265. void SX1280SendPayload( uint8_t *payload, uint8_t size, TickTime_t timeout );
  1266. /*!
  1267. * \brief Sets the Sync Word given by index used in GFSK, FLRC and BLE protocols
  1268. *
  1269. * \remark 5th byte isn't used in FLRC and BLE protocols
  1270. *
  1271. * \param [in] syncWordIdx Index of SyncWord to be set [1..3]
  1272. * \param [in] syncWord SyncWord bytes ( 5 bytes )
  1273. *
  1274. * \retval status [0: OK, 1: NOK]
  1275. */
  1276. uint8_t SX1280SetSyncWord( uint8_t syncWordIdx, uint8_t *syncWord );
  1277. /*!
  1278. * \brief Defines how many error bits are tolerated in sync word detection
  1279. *
  1280. * \param [in] errorBits Number of error bits supported to validate the Sync word detection
  1281. * ( default is 4 bit, minimum is 1 bit )
  1282. */
  1283. void SX1280SetSyncWordErrorTolerance( uint8_t errorBits );
  1284. /*!
  1285. * \brief Sets the Initial value for the LFSR used for the CRC calculation
  1286. *
  1287. * \param [in] seed Initial LFSR value ( 4 bytes )
  1288. *
  1289. */
  1290. void SX1280SetCrcSeed( uint16_t seed );
  1291. /*!
  1292. * \brief Set the Access Address field of BLE packet
  1293. *
  1294. * \param [in] accessAddress The access address to be used for next BLE packet sent
  1295. */
  1296. void SX1280SetBleAccessAddress( uint32_t accessAddress );
  1297. /*!
  1298. * \brief Set the Access Address for Advertizer BLE packets
  1299. *
  1300. * All advertizer BLE packets must use a particular value for Access
  1301. * Address field. This method sets it.
  1302. *
  1303. * \see SX1280::SetBleAccessAddress
  1304. */
  1305. void SX1280SetBleAdvertizerAccessAddress( void );
  1306. /*!
  1307. * \brief Sets the seed used for the CRC calculation
  1308. *
  1309. * \param [in] seed The seed value
  1310. *
  1311. */
  1312. void SX1280SetCrcPolynomial( uint16_t seed );
  1313. /*!
  1314. * \brief Sets the Initial value of the LFSR used for the whitening in GFSK, FLRC and BLE protocols
  1315. *
  1316. * \param [in] seed Initial LFSR value
  1317. */
  1318. void SX1280SetWhiteningSeed( uint8_t seed );
  1319. /*!
  1320. * \brief Sets the number of bits used to check that ranging request match ranging ID
  1321. *
  1322. * \param [in] length [0: 8 bits, 1: 16 bits,
  1323. * 2: 24 bits, 3: 32 bits]
  1324. */
  1325. void SX1280SetRangingIdLength( RadioRangingIdCheckLengths_t length );
  1326. /*!
  1327. * \brief Sets ranging device id
  1328. *
  1329. * \param [in] address Device address
  1330. */
  1331. void SX1280SetDeviceRangingAddress( uint32_t address );
  1332. /*!
  1333. * \brief Sets the device id to ping in a ranging request
  1334. *
  1335. * \param [in] address Address of the device to ping
  1336. */
  1337. void SX1280SetRangingRequestAddress( uint32_t address );
  1338. /*!
  1339. * \brief Return the ranging result value
  1340. *
  1341. * \param [in] resultType Specifies the type of result.
  1342. * [0: RAW, 1: Averaged,
  1343. * 2: De-biased, 3:Filtered]
  1344. *
  1345. * \retval ranging The ranging measure filtered according to resultType [m]
  1346. */
  1347. double SX1280GetRangingResult( RadioRangingResultTypes_t resultType );
  1348. /*!
  1349. * \brief Sets the standard processing delay between Master and Slave
  1350. *
  1351. * \param [in] cal RxTx delay offset for correcting ranging bias.
  1352. *
  1353. * The calibration value reflects the group delay of the radio front end and
  1354. * must be re-performed for each new SX1280 PCB design. The value is obtained
  1355. * empirically by either conducted measurement in a known electrical length
  1356. * coaxial RF cable (where the design is connectorised) or by radiated
  1357. * measurement, at a known distance, where an antenna is present.
  1358. * The result of the calibration process is that the SX1280 ranging result
  1359. * accurately reflects the physical range, the calibration procedure therefore
  1360. * removes the average timing error from the time-of-flight measurement for a
  1361. * given design.
  1362. *
  1363. * The values are Spreading Factor dependents, and depend also of the board
  1364. * design. Some typical values are provided in the next table.
  1365. *
  1366. * Spreading Factor | Calibration Value
  1367. * ---------------- | -----------------
  1368. * SF5 | 12200
  1369. * SF6 | 12200
  1370. * SF7 | 12400
  1371. * SF8 | 12650
  1372. * SF9 | 12940
  1373. * SF10 | 13000
  1374. * SF11 | 13060
  1375. * SF12 | 13120
  1376. */
  1377. void SX1280SetRangingCalibration( uint16_t cal );
  1378. /*!
  1379. * \brief Clears the ranging filter
  1380. */
  1381. void SX1280RangingClearFilterResult( void );
  1382. /*!
  1383. * \brief Set the number of samples considered in the built-in filter
  1384. *
  1385. * \param [in] numSample The number of samples to use built-in filter
  1386. * [8..255]
  1387. *
  1388. * \remark Value inferior to 8 will be silently set to 8
  1389. */
  1390. void SX1280RangingSetFilterNumSamples( uint8_t numSample );
  1391. /*!
  1392. * \brief Return the Estimated Frequency Error in LORA and RANGING operations
  1393. *
  1394. * \retval efe The estimated frequency error [Hz]
  1395. */
  1396. double SX1280GetFrequencyError( void );
  1397. /*!
  1398. * \brief Process the analysis of radio IRQs and calls callback functions
  1399. * depending on radio state
  1400. */
  1401. void SX1280ProcessIrqs( void );
  1402. /*!
  1403. * \brief Clears the instruction RAM
  1404. */
  1405. void SX1280ClearInstructionRam( void );
  1406. /*!
  1407. * \brief Parses 1 HEX file line and writes the content to the instruction memory
  1408. *
  1409. * \param [in] line HEX file line string
  1410. *
  1411. * \retval status [0: ERROR, 1:OK]
  1412. */
  1413. int8_t SX1280ParseHexFileLine( char* line );
  1414. /*!
  1415. * \brief Gets individual fields for the given HEX file line
  1416. *
  1417. * \param [in] line HEX file line string
  1418. * \param [out] bytes Bytes array to be written to the instruction memory
  1419. * \param [out] addr Instruction memory address where to write the bytes array
  1420. * \param [out] num Number of bytes in Bytes array
  1421. * \param [out] code HEX file line type [0: instruction, 1: end of file, 2: begin of file]
  1422. *
  1423. * \retval status [0: ERROR, 1:OK]
  1424. */
  1425. int8_t SX1280GetHexFileLineFields( char* line, uint8_t *bytes, uint16_t *addr, uint16_t *num, uint8_t *code );
  1426. #endif // __SX1280_H__