nrf_gzll.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. /**
  2. * Copyright (c) 2012 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /**
  41. * @file
  42. * @brief Gazell Link Layer API.
  43. */
  44. #ifndef NRF_GZLL_H__
  45. #define NRF_GZLL_H__
  46. #include <stdbool.h>
  47. #include "nrf.h"
  48. #include "nrf_gzll_constants.h"
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /**
  53. * @defgroup gzll_02_api Gazell Link Layer
  54. * @{
  55. * @ingroup modules_01_gzll
  56. * @brief Gazell Link Layer Application Programming Interface (API).
  57. */
  58. /**
  59. * @enum nrf_gzll_mode_t
  60. * @brief Enumerator used for selecting Gazell mode.
  61. */
  62. typedef enum
  63. {
  64. NRF_GZLL_MODE_DEVICE, ///< Device mode
  65. NRF_GZLL_MODE_HOST, ///< Host mode
  66. NRF_GZLL_MODE_SUSPEND, ///< Suspend mode ("disabled with timer running")
  67. } nrf_gzll_mode_t;
  68. /**
  69. * @enum nrf_gzll_device_channel_selection_policy_t
  70. * @brief Enumerator used for selecting Gazell Device channel
  71. * selection policy.
  72. */
  73. typedef enum
  74. {
  75. NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_SUCCESSFUL, ///< Start on previous successful channel
  76. NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT, ///< Start on channel currently monitored by Host
  77. } nrf_gzll_device_channel_selection_policy_t;
  78. /**
  79. * @enum nrf_gzll_tx_power_t
  80. * @brief Enumerator used for selecting the transmit (TX) power.
  81. */
  82. typedef enum
  83. {
  84. NRF_GZLL_TX_POWER_4_DBM, ///< 4 dBm transmit power.
  85. NRF_GZLL_TX_POWER_0_DBM, ///< 0 dBm transmit power.
  86. NRF_GZLL_TX_POWER_N4_DBM, ///< -4 dBm transmit power.
  87. NRF_GZLL_TX_POWER_N8_DBM, ///< -8 dBm transmit power.
  88. NRF_GZLL_TX_POWER_N12_DBM, ///< -12 dBm transmit power.
  89. NRF_GZLL_TX_POWER_N16_DBM, ///< -16 dBm transmit power.
  90. NRF_GZLL_TX_POWER_N20_DBM ///< -20 dBm transmit power.
  91. } nrf_gzll_tx_power_t;
  92. /**
  93. * @enum nrf_gzll_datarate_t
  94. * @brief Enumerator used for selecting the radio datarate.
  95. */
  96. typedef enum
  97. {
  98. #ifdef NRF51
  99. NRF_GZLL_DATARATE_250KBIT = 0, ///< 250 Kbps datarate, available only for the nRF51.
  100. #endif
  101. NRF_GZLL_DATARATE_1MBIT = 1, ///< 1 Mbps datarate.
  102. NRF_GZLL_DATARATE_2MBIT = 2 ///< 2 Mbps datarate.
  103. } nrf_gzll_datarate_t;
  104. /**
  105. * @enum nrf_gzll_xosc_ctl_t
  106. * @brief Enumerator used for specifying whether switching the
  107. * external 16 MHz oscillator on/off shall be handled automatically
  108. * inside Gazell or manually by the application.
  109. */
  110. typedef enum
  111. {
  112. NRF_GZLL_XOSC_CTL_AUTO, ///< Switch XOSC on/off automatically
  113. NRF_GZLL_XOSC_CTL_MANUAL ///< Switch XOSC on/off manually
  114. } nrf_gzll_xosc_ctl_t;
  115. /**
  116. * @enum nrf_gzll_error_code_t
  117. * @brief Enumerator used for error codes for Gazell API functions
  118. */
  119. typedef enum
  120. {
  121. NRF_GZLL_ERROR_CODE_NO_ERROR = 0, ///< No error has been detected.
  122. NRF_GZLL_ERROR_CODE_FAILED_TO_INITIALIZE = 1, ///< The function NRF_GZLL_init failed.
  123. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_CONFIGURE_WHEN_ENABLED = 2, ///< A call to a configuration 'set' function was made while Gazell was enabled.
  124. NRF_GZLL_ERROR_CODE_POINTER_IS_NULL = 3, ///< A null pointer was given as an input to a function.
  125. NRF_GZLL_ERROR_CODE_INVALID_PIPE = 4, ///< An invalid pipe number was given as an input to a function.
  126. NRF_GZLL_ERROR_CODE_INVALID_MODE = 5, ///< An invalid value for the nrf_gzll_mode_t enumerator was given as input to a function.
  127. NRF_GZLL_ERROR_CODE_INVALID_PAYLOAD_LENGTH = 6, ///< An invalid payload length was given as an input to a function.
  128. NRF_GZLL_ERROR_CODE_INVALID_CHANNEL_TABLE_SIZE = 7, ///< An invalid channel table size was given as an input to a function.
  129. NRF_GZLL_ERROR_CODE_INSUFFICIENT_PACKETS_AVAILABLE = 8, ///< There are insufficient packets in the Gazell memory pool to successfully execute the operation.
  130. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_ADD_TO_FULL_FIFO = 9, ///< There is insufficient space in the TX FIFO for the data packet.
  131. NRF_GZLL_ERROR_CODE_NO_SPACE_IN_RX_FIFO_FOR_ACK = 10, ///< There is insufficient space in the RX FIFO for the ACK.
  132. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_FETCH_FROM_EMPTY_FIFO = 11, ///< 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()
  133. NRF_GZLL_ERROR_CODE_ATTEMPTED_TO_FLUSH_WHEN_ENABLED = 12, ///< 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()
  134. NRF_GZLL_ERROR_CODE_INVALID_PARAMETER = 14, ///< Attempted to set a variable which was not valid.
  135. NRF_GZLL_ERROR_CODE_INTERNAL_ASSERT_OCCURRED = 15, ///< An internal assert occurred.
  136. NRF_GZLL_ERROR_CODE_CALLBACK_NOT_IMPLEMENTED = 16, ///< A callback was called but not implemented by the application.
  137. NRF_GZLL_ERROR_CODE_INVALID_ADDRESS = 17, ///< Invalid pipe 0 address detected, see Anomaly 107 at nRF52832 errata document.
  138. NRF_GZLL_ERROR_CODE_NUMBER_OF_ERROR_CODES = 18, ///< Number of possible error codes.
  139. } nrf_gzll_error_code_t;
  140. /**
  141. * @struct nrf_gzll_device_tx_info_t;
  142. * @brief Data structure containing information about the last packet
  143. * transmission.
  144. */
  145. typedef struct
  146. {
  147. bool payload_received_in_ack; ///< A payload was received in the ACK.
  148. uint16_t num_tx_attempts; ///< Number of attempts used on previous Device packet transmission.
  149. uint16_t num_channel_switches; ///< Number of channel switches needed during previous packet transmission.
  150. int8_t rssi; ///< Received signal strength indicator in dBm. @sa nrf_gzll_enable_rssi().
  151. uint8_t rf_channel; ///< Channel on which packet has been transmitted.
  152. } nrf_gzll_device_tx_info_t;
  153. /**
  154. * @struct nrf_gzll_host_rx_info_t;
  155. * @brief Data structure containing information about the last packet
  156. * received.
  157. */
  158. typedef struct
  159. {
  160. bool packet_removed_from_tx_fifo; ///< A payload was received in the ACK.
  161. int8_t rssi; ///< Received signal strength indicator in dBm. @sa nrf_gzll_enable_rssi().
  162. uint8_t rf_channel; ///< Channel on which packet has been received.
  163. } nrf_gzll_host_rx_info_t;
  164. typedef struct
  165. {
  166. uint32_t packets_num; ///< Number of succesfully transmitted packets
  167. uint32_t timeouts_num; ///< Total timeouts number
  168. uint32_t channel_timeouts[NRF_GZLL_CONST_MAX_CHANNEL_TABLE_SIZE]; ///< Transmission timeouts per channel
  169. uint32_t channel_packets[NRF_GZLL_CONST_MAX_CHANNEL_TABLE_SIZE]; ///< Succesfully transmitted packets per channel
  170. } nrf_gzll_tx_statistics_t;
  171. /**< Transmission timeout callback function definition */
  172. typedef void (*nrf_gzll_tx_timeout_callback)(uint32_t pipe, uint8_t rf_channel);
  173. /**< Transmission CRC failure callback function definition */
  174. typedef void (*nrf_gzll_crc_failure_callback)(uint32_t pipe, uint8_t rf_channel);
  175. #if defined(NRF52_SERIES) || defined(__SDK_DOXYGEN__)
  176. /**
  177. * @brief Data structure holding external front
  178. * end control configuration.
  179. */
  180. typedef struct
  181. {
  182. bool pa_enabled; ///< Flag indicating if PA control is enabled.
  183. bool pa_active_high; ///< Flag indicating if PA is active in high input state.
  184. uint8_t pa_gpio_pin; ///< Number of output pin used for PA control.
  185. uint8_t pa_gpiote_channel; ///< Number of GPIOTE channel used for PA control.
  186. bool lna_enabled; ///< Flag indicating if LNA control is enabled.
  187. bool lna_active_high; ///< Flag indicating if LNA is active in high input state.
  188. uint8_t lna_gpio_pin; ///< Number of output pin used for LNA control.
  189. uint8_t lna_gpiote_channel; ///< Number of GPIOTE channel used for LNA control.
  190. NRF_TIMER_Type * timer; ///< Pointer to the TIMER instance.
  191. uint8_t ppi_channels[NRF_GZLL_PA_LNA_PPI_CHANNELS_NUM]; ///< PPI channels used to control front end.
  192. uint8_t ramp_up_time; ///< Determines how early should the PA/LNA be turned one before RADIO activity. Should be less than @ref NRF_GZLL_PA_LNA_MAX_RAMP_UP_TIME.
  193. } nrf_gzll_pa_lna_cfg_t;
  194. #endif
  195. /******************************************************************************/
  196. /** @name General API functions
  197. * @{ */
  198. /******************************************************************************/
  199. /**
  200. * @brief Initialize Gazell.
  201. *
  202. * @param mode The mode to initialize Gazell in.
  203. *
  204. * @retval true if Gazell initialized.
  205. * @retval false if Gazell failed to initialize.
  206. */
  207. bool nrf_gzll_init(nrf_gzll_mode_t mode);
  208. /**
  209. * @brief Enable Gazell.
  210. *
  211. * When enabled the behaviour described for the current Gazell Link Layer mode
  212. * will apply.
  213. *
  214. * @retval false if nrf_gzll_init has not previously been called or invalid address
  215. * has been set - see Anomaly 107 at nRF52832 errata document.
  216. */
  217. bool nrf_gzll_enable(void);
  218. /**
  219. * @brief Disable Gazell.
  220. *
  221. * When calling this function the Gazell Link Layer will begin disabling,
  222. * and will be fully disabled when Gazell calls nrf_gzll_disabled().
  223. * If there are any pending notifications, or if any new notifications are
  224. * being added to the internal notification queue while Gazell is disabling,
  225. * these will be sent to the application before Gazell is fully disabled.
  226. *
  227. * After Gazell has been fully disabled, no more notifications will be sent to
  228. * the application.
  229. */
  230. void nrf_gzll_disable(void);
  231. /** Check whether Gazell is enabled or disabled.
  232. *
  233. * @retval true If Gazell is enabled.
  234. * @retval false If Gazell is disabled.
  235. */
  236. bool nrf_gzll_is_enabled(void);
  237. /** @} */
  238. /******************************************************************************/
  239. /** @name Device mode callback functions
  240. * @{ */
  241. /******************************************************************************/
  242. /**
  243. * @brief ACK received callback (Device mode only).
  244. *
  245. * This callback is made when the Device receives an ACK (acknowledgement)
  246. * packet.
  247. * @sa nrf_gzll_ack_payload_received.
  248. *
  249. * @param pipe is the pipe on which an ACK packet was received.
  250. * @param tx_info struct used to indicate whether a payload was received in the
  251. * ack, as well as the number of TX attempts and channel switches required.
  252. */
  253. void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info);
  254. /**
  255. * @brief Transmission failed callback (Device mode only).
  256. *
  257. * This callback is made when a packet does not receive an ACK after
  258. * nrf_gzll_max_retries is reached. The packet is deleted by Gazell.
  259. *
  260. * @param pipe is the pipe on which the transmission failed.
  261. * @param tx_info struct used to indicate whether a payload was received
  262. * in the ack, as well as RSSI and the number of TX attempts and
  263. * channel switches required.
  264. */
  265. void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info);
  266. /** @} */
  267. /******************************************************************************/
  268. /** @name Host mode callback functions
  269. * @{ */
  270. /******************************************************************************/
  271. /**
  272. * @brief Data packet received callback (Host mode only).
  273. *
  274. * This callback is made when a Host receives a data packet from a Device.
  275. *
  276. * @param pipe is the pipe on which the data packet was received.
  277. * @param rx_info struct used to indicate whether a payload was removed from the
  278. * pipe's TX FIFO, as well as RSSI.
  279. */
  280. void nrf_gzll_host_rx_data_ready(uint32_t pipe, nrf_gzll_host_rx_info_t rx_info);
  281. /** @} */
  282. /******************************************************************************/
  283. /** @name Callback functions for both Device and Host mode
  284. * @{ */
  285. /******************************************************************************/
  286. /**
  287. * @brief Disabled callback.
  288. *
  289. * This is called after Gazell enters the disabled state.
  290. * There is no further CPU use by Gazell, the radio is disabled and the timer is
  291. * powered down.
  292. */
  293. void nrf_gzll_disabled(void);
  294. /**
  295. * @brief Mode changed callbackl.
  296. *
  297. * This function is called after the Gazell mode has been changed.
  298. * This function can only be called when Gazell is enabled.
  299. */
  300. void nrf_gzll_mode_changed(void);
  301. /** @} */
  302. /******************************************************************************/
  303. /** @name Packet transmission and receiving functions
  304. * @{ */
  305. /******************************************************************************/
  306. /**
  307. * @brief Add a packet to the tail of the TX FIFO.
  308. *
  309. * In Device mode, the packet will be added.
  310. * In Host mode, the payload will be piggybacked onto an ACK.
  311. *
  312. * @param pipe Pipe to which to add the payload. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  313. * @param p_payload Pointer to the payload.
  314. * @param length Number of bytes of the payload to transmit
  315. * (0 to NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH).
  316. *
  317. * @retval true if the packet was successfully added to the TX FIFO.
  318. * @retval false if unsuccessful, check nrf_gzll_error_code_t for more information.
  319. */
  320. bool nrf_gzll_add_packet_to_tx_fifo(uint32_t pipe, uint8_t * p_payload, uint32_t length);
  321. /**
  322. * @brief Fetch a packet from the head of the RX FIFO.
  323. *
  324. * @param pipe Pipe from which to fetch the payload. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  325. * @param p_payload Pointer to copy the payload to.
  326. * @param p_length Length must be at least as large as the the number of bytes
  327. * in the received payload length.
  328. *
  329. * @retval true If the fetch was successful.
  330. * @retval false If unsuccessful, check nrf_gzll_error_code_t for more information.
  331. */
  332. bool nrf_gzll_fetch_packet_from_rx_fifo(uint32_t pipe, uint8_t * p_payload, uint32_t * p_length);
  333. /**
  334. * @brief Get the number of packets in the TX FIFO on a specific pipe.
  335. *
  336. * @param pipe The pipe for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  337. *
  338. * @retval >=0 The number of packets in the TX FIFO for the pipe.
  339. * @retval -1 If the pipe number is invalid.
  340. */
  341. int32_t nrf_gzll_get_tx_fifo_packet_count(uint32_t pipe);
  342. /**
  343. * @brief Get the number of packets in the RX FIFO on a specific pipe.
  344. *
  345. * @param pipe The pipe for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  346. * @retval >=0 The number of packets in the RX FIFO for the pipe.
  347. * @retval -1 If the pipe number is invalid.
  348. */
  349. int32_t nrf_gzll_get_rx_fifo_packet_count(uint32_t pipe);
  350. /**
  351. * @brief Get the total number of packets residing in all TX and RX FIFOs.
  352. *
  353. * Can be used to check against NRF_GZLL_CONST_MAX_TOTAL_PACKETS to
  354. * determine if there is free space in the memory pool for more packets.
  355. *
  356. * @return The number of packets residing in all TX and RX FIFOs.
  357. */
  358. uint32_t nrf_gzll_get_total_allocated_packet_count(void);
  359. /**
  360. * @brief Check if adding a packet to a pipe's TX FIFO should be successful.
  361. *
  362. * Checks if there is another space in the pipe's TX and RX FIFOs
  363. * as well as enough overall space in the packet pool.
  364. *
  365. * @param pipe The pip for which to check. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  366. *
  367. * @retval true If there is another space.
  368. * @retval false If there is not enough space, or the pipe is invalid.
  369. */
  370. bool nrf_gzll_ok_to_add_packet_to_tx_fifo(uint32_t pipe);
  371. /**
  372. * @brief Flush the RX FIFO for a specific pipe.
  373. *
  374. * Delete all the packets and free the memory of the TX FIFO for a
  375. * specific pipe.
  376. *
  377. * Note that it is not allowed to flush a TX FIFO when
  378. * Gazell is enabled.
  379. *
  380. * @param pipe is the pipe for which to flush. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  381. * @retval true if the pipe was flushed.
  382. * @retval false if the pipe was not flushed.
  383. */
  384. bool nrf_gzll_flush_tx_fifo(uint32_t pipe);
  385. /**
  386. * @brief Flush the RX FIFO for a specific pipe.
  387. *
  388. * Delete all the packets and free the memory of the RX FIFO for a
  389. * specific pipe.
  390. *
  391. * @param pipe is the pipe for which to flush. This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  392. * @retval true if the pipe was flushed.
  393. * @retval false if the pipe was not flushed.
  394. */
  395. bool nrf_gzll_flush_rx_fifo(uint32_t pipe);
  396. /**
  397. * @brief Function for enabling transmission statistics.
  398. *
  399. * @param p_statistics Pointer to the statistics structure.
  400. *
  401. * @return True if channel statistics has been enabled, false otherwise.
  402. */
  403. bool nrf_gzll_tx_statistics_enable(nrf_gzll_tx_statistics_t * p_statistics);
  404. /**
  405. * @brief Function for disabling transmission statistics.
  406. */
  407. void nrf_gzll_tx_statistics_disable(void);
  408. /**
  409. * @brief Function for obtaining number of transmission timeouts for specific channel.
  410. *
  411. * @param[in] channel_index Channel index in channel table.
  412. * @param[out] p_timeouts Pointer for the result.
  413. *
  414. * @return True in case of success, false otherwise.
  415. */
  416. bool nrf_gzll_get_channel_timeouts(uint8_t channel_index, uint32_t *p_timeouts);
  417. /**
  418. * @brief Function for clearing transmission statistic structure.
  419. */
  420. void nrf_gzll_reset_tx_statistics(void);
  421. /** @} */
  422. /******************************************************************************/
  423. /** @name Configuration functions
  424. *
  425. * Configuration 'set' functions may only be called while Gazell is disabled. The
  426. * new parameter comes into effect when Gazell is enabled again.
  427. *
  428. * Configuration 'get' functions may be called at any time.
  429. *
  430. * @{ */
  431. /******************************************************************************/
  432. /**
  433. * @brief Function for registering callback to be called on the transmission timeout.
  434. */
  435. void nrf_gzll_tx_timeout_callback_register(nrf_gzll_tx_timeout_callback callback);
  436. /**
  437. * @brief Function for registering callback to be called on the packet CRC failure.
  438. */
  439. void nrf_gzll_crc_failure_callback_register(nrf_gzll_crc_failure_callback callback);
  440. /**
  441. * @brief Set the mode.
  442. *
  443. * @param mode The mode to be used.
  444. * See nrf_gzll_mode_t for a list of valid modes.
  445. *
  446. * It is allowed to change mode when Gazell is enabled. If the mode is
  447. * being changed while Gazell is enabled, the mode will not change right away.
  448. * In this case the callback function nrf_gzll_mode_changed() will be called
  449. * after the mdoe has changed.
  450. *
  451. * @retval true If the parameter was set.
  452. */
  453. bool nrf_gzll_set_mode(nrf_gzll_mode_t mode);
  454. /**
  455. * @brief Get function counterpart to nrf_gzll_set_mode().
  456. *
  457. * @return The current mode.
  458. */
  459. nrf_gzll_mode_t nrf_gzll_get_mode(void);
  460. /**
  461. * @brief Set the base address for pipe 0.
  462. *
  463. * The full on-air address for each pipe is composed of a multi-byte base address
  464. * prepended to a prefix byte.
  465. *
  466. * For packets to be received correctly, the most significant byte of
  467. * the base address should not be an alternating sequence of 0s and 1s i.e.
  468. * it should not be 0x55 or 0xAA.
  469. *
  470. * @param base_address The 4 byte base address. All bytes are used.
  471. *
  472. * @note Due to the nRF52 Anomaly 107, pipe 0 address should not have
  473. * both prefix and two LSB of base address set to 0.
  474. *
  475. * @retval true If the parameter was set.
  476. * @return false If Gazell was enabled.
  477. */
  478. bool nrf_gzll_set_base_address_0(uint32_t base_address);
  479. /**
  480. * @brief Get function counterpart to nrf_gzll_set_base_address_0().
  481. *
  482. * @return Base address 0.
  483. */
  484. uint32_t nrf_gzll_get_base_address_0(void);
  485. /**
  486. * @brief Set the base address for pipes 1-7.
  487. *
  488. * Pipes 1 through 7 share base_address_1. @sa nrf_gzll_set_base_address_0.
  489. *
  490. * @param base_address The 4 byte base address.
  491. *
  492. * @retval true If the parameter was set.
  493. * @retval false If Gazell was enabled.
  494. */
  495. bool nrf_gzll_set_base_address_1(uint32_t base_address);
  496. /**
  497. * @brief Get function counterpart to nrf_gzll_set_base_address_1().
  498. *
  499. * @return Base address 1.
  500. */
  501. uint32_t nrf_gzll_get_base_address_1(void);
  502. /**
  503. * @brief Set the address prefix byte for a specific pipe.
  504. *
  505. * Each pipe should have its own unique prefix byte.
  506. *
  507. * @param pipe The pipe that the address should apply to.
  508. * This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  509. * @param address_prefix_byte The address prefix byte.
  510. *
  511. * @note Due to the Anomaly 107, pipe 0 address should not have
  512. * both prefix and two LSB of base address set to 0.
  513. *
  514. * @retval true If the parameter was set.
  515. * @retval false If Gazell was enabled, or if the pipe was invalid.
  516. */
  517. bool nrf_gzll_set_address_prefix_byte(uint32_t pipe, uint8_t address_prefix_byte);
  518. /**
  519. * @brief Get function counterpart to nrf_gzll_set_address_prefix_byte().
  520. *
  521. * @param pipe The pipe for which to get the address.
  522. * This value must be < NRF_GZLL_CONST_PIPE_COUNT.
  523. * @param p_out_address_prefix_byte The pointer in which to return the
  524. * address prefix byte.
  525. *
  526. * @retval true If the parameter was returned.
  527. * @retval false If Gazell was enabled, the pipe was invalid or
  528. * out_address was a NULL pointer.
  529. */
  530. bool nrf_gzll_get_address_prefix_byte(uint32_t pipe, uint8_t * p_out_address_prefix_byte);
  531. /**
  532. * @brief Set which pipes shall listen for packets in Host mode.
  533. *
  534. * This value is a bitmap, and each bit corresponds to a given pipe number.
  535. * Bit 0 set to "1" enables pipes 0, bit 1 set to "1" enables pipe 1
  536. * and so forth.
  537. * The maximum number of pipes is defined by NRF_GZLL_CONST_PIPE_COUNT.
  538. *
  539. * @param pipes A bitmap specifying which pipes to monitor.
  540. *
  541. * @retval true If the parameter was set.
  542. * @retval false If Gazell was enabled.
  543. */
  544. bool nrf_gzll_set_rx_pipes_enabled(uint32_t pipes);
  545. /**
  546. * @brief Get function counterpart to nrf_gzll_set_rx_pipes_enabled().
  547. *
  548. * @return Bitmap holding the current enabled pipes.
  549. */
  550. uint32_t nrf_gzll_get_rx_pipes_enabled(void);
  551. /**
  552. * @brief Set the timeslot period.
  553. *
  554. * The length in microseconds of a Gazell link layer timeslot.
  555. *
  556. * The minimum value of the timeslot period is dependent of the
  557. * radio data rate (@sa nrf_gzll_set_datarate()).
  558. *
  559. * - For NRF_GZLL_DATARATE_2MBIT the timeslot period must be >= 600 us.
  560. * - For NRF_GZLL_DATARATE_1MBIT the timeslot period must be >= 900 us.
  561. * - For NRF_GZLL_DATARATE_250KBIT the timeslot period must be >= 2700 us.
  562. *
  563. * @param period_us The timeslot period in microseconds.
  564. *
  565. * @retval true If the parameter was set.
  566. * @retval false If Gazell was enabled.
  567. */
  568. bool nrf_gzll_set_timeslot_period(uint32_t period_us);
  569. /**
  570. * @brief Get function counterpart to nrf_gzll_get_timeslot_period().
  571. *
  572. * @return The current timeslot period.
  573. */
  574. uint32_t nrf_gzll_get_timeslot_period(void);
  575. /**
  576. * @brief Set the Device channel selection policy
  577. *
  578. * The policy determines the initial channel when starting a new packet.
  579. * transmission.
  580. *
  581. * @param policy The channel selection policy.
  582. *
  583. * @arg NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_SUCCESSFUL specifies
  584. * that a new packet transmission always shall use the previous
  585. * successful channel from the channel table. If Gazell is "in sync", Gazell
  586. * will wait until this channel is being monitored by the Host before starting
  587. * the transmission.
  588. *
  589. * @arg NRF_GZLL_DEVICE_CHANNEL_SELECTION_POLICY_USE_CURRENT specifies that
  590. * Gazell shall transmit on the channel that is currently being monitored by the
  591. * Host. This parameter is only used when Gazell is "in sync". When "out of" sync,
  592. * Gazell will always start using the "previous successful" channel.
  593. *
  594. * @retval true If the parameter was set.
  595. * @retval false If Gazell was enabled or the policy was invalid.
  596. */
  597. bool nrf_gzll_set_device_channel_selection_policy(nrf_gzll_device_channel_selection_policy_t policy);
  598. /**
  599. * @brief Get function counterpart to nrf_gzll_set_device_channel_selection_policy().
  600. *
  601. * @return the Device channel selection policy.
  602. */
  603. nrf_gzll_device_channel_selection_policy_t nrf_gzll_get_device_channel_selection_policy(void);
  604. /**
  605. * @brief Set the number of timeslots that Gazell shall
  606. * reside on a single channel before switching to another channel.
  607. *
  608. * This parameter applies in Host mode and for a Device that is
  609. * in the "in sync" state.
  610. *
  611. * Since the Device and Host can not be in perfect synchronization, a
  612. * transmission should overlap to adjacent timeslots on the Host.
  613. * Therefore this value should be at least 2.
  614. *
  615. * @sa nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync
  616. *
  617. * @param timeslots The number of timeslots to reside on
  618. * each channel before channel switch.
  619. *
  620. * @retval true If the parameter was set.
  621. * @retval false If Gazell was enabled.
  622. */
  623. bool nrf_gzll_set_timeslots_per_channel(uint32_t timeslots);
  624. /**
  625. * @brief Get function counterpart to nrf_gzll_set_timeslots_per_channel().
  626. *
  627. * @return The current number of timeslots.
  628. */
  629. uint32_t nrf_gzll_get_timeslots_per_channel(void);
  630. /**
  631. * @brief Set the number of timeslots that a Gazell shall
  632. * reside on a single channel before switching to another channel when
  633. * in the "out of sync" state.
  634. *
  635. * This value should be set so that the Device transmits on one channel
  636. * while the Host goes through a full channel rotation, i.e.,
  637. * channel_table_size*timeslots_per_channel.
  638. * This ensures that the channels on the Device and Host will coincide
  639. * at some point.
  640. * Further increasing the value has been observed to provide better performance
  641. * in the presence of interferers.
  642. *
  643. * @param timeslots The number of timeslots to reside on
  644. * each channel before channel switch.
  645. *
  646. * @retval true If the parameter was set.
  647. * @retval false If Gazell was enabled.
  648. */
  649. bool nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync(uint32_t timeslots);
  650. /**
  651. * @brief Get function counterpart to
  652. * nrf_gzll_set_timeslots_per_channel_when_device_out_of_sync().
  653. *
  654. * @return The current number of timeslots.
  655. */
  656. uint32_t nrf_gzll_get_timeslots_per_channel_when_device_out_of_sync(void);
  657. /**
  658. * @brief Set the number of timeslots after a successful
  659. * reception of a Device or Host packet that the Gazell Link Layer shall assume
  660. * that the link is synchronized. A value of 0 implies that the
  661. * link is always out of sync.
  662. *
  663. * @param lifetime The sync lifetime in number of timeslots.
  664. *
  665. * @retval true If the sync lifetime was set.
  666. * @retval false If Gazell was enabled.
  667. */
  668. bool nrf_gzll_set_sync_lifetime(uint32_t lifetime);
  669. /**
  670. * @brief Get function counterpart to nrf_gzll_set_sync_lifetime().
  671. *
  672. * @return The sync lifetime measured in number of timeslots.
  673. */
  674. uint32_t nrf_gzll_get_sync_lifetime(void);
  675. /**
  676. * @brief Set the maximum number of TX attempts
  677. * that can be used for a single packet.
  678. *
  679. * After the maximum number of attempts have been spent without
  680. * receiving any ACK from the Host, the transmission will be terminated
  681. * and the nrf_gzll_device_tx_failed() callback will be called. A zero
  682. * value of the function parameter implies the infinite number of TX attempts.
  683. *
  684. * @param max_tx_attempts The maximum number of TX attempts.
  685. */
  686. void nrf_gzll_set_max_tx_attempts(uint16_t max_tx_attempts);
  687. /**
  688. * @brief Get function counterpart to nrf_gzll_set_max_tx_attempts().
  689. *
  690. * @return The current max Device TX attempts.
  691. */
  692. uint16_t nrf_gzll_get_max_tx_attempts(void);
  693. /**
  694. * @brief Set the table of Radio Frequency (RF) channels.
  695. *
  696. * The valid channels are in the range 0 <= channel <= 125, where the
  697. * actual centre frequency is (2400 + channel) MHz.
  698. * The maximum channel table size is defined by
  699. * NRF_GZLL_CONST_MAX_CHANNEL_TABLE_SIZE.
  700. *
  701. * @param p_channel_table Pointer to the channel table.
  702. * @param size The size of the channel table.
  703. *
  704. * @retval true If the channel table was set.
  705. * @retval false If Gazell was enabled, or the channel_table pointer was NULL,
  706. * or the size was invalid.
  707. */
  708. bool nrf_gzll_set_channel_table(uint8_t * p_channel_table, uint32_t size);
  709. /**
  710. * @brief Get the table of Radio Frequency (RF) channels.
  711. *
  712. * @param p_channel_table Pointer to copy the channel table to.
  713. * @param p_size Pointer to copy the size of the channel table to.
  714. * The value already at size must be at least the size
  715. * of the channel table.
  716. *
  717. * @retval true If the channel table was copied to channel_table.
  718. * @retval false If the channel_table pointer was NULL,
  719. * or the size was not large enough.
  720. */
  721. bool nrf_gzll_get_channel_table(uint8_t * p_channel_table, uint32_t * p_size);
  722. /**
  723. * @brief Get the current channel table size.
  724. *
  725. * @return The current channel table size.
  726. */
  727. uint32_t nrf_gzll_get_channel_table_size(void);
  728. /**
  729. * @brief Set the radio TX power.
  730. *
  731. * @param tx_power TX power.
  732. *
  733. * @retval true If the parameter was set.
  734. * @retval false If the TX power was invalid.
  735. */
  736. bool nrf_gzll_set_tx_power(nrf_gzll_tx_power_t tx_power);
  737. /**
  738. * @brief Get function counterpart to nrf_gzll_set_tx_power().
  739. *
  740. * @return The current TX power.
  741. */
  742. nrf_gzll_tx_power_t nrf_gzll_get_tx_power(void);
  743. /**
  744. * @brief Set the radio datarate.
  745. *
  746. * @param data_rate Datarate.
  747. *
  748. * @retval true If the parameter was set.
  749. * @retval false If Gazell was enabled or the datarate was invalid.
  750. */
  751. bool nrf_gzll_set_datarate(nrf_gzll_datarate_t data_rate);
  752. /**
  753. * @brief Get function counterpart to nrf_gzll_set_datarate().
  754. *
  755. * @return The current datarate.
  756. */
  757. nrf_gzll_datarate_t nrf_gzll_get_datarate(void);
  758. /**
  759. * @brief Set whether start/stop of external oscillator (XOSC) shall be handled
  760. * automatically inside Gazell or manually by the application.
  761. *
  762. * When controlling the XOSC manually from the application it is
  763. * required that the XOSC is started before Gazell is enabled.
  764. *
  765. * When start/stop of the XOSC is handled automatically by Gazell,
  766. * the XOSC will only be running when needed, that is when the radio
  767. * is being used or when Gazell needs to maintain synchronization.
  768. *
  769. * It is required that the XOSC is started in order for the radio to be
  770. * able to send or receive any packets.
  771. *
  772. * @param xosc_ctl setting for XOSC control.
  773. *
  774. * @retval true if the parameter was set.
  775. * @retval false if Gazell was enabled or the xosc_ctl value was invalid.
  776. */
  777. bool nrf_gzll_set_xosc_ctl(nrf_gzll_xosc_ctl_t xosc_ctl);
  778. /**
  779. * Get function counterpart for nrf_gzll_set_xosc_ctl();
  780. *
  781. * @return The XOSC control setting.
  782. */
  783. nrf_gzll_xosc_ctl_t nrf_gzll_get_xosc_ctl(void);
  784. /**
  785. * @brief Set Gazell to disable automatically after a certain number of timeslot ticks.
  786. *
  787. * @param num_ticks Number of timeslot ticks.
  788. *
  789. */
  790. void nrf_gzll_set_auto_disable(uint32_t num_ticks);
  791. #if defined(NRF52_SERIES) || defined(__SDK_DOXYGEN__)
  792. /**
  793. * @brief Set up external front end control.
  794. *
  795. * @param p_pa_lna_cfg Pointer to the configuration struct.
  796. */
  797. bool nrf_gzll_set_pa_lna_cfg(nrf_gzll_pa_lna_cfg_t const * p_pa_lna_cfg);
  798. #endif
  799. /**
  800. * @brief Get the number of timeslot ticks that have occurred since
  801. * nrf_gzll_init() was called.
  802. *
  803. * @return Number of timeslot ticks.
  804. *
  805. */
  806. uint32_t nrf_gzll_get_tick_count(void);
  807. /**
  808. * @brief Clear the internal timeslot tick count variable that is read
  809. * by nrf_gzll_get_tick_count().
  810. *
  811. */
  812. void nrf_gzll_clear_tick_count(void);
  813. /** @} */
  814. /******************************************************************************/
  815. /** @name Error handling functions
  816. * @{ */
  817. /******************************************************************************/
  818. /**
  819. * @brief Gets the Gazell error code.
  820. *
  821. * @return The current error code.
  822. */
  823. nrf_gzll_error_code_t nrf_gzll_get_error_code(void);
  824. /**
  825. * @brief Reset the Gazell error code.
  826. *
  827. * The error code is reset to NRF_GZLL_ERROR_CODE_NO_ERRROR.
  828. */
  829. void nrf_gzll_reset_error_code(void);
  830. /** @} */
  831. /** @} */
  832. #ifdef __cplusplus
  833. }
  834. #endif
  835. #endif