nrf_gzll.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. * $LastChangedRevision: 39629 $
  12. */
  13. /**
  14. * @file
  15. * @brief Gazell Link Layer API.
  16. */
  17. #ifndef NRF_GZLL_H__
  18. #define NRF_GZLL_H__
  19. #include <stdbool.h>
  20. #include "nrf.h"
  21. #include "nrf_gzll_constants.h"
  22. /**
  23. * @defgroup gzll_02_api Application Programming Interface (API)
  24. * @{
  25. * @ingroup modules_01_gzll
  26. * @brief Gazell Link Layer Application Programming Interface (API).
  27. */
  28. /**
  29. * @enum nrf_gzll_mode_t
  30. * @brief Enumerator used for selecting Gazell mode.
  31. */
  32. typedef enum
  33. {
  34. NRF_GZLL_MODE_DEVICE, ///< Device mode
  35. NRF_GZLL_MODE_HOST, ///< Host mode
  36. NRF_GZLL_MODE_SUSPEND, ///< Suspend mode ("disabled with timer running")
  37. } nrf_gzll_mode_t;
  38. /**
  39. * @enum nrf_gzll_device_channel_selection_policy_t
  40. * @brief Enumerator used for selecting Gazell Device channel
  41. * selection policy.
  42. */
  43. typedef enum
  44. {
  45. NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_SUCCESSFUL, ///< Start on previous successful channel
  46. NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT, ///< Start on channel currently monitored by Host
  47. } nrf_gzll_device_channel_selection_policy_t;
  48. /**
  49. * @enum nrf_gzll_tx_power_t
  50. * @brief Enumerator used for selecting the transmit (TX) power.
  51. */
  52. typedef enum
  53. {
  54. NRF_GZLL_TX_POWER_4_DBM, ///< 4 dBm transmit power.
  55. NRF_GZLL_TX_POWER_0_DBM, ///< 0 dBm transmit power.
  56. NRF_GZLL_TX_POWER_N4_DBM, ///< -4 dBm transmit power.
  57. NRF_GZLL_TX_POWER_N8_DBM, ///< -8 dBm transmit power.
  58. NRF_GZLL_TX_POWER_N12_DBM, ///< -12 dBm transmit power.
  59. NRF_GZLL_TX_POWER_N16_DBM, ///< -16 dBm transmit power.
  60. NRF_GZLL_TX_POWER_N20_DBM ///< -20 dBm transmit power.
  61. } nrf_gzll_tx_power_t;
  62. /**
  63. * @enum nrf_gzll_datarate_t
  64. * @brief Enumerator used for selecting the radio datarate.
  65. */
  66. typedef enum
  67. {
  68. NRF_GZLL_DATARATE_250KBIT, ///< 250 Kbps datarate.
  69. NRF_GZLL_DATARATE_1MBIT, ///< 1 Mbps datarate.
  70. NRF_GZLL_DATARATE_2MBIT ///< 2 Mbps datarate.
  71. } nrf_gzll_datarate_t;
  72. /**
  73. * @enum nrf_gzll_xosc_ctl_t
  74. * @brief Enumerator used for specifying whether switching the
  75. * external 16 MHz oscillator on/off shall be handled automatically
  76. * inside Gazell or manually by the application.
  77. */
  78. typedef enum
  79. {
  80. NRF_GZLL_XOSC_CTL_AUTO, ///< Switch XOSC on/off automatically
  81. NRF_GZLL_XOSC_CTL_MANUAL ///< Switch XOSC on/off manually
  82. } nrf_gzll_xosc_ctl_t;
  83. /**
  84. * @enum nrf_gzll_error_code_t
  85. * @brief Enumerator used for error codes for Gazell API functions
  86. */
  87. typedef enum
  88. {
  89. NRF_GZLL_ERROR_CODE_NO_ERROR = 0,
  90. ///< No error has been detected.
  91. NRF_GZLL_ERROR_CODE_FAILED_TO_INITIALIZE = 1,
  92. ///< The function NRF_GZLL_init failed.
  93. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_CONFIGURE_WHEN_ENABLED = 2,
  94. ///< A call to a configuration 'set' function was made while Gazell was
  95. ///< enabled.
  96. NRF_GZLL_ERROR_CODE_POINTER_IS_NULL = 3,
  97. ///< A null pointer was given as an input to a function.
  98. NRF_GZLL_ERROR_CODE_INVALID_PIPE = 4,
  99. ///< An invalid pipe number was given as an input to a function.
  100. NRF_GZLL_ERROR_CODE_INVALID_MODE = 5,
  101. ///< An invalid value for the nrf_gzll_mode_t enumerator was given as input
  102. ///< to a function.
  103. NRF_GZLL_ERROR_CODE_INVALID_PAYLOAD_LENGTH = 6,
  104. ///< An invalid payload length was given as an input to a function.
  105. NRF_GZLL_ERROR_CODE_INVALID_CHANNEL_TABLE_SIZE = 7,
  106. ///< An invalid channel table size was given as an input to a function.
  107. NRF_GZLL_ERROR_CODE_INSUFFICIENT_PACKETS_AVAILABLE = 8,
  108. ///< There are insufficient packets in the Gazell memory pool to
  109. ///< successfully execute the operation.
  110. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_ADD_TO_FULL_FIFO = 9,
  111. ///< There is insufficient space in the TX FIFO for the data packet.
  112. NRF_GZLL_ERROR_CODE_NO_SPACE_IN_RX_FIFO_FOR_ACK = 10,
  113. ///< There is insufficient space in the RX FIFO for the ACK.
  114. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_FETCH_FROM_EMPTY_FIFO = 11,
  115. ///< Attempted to fetch a packet from an empty FIFO. Use the functions nrf_gzll_get_tx_fifo_packet_count() or nrf_gzll_get_rx_fifo_packet_count()
  116. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_FLUSH_WHEN_ENABLED = 12,
  117. ///< Attempted to fetch a packet from an empty FIFO. Use the functions nrf_gzll_get_tx_fifo_packet_count() or nrf_gzll_get_rx_fifo_packet_count()
  118. NRF_GZLL_ERROR_CODE_INVALID_PARAMETER = 14,
  119. ///< Attempted to set a variable which was not valid.
  120. NRF_GZLL_ERROR_CODE_INTERNAL_ASSERT_OCCURRED = 15,
  121. ///< An internal assert occurred.
  122. NRF_GZLL_ERROR_CODE_CALLBACK_NOT_IMPLEMENTED = 16,
  123. ///< A callback was called but not implemented by the application.
  124. NRF_GZLL_ERROR_CODE_NUMBER_OF_ERROR_CODES = 17,
  125. ///< Number of possible error codes.
  126. } nrf_gzll_error_code_t;
  127. /**
  128. * @struct nrf_gzll_device_tx_info_t;
  129. * @brief Data structure containing information about the last packet
  130. * transmission.
  131. */
  132. typedef struct
  133. {
  134. bool payload_received_in_ack;
  135. ///< A payload was received in the ACK.
  136. uint16_t num_tx_attempts;
  137. ///< Number of attempts used on previous Device packet transmission.
  138. uint16_t num_channel_switches;
  139. ///< Number of channel switches needed during previous packet transmission.
  140. int16_t rssi;
  141. ///< Received signal strength indicator in dBm. @sa nrf_gzll_enable_rssi().
  142. } nrf_gzll_device_tx_info_t;
  143. /**
  144. * @struct nrf_gzll_host_rx_info_t;
  145. * @brief Data structure containing information about the last packet
  146. * received.
  147. */
  148. typedef struct
  149. {
  150. bool packet_removed_from_tx_fifo;
  151. ///< A payload was received in the ACK.
  152. int16_t rssi;
  153. ///< Received signal strength indicator in dBm. @sa nrf_gzll_enable_rssi().
  154. } nrf_gzll_host_rx_info_t;
  155. /******************************************************************************/
  156. /** @name General API functions
  157. * @{ */
  158. /******************************************************************************/
  159. /**
  160. * @brief Initialize Gazell.
  161. *
  162. * @param mode The mode to initialize Gazell in.
  163. *
  164. * @retval true if Gazell initialized.
  165. * @retval false if Gazell failed to initialize.
  166. */
  167. bool nrf_gzll_init(nrf_gzll_mode_t mode);
  168. /**
  169. * @brief Enable Gazell.
  170. *
  171. * When enabled the behaviour described for the current Gazell Link Layer mode
  172. * will apply.
  173. *
  174. * @retval false if nrf_gzll_init has not previously been called.
  175. */
  176. bool nrf_gzll_enable(void);
  177. /**
  178. * @brief Disable Gazell.
  179. *
  180. * When calling this function the Gazell Link Layer will begin disabling,
  181. * and will be fully disabled when Gazell calls nrf_gzll_disabled().
  182. * If there are any pending notifications, or if any new notifications are
  183. * being added to the internal notification queue while Gazell is disabling,
  184. * these will be sent to the application before Gazell is fully disabled.
  185. *
  186. * After Gazell has been fully disabled, no more notifications will be sent to
  187. * the application.
  188. */
  189. void nrf_gzll_disable(void);
  190. /** Check whether Gazell is enabled or disabled.
  191. *
  192. * @retval true If Gazell is enabled.
  193. * @retval false If Gazell is disabled.
  194. */
  195. bool nrf_gzll_is_enabled(void);
  196. /** @} */
  197. /******************************************************************************/
  198. /** @name Device mode callback functions
  199. * @{ */
  200. /******************************************************************************/
  201. /**
  202. * @brief ACK received callback (Device mode only).
  203. *
  204. * This callback is made when the Device receives an ACK (acknowledgement)
  205. * packet.
  206. * @sa nrf_gzll_ack_payload_received.
  207. *
  208. * @param pipe is the pipe on which an ACK packet was received.
  209. * @param tx_info struct used to indicate whether a payload was received in the
  210. * ack, as well as the number of TX attempts and channel switches required.
  211. */
  212. void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info);
  213. /**
  214. * @brief Transmission failed callback (Device mode only).
  215. *
  216. * This callback is made when a packet does not receive an ACK after
  217. * nrf_gzll_max_retries is reached. The packet is deleted by Gazell.
  218. *
  219. * @param pipe is the pipe on which the transmission failed.
  220. * @param tx_info struct used to indicate whether a payload was received
  221. * in the ack, as well as RSSI and the number of TX attempts and
  222. * channel switches required.
  223. */
  224. void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info);
  225. /** @} */
  226. /******************************************************************************/
  227. /** @name Host mode callback functions
  228. * @{ */
  229. /******************************************************************************/
  230. /**
  231. * @brief Data packet received callback (Host mode only).
  232. *
  233. * This callback is made when a Host receives a data packet from a Device.
  234. *
  235. * @param pipe is the pipe on which the data packet was received.
  236. * @param rx_info struct used to indicate whether a payload was removed from the
  237. * pipe's TX FIFO, as well as RSSI.
  238. */
  239. void nrf_gzll_host_rx_data_ready(uint32_t pipe, nrf_gzll_host_rx_info_t rx_info);
  240. /** @} */
  241. /******************************************************************************/
  242. /** @name Callback functions for both Device and Host mode
  243. * @{ */
  244. /******************************************************************************/
  245. /**
  246. * @brief Disabled callback.
  247. *
  248. * This is called after Gazell enters the disabled state.
  249. * There is no further CPU use by Gazell, the radio is disabled and the timer is
  250. * powered down.
  251. */
  252. void nrf_gzll_disabled(void);
  253. /**
  254. * @brief Mode changed callbackl.
  255. *
  256. * This function is called after the Gazell mode has been changed.
  257. * This function can only be called when Gazell is enabled.
  258. */
  259. void nrf_gzll_mode_changed(void);
  260. /** @} */
  261. /******************************************************************************/
  262. /** @name Packet transmission and receiving functions
  263. * @{ */
  264. /******************************************************************************/
  265. /**
  266. * @brief Add a packet to the tail of the TX FIFO.
  267. *
  268. * In Device mode, the packet will be added.
  269. * In Host mode, the payload will be piggybacked onto an ACK.
  270. *
  271. * @param pipe Pipe to which to add the payload. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  272. * @param payload Pointer to the payload.
  273. * @param length Number of bytes of the payload to transmit
  274. * (0 to NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH).
  275. *
  276. * @retval true if the packet was successfully added to the TX FIFO.
  277. * @retval false if unsuccessful, check nrf_gzll_error_code_t for more information.
  278. */
  279. bool nrf_gzll_add_packet_to_tx_fifo(uint32_t pipe, uint8_t * payload, uint32_t length);
  280. /**
  281. * @brief Fetch a packet from the head of the RX FIFO.
  282. *
  283. * @param pipe Pipe from which to fetch the payload. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  284. * @param payload Pointer to copy the payload to.
  285. * @param length Length must be at least as large as the the number of bytes
  286. * in the received payload length.
  287. *
  288. * @retval true If the fetch was successful.
  289. * @retval false If unsuccessful, check nrf_gzll_error_code_t for more information.
  290. */
  291. bool nrf_gzll_fetch_packet_from_rx_fifo(uint32_t pipe, uint8_t * payload, uint32_t* length);
  292. /**
  293. * @brief Get the number of packets in the TX FIFO on a specific pipe.
  294. *
  295. * @param pipe The pipe for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  296. *
  297. * @retval >=0 The number of packets in the TX FIFO for the pipe.
  298. * @retval -1 If the pipe number is invalid.
  299. */
  300. int32_t nrf_gzll_get_tx_fifo_packet_count(uint32_t pipe);
  301. /**
  302. * @brief Get the number of packets in the RX FIFO on a specific pipe.
  303. *
  304. * @param pipe The pipe for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  305. * @retval >=0 The number of packets in the RX FIFO for the pipe.
  306. * @retval -1 If the pipe number is invalid.
  307. */
  308. int32_t nrf_gzll_get_rx_fifo_packet_count(uint32_t pipe);
  309. /**
  310. * @brief Get the total number of packets residing in all TX and RX FIFOs.
  311. *
  312. * Can be used to check against NRF_GZLL_CONST_MAX_TOTAL_PACKETS to
  313. * determine if there is free space in the memory pool for more packets.
  314. *
  315. * @return The number of packets residing in all TX and RX FIFOs.
  316. */
  317. uint32_t nrf_gzll_get_total_allocated_packet_count(void);
  318. /**
  319. * @brief Check if adding a packet to a pipe's TX FIFO should be successful.
  320. *
  321. * Checks if there is another space in the pipe's TX and RX FIFOs
  322. * as well as enough overall space in the packet pool.
  323. *
  324. * @param pipe The pip for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  325. *
  326. * @retval true If there is another space.
  327. * @retval false If there is not enough space, or the pipe is invalid.
  328. */
  329. bool nrf_gzll_ok_to_add_packet_to_tx_fifo(uint32_t pipe);
  330. /**
  331. * @brief Flush the RX FIFO for a specific pipe.
  332. *
  333. * Delete all the packets and free the memory of the TX FIFO for a
  334. * specific pipe.
  335. *
  336. * Note that it is not allowed to flush a TX FIFO when
  337. * Gazell is enabled.
  338. *
  339. * @param pipe is the pipe for which to flush. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  340. * @retval true if the pipe was flushed.
  341. * @retval false if the pipe was not flushed.
  342. */
  343. bool nrf_gzll_flush_tx_fifo(uint32_t pipe);
  344. /**
  345. * @brief Flush the RX FIFO for a specific pipe.
  346. *
  347. * Delete all the packets and free the memory of the RX FIFO for a
  348. * specific pipe.
  349. *
  350. * @param pipe is the pipe for which to flush. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  351. * @retval true if the pipe was flushed.
  352. * @retval false if the pipe was not flushed.
  353. */
  354. bool nrf_gzll_flush_rx_fifo(uint32_t pipe);
  355. /** @} */
  356. /******************************************************************************/
  357. /** @name Configuration functions
  358. *
  359. * Configuration 'set' functions may only be called while Gazell is disabled. The
  360. * new parameter comes into effect when Gazell is enabled again.
  361. *
  362. * Configuration 'get' functions may be called at any time.
  363. *
  364. * @{ */
  365. /******************************************************************************/
  366. /**
  367. * @brief Set the mode.
  368. *
  369. * @param mode The mode to be used.
  370. * See nrf_gzll_mode_t for a list of valid modes.
  371. *
  372. * It is allowed to change mode when Gazell is enabled. If the mode is
  373. * being changed while Gazell is enabled, the mode will not change right away.
  374. * In this case the callback function nrf_gzll_mode_changed() will be called
  375. * after the mdoe has changed.
  376. *
  377. * @retval true If the parameter was set.
  378. */
  379. bool nrf_gzll_set_mode(nrf_gzll_mode_t mode);
  380. /**
  381. * @brief Get function counterpart to nrf_gzll_set_mode().
  382. *
  383. * @return The current mode.
  384. */
  385. nrf_gzll_mode_t nrf_gzll_get_mode(void);
  386. /**
  387. * @brief Set the base address for pipe 0.
  388. *
  389. * The full on-air address for each pipe is composed of a multi-byte base address
  390. * prepended to a prefix byte.
  391. *
  392. * For packets to be received correctly, the most significant byte of
  393. * the base address should not be an alternating sequence of 0s and 1s i.e.
  394. * it should not be 0x55 or 0xAA.
  395. *
  396. * @param base_address The 4 byte base address. All bytes are used.
  397. *
  398. * @retval true If the parameter was set.
  399. * @return false If Gazell was enabled.
  400. */
  401. bool nrf_gzll_set_base_address_0(uint32_t base_address);
  402. /**
  403. * @brief Get function counterpart to nrf_gzll_set_base_address_0().
  404. *
  405. * @return Base address 0.
  406. */
  407. uint32_t nrf_gzll_get_base_address_0(void);
  408. /**
  409. * @brief Set the base address for pipes 1-7.
  410. *
  411. * Pipes 1 through 7 share base_address_1. @sa nrf_gzll_set_base_address_0.
  412. *
  413. * @param base_address The 4 byte base address.
  414. *
  415. * @retval true If the parameter was set.
  416. * @retval false If Gazell was enabled.
  417. */
  418. bool nrf_gzll_set_base_address_1(uint32_t base_address);
  419. /**
  420. * @brief Get function counterpart to nrf_gzll_set_base_address_1().
  421. *
  422. * @return Base address 1.
  423. */
  424. uint32_t nrf_gzll_get_base_address_1(void);
  425. /**
  426. * @brief Set the address prefix byte for a specific pipe.
  427. *
  428. * Each pipe should have its own unique prefix byte.
  429. *
  430. * @param pipe The pipe that the address should apply to.
  431. * This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  432. * @param address_prefix_byte The address prefix byte.
  433. *
  434. * @retval true If the parameter was set.
  435. * @retval false If Gazell was enabled, or if the pipe was invalid.
  436. */
  437. bool nrf_gzll_set_address_prefix_byte(uint32_t pipe, uint8_t address_prefix_byte);
  438. /**
  439. * @brief Get function counterpart to nrf_gzll_set_address_prefix_byte().
  440. *
  441. * @param pipe The pipe for which to get the address.
  442. * This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  443. * @param out_address_prefix_byte The pointer in which to return the
  444. * address prefix byte.
  445. *
  446. * @retval true If the parameter was returned.
  447. * @retval false If Gazell was enabled, the pipe was invalid or
  448. * out_address was a NULL pointer.
  449. */
  450. bool nrf_gzll_get_address_prefix_byte(uint32_t pipe, uint8_t* out_address_prefix_byte);
  451. /**
  452. * @brief Set which pipes shall listen for packets in Host mode.
  453. *
  454. * This value is a bitmap, and each bit corresponds to a given pipe number.
  455. * Bit 0 set to "1" enables pipes 0, bit 1 set to "1" enables pipe 1
  456. * and so forth.
  457. * The maximum number of pipes is defined by NRF_GZLL_CONST_PIPE_COUNT.
  458. *
  459. * @param pipes A bitmap specifying which pipes to monitor.
  460. *
  461. * @retval true If the parameter was set.
  462. * @retval false If Gazell was enabled.
  463. */
  464. bool nrf_gzll_set_rx_pipes_enabled(uint32_t pipes);
  465. /**
  466. * @brief Get function counterpart to nrf_gzll_set_rx_pipes_enabled().
  467. *
  468. * @return Bitmap holding the current enabled pipes.
  469. */
  470. uint32_t nrf_gzll_get_rx_pipes_enabled(void);
  471. /**
  472. * @brief Set the timeslot period.
  473. *
  474. * The length in microseconds of a Gazell link layer timeslot.
  475. *
  476. * The minimum value of the timeslot period is dependent of the
  477. * radio data rate (@sa nrf_gzll_set_datarate()).
  478. *
  479. * - For NRF_GZLL_DATARATE_2MBIT the timeslot period must be >= 600 us.
  480. * - For NRF_GZLL_DATARATE_1MBIT the timeslot period must be >= 900 us.
  481. * - For NRF_GZLL_DATARATE_250KBIT the timeslot period must be >= 2700 us.
  482. *
  483. * @param period_us The timeslot period in microseconds.
  484. *
  485. * @retval true If the parameter was set.
  486. * @retval false If Gazell was enabled.
  487. */
  488. bool nrf_gzll_set_timeslot_period(uint32_t period_us);
  489. /**
  490. * @brief Get function counterpart to nrf_gzll_get_timeslot_period().
  491. *
  492. * @return The current timeslot period.
  493. */
  494. uint32_t nrf_gzll_get_timeslot_period(void);
  495. /**
  496. * @brief Set the Device channel selection policy
  497. *
  498. * The policy determines the initial channel when starting a new packet.
  499. * transmission.
  500. *
  501. * @param policy The channel selection policy.
  502. *
  503. * @arg NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_SUCCESSFUL specifies
  504. * that a new packet transmission always shall use the previous
  505. * successful channel from the channel table. If Gazell is "in sync", Gazell
  506. * will wait until this channel is being monitored by the Host before starting
  507. * the transmission.
  508. *
  509. * @arg NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT specifies that
  510. * Gazell shall transmit on the channel that is currently being monitored by the
  511. * Host. This parameter is only used when Gazell is "in sync". When "out of" sync,
  512. * Gazell will always start using the "previous successful" channel.
  513. *
  514. * @retval true If the parameter was set.
  515. * @retval false If Gazell was enabled or the policy was invalid.
  516. */
  517. bool nrf_gzll_set_device_channel_selection_policy(nrf_gzll_device_channel_selection_policy_t policy);
  518. /**
  519. * @brief Get function counterpart to nrf_gzll_set_device_channel_selection_policy().
  520. *
  521. * @return the Device channel selection policy.
  522. */
  523. nrf_gzll_device_channel_selection_policy_t nrf_gzll_get_device_channel_selection_policy(void);
  524. /**
  525. * @brief Set the number of timeslots that Gazell shall
  526. * reside on a single channel before switching to another channel.
  527. *
  528. * This parameter applies in Host mode and for a Device that is
  529. * in the "in sync" state.
  530. *
  531. * Since the Device and Host can not be in perfect synchronization, a
  532. * transmission should overlap to adjacent timeslots on the Host.
  533. * Therefore this value should be at least 2.
  534. *
  535. * @sa nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync
  536. *
  537. * @param timeslots The number of timeslots to reside on
  538. * each channel before channel switch.
  539. *
  540. * @retval true If the parameter was set.
  541. * @retval false If Gazell was enabled.
  542. */
  543. bool nrf_gzll_set_timeslots_per_channel(uint32_t timeslots);
  544. /**
  545. * @brief Get function counterpart to nrf_gzll_set_timeslots_per_channel().
  546. *
  547. * @return The current number of timeslots.
  548. */
  549. uint32_t nrf_gzll_get_timeslots_per_channel(void);
  550. /**
  551. * @brief Set the number of timeslots that a Gazell shall
  552. * reside on a single channel before switching to another channel when
  553. * in the "out of sync" state.
  554. *
  555. * This value should be set so that the Device transmits on one channel
  556. * while the Host goes through a full channel rotation, i.e.,
  557. * channel_table_size*timeslots_per_channel.
  558. * This ensures that the channels on the Device and Host will coincide
  559. * at some point.
  560. * Further increasing the value has been observed to provide better performance
  561. * in the presence of interferers.
  562. *
  563. * @param timeslots The number of timeslots to reside on
  564. * each channel before channel switch.
  565. *
  566. * @retval true If the parameter was set.
  567. * @retval false If Gazell was enabled.
  568. */
  569. bool nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync(uint32_t timeslots);
  570. /**
  571. * @brief Get function counterpart to
  572. * nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync().
  573. *
  574. * @return The current number of timeslots.
  575. */
  576. uint32_t nrf_gzll_get_timeslots_per_channel_when_device_out_of_sync(void);
  577. /**
  578. * @brief Set the number of timeslots after a successful
  579. * reception of a Device or Host packet that the Gazell Link Layer shall assume
  580. * that the link is synchronized. A value of 0 implies that the
  581. * link is always out of sync.
  582. *
  583. * @param lifetime The sync lifetime in number of timeslots.
  584. *
  585. * @retval true If the sync lifetime was set.
  586. * @retval false If Gazell was enabled.
  587. */
  588. bool nrf_gzll_set_sync_lifetime(uint32_t lifetime);
  589. /**
  590. * @brief Get function counterpart to nrf_gzll_set_sync_lifetime().
  591. *
  592. * @return The sync lifetime measured in number of timeslots.
  593. */
  594. uint32_t nrf_gzll_get_sync_lifetime(void);
  595. /**
  596. * @brief Set the maximum number of TX attempts
  597. * that can be used for a single packet.
  598. *
  599. * After the maximum number of attempts have been spent without
  600. * receiving any ACK from the Host, the transmission will be terminated
  601. * and the nrf_gzll_device_tx_failed() callback will be called.
  602. *
  603. * @param max_tx_attempts The maximum number of TX attempts.
  604. *
  605. * @retval true If the parameter was set.
  606. * @retval false If Gazell was enabled.
  607. */
  608. bool nrf_gzll_set_max_tx_attempts(uint16_t max_tx_attempts);
  609. /**
  610. * @brief Get function counterpart to nrf_gzll_set_max_tx_attempts().
  611. *
  612. * @return The current max Device TX attempts.
  613. */
  614. uint16_t nrf_gzll_get_max_tx_attempts(void);
  615. /**
  616. * @brief Set the table of Radio Frequency (RF) channels.
  617. *
  618. * The valid channels are in the range 0 <= channel <= 125, where the
  619. * actual centre frequency is (2400 + channel) MHz.
  620. * The maximum channel table size is defined by
  621. * NRF_GZLL_CONST_MAX_CHANNEL_TABLE_SIZE.
  622. *
  623. * @param channel_table Pointer to the channel table.
  624. * @param size The size of the channel table.
  625. *
  626. * @retval true If the channel table was set.
  627. * @retval false If Gazell was enabled, or the channel_table pointer was NULL,
  628. * or the size was invalid.
  629. */
  630. bool nrf_gzll_set_channel_table(uint8_t* channel_table, uint32_t size);
  631. /**
  632. * @brief Get the table of Radio Frequency (RF) channels.
  633. *
  634. * @param channel_table Pointer to copy the channel table to.
  635. * @param size Pointer to copy the size of the channel table to.
  636. * The value already at size must be at least the size
  637. * of the channel table.
  638. *
  639. * @retval true If the channel table was copied to channel_table.
  640. * @retval false If the channel_table pointer was NULL,
  641. * or the size was not large enough.
  642. */
  643. bool nrf_gzll_get_channel_table(uint8_t* channel_table, uint32_t* size);
  644. /**
  645. * @brief Get the current channel table size.
  646. *
  647. * @return The current channel table size.
  648. */
  649. uint32_t nrf_gzll_get_channel_table_size(void);
  650. /**
  651. * @brief Set the radio TX power.
  652. *
  653. * @param tx_power TX power.
  654. *
  655. * @retval true If the parameter was set.
  656. * @retval false If Gazell was enabled or the TX power was invalid.
  657. */
  658. bool nrf_gzll_set_tx_power(nrf_gzll_tx_power_t tx_power);
  659. /**
  660. * @brief Get function counterpart to nrf_gzll_set_tx_power().
  661. *
  662. * @return The current TX power.
  663. */
  664. nrf_gzll_tx_power_t nrf_gzll_get_tx_power(void);
  665. /**
  666. * @brief Set the radio datarate.
  667. *
  668. * @param data_rate Datarate.
  669. *
  670. * @retval true If the parameter was set.
  671. * @retval false If Gazell was enabled or the datarate was invalid.
  672. */
  673. bool nrf_gzll_set_datarate(nrf_gzll_datarate_t data_rate);
  674. /**
  675. * @brief Get function counterpart to nrf_gzll_set_datarate().
  676. *
  677. * @return The current datarate.
  678. */
  679. nrf_gzll_datarate_t nrf_gzll_get_datarate(void);
  680. /**
  681. * @brief Set whether start/stop of external oscillator (XOSC) shall be handled
  682. * automatically inside Gazell or manually by the application.
  683. *
  684. * When controlling the XOSC manually from the application it is
  685. * required that the XOSC is started before Gazell is enabled.
  686. *
  687. * When start/stop of the XOSC is handled automatically by Gazell,
  688. * the XOSC will only be running when needed, that is when the radio
  689. * is being used or when Gazell needs to maintain synchronization.
  690. *
  691. * It is required that the XOSC is started in order for the radio to be
  692. * able to send or receive any packets.
  693. *
  694. * @param xosc_ctl setting for XOSC control.
  695. *
  696. * @retval true if the parameter was set.
  697. * @retval false if Gazell was enabled or the xosc_ctl value was invalid.
  698. */
  699. bool nrf_gzll_set_xosc_ctl(nrf_gzll_xosc_ctl_t xosc_ctl);
  700. /**
  701. * Get function counterpart for nrf_gzll_set_xosc_ctl();
  702. *
  703. * @return The XOSC control setting.
  704. */
  705. nrf_gzll_xosc_ctl_t nrf_gzll_get_xosc_ctl(void);
  706. /**
  707. * @brief Set Gazell to disable automatically after a certain number of timeslot ticks.
  708. *
  709. * @param num_ticks Number of timeslot ticks.
  710. *
  711. */
  712. void nrf_gzll_set_auto_disable(uint32_t num_ticks);
  713. /**
  714. * @brief Get the number of timeslot ticks that have occurred since
  715. * nrf_gzll_init() was called.
  716. *
  717. * @return Number of timeslot ticks.
  718. *
  719. */
  720. uint32_t nrf_gzll_get_tick_count(void);
  721. /**
  722. * @brief Clear the internal timeslot tick count variable that is read
  723. * by nrf_gzll_get_tick_count().
  724. *
  725. */
  726. void nrf_gzll_clear_tick_count(void);
  727. /** @} */
  728. /******************************************************************************/
  729. /** @name Error handling functions
  730. * @{ */
  731. /******************************************************************************/
  732. /**
  733. * @brief Gets the Gazell error code.
  734. *
  735. * @return The current error code.
  736. */
  737. nrf_gzll_error_code_t nrf_gzll_get_error_code(void);
  738. /**
  739. * @brief Reset the Gazell error code.
  740. *
  741. * The error code is reset to NRF_GZLL_ERROR_CODE_NO_ERRROR.
  742. */
  743. void nrf_gzll_reset_error_code(void);
  744. /** @} */
  745. /** @} */
  746. #endif