nrf_esb.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /**
  2. * Copyright (c) 2016 - 2020, 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. #ifndef __NRF_ESB_H
  41. #define __NRF_ESB_H
  42. #include <stdbool.h>
  43. #include <stdint.h>
  44. #include "nrf.h"
  45. #include "app_util.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /** @defgroup nrf_esb Enhanced ShockBurst
  50. * @{
  51. * @ingroup proprietary_api
  52. *
  53. * @brief Enhanced ShockBurst (ESB) is a basic protocol that supports two-way data
  54. * packet communication including packet buffering, packet acknowledgment,
  55. * and automatic retransmission of lost packets.
  56. */
  57. /** @name Debug pins
  58. * @{
  59. * @brief If NRF_ESB_DEBUG is defined, these GPIO pins can be used for debug timing.
  60. */
  61. #ifndef NRF52840_XXAA
  62. #define DEBUGPIN1 12 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every radio interrupt.
  63. #define DEBUGPIN2 13 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every NRF_RADIO->EVENTS_END.
  64. #define DEBUGPIN3 14 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every NRF_RADIO->EVENTS_DISABLED.
  65. #define DEBUGPIN4 15 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set when the radio is set to start transmission.
  66. #else
  67. #define DEBUGPIN1 24 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every radio interrupt.
  68. #define DEBUGPIN2 25 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every NRF_RADIO->EVENTS_END.
  69. #define DEBUGPIN3 26 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set with every NRF_RADIO->EVENTS_DISABLED.
  70. #define DEBUGPIN4 27 //!< If NRF_ESB_DEBUG is defined, this GPIO pin is set when the radio is set to start transmission.
  71. #endif
  72. #ifdef NRF_ESB_DEBUG
  73. #define DEBUG_PIN_SET(a) (NRF_GPIO->OUTSET = (1 << (a))) //!< Used internally to set debug pins.
  74. #define DEBUG_PIN_CLR(a) (NRF_GPIO->OUTCLR = (1 << (a))) //!< Used internally to clear debug pins.
  75. #else
  76. #define DEBUG_PIN_SET(a) //!< Used internally to set debug pins.
  77. #define DEBUG_PIN_CLR(a) //!< Used internally to clear debug pins.
  78. #endif
  79. /** @} */
  80. // Hardcoded parameters - change if necessary
  81. #ifndef NRF_ESB_MAX_PAYLOAD_LENGTH
  82. #define NRF_ESB_MAX_PAYLOAD_LENGTH 32 //!< The maximum size of the payload. Valid values are 1 to 252.
  83. #endif
  84. #define NRF_ESB_TX_FIFO_SIZE 8 //!< The size of the transmission first-in, first-out buffer.
  85. #define NRF_ESB_RX_FIFO_SIZE 8 //!< The size of the reception first-in, first-out buffer.
  86. // 252 is the largest possible payload size according to the nRF5 architecture.
  87. STATIC_ASSERT(NRF_ESB_MAX_PAYLOAD_LENGTH <= 252);
  88. #define NRF_ESB_SYS_TIMER NRF_TIMER2 //!< The timer that is used by the module.
  89. #define NRF_ESB_SYS_TIMER_IRQ_Handler TIMER2_IRQHandler //!< The handler that is used by @ref NRF_ESB_SYS_TIMER.
  90. #define NRF_ESB_PPI_TIMER_START 10 //!< The PPI channel used for starting the timer.
  91. #define NRF_ESB_PPI_TIMER_STOP 11 //!< The PPI channel used for stopping the timer.
  92. #define NRF_ESB_PPI_RX_TIMEOUT 12 //!< The PPI channel used for RX time-out.
  93. #define NRF_ESB_PPI_TX_START 13 //!< The PPI channel used for starting TX.
  94. #ifndef NRF_ESB_PIPE_COUNT
  95. #define NRF_ESB_PIPE_COUNT 8 //!< The maximum number of pipes allowed in the API, can be used if you need to restrict the number of pipes used. Must be 8 or lower because of architectural limitations.
  96. #endif
  97. STATIC_ASSERT(NRF_ESB_PIPE_COUNT <= 8);
  98. /**@cond NO_DOXYGEN */
  99. #ifdef NRF52832_XXAA
  100. // nRF52 address fix timer and PPI defines
  101. #define NRF_ESB_PPI_BUGFIX1 9
  102. #define NRF_ESB_PPI_BUGFIX2 8
  103. #define NRF_ESB_PPI_BUGFIX3 7
  104. #define NRF_ESB_BUGFIX_TIMER NRF_TIMER3
  105. #define NRF_ESB_BUGFIX_TIMER_IRQn TIMER3_IRQn
  106. #define NRF_ESB_BUGFIX_TIMER_IRQHandler TIMER3_IRQHandler
  107. #endif
  108. /** @endcond */
  109. // Interrupt flags
  110. #define NRF_ESB_INT_TX_SUCCESS_MSK 0x01 //!< The flag used to indicate a success since the last event.
  111. #define NRF_ESB_INT_TX_FAILED_MSK 0x02 //!< The flag used to indicate a failure since the last event.
  112. #define NRF_ESB_INT_RX_DR_MSK 0x04 //!< The flag used to indicate that a packet was received since the last event.
  113. #define NRF_ESB_PID_RESET_VALUE 0xFF //!< Invalid PID value that is guaranteed to not collide with any valid PID value.
  114. #define NRF_ESB_PID_MAX 3 //!< The maximum value for PID.
  115. #define NRF_ESB_CRC_RESET_VALUE 0xFFFF //!< The CRC reset value.
  116. #define ESB_EVT_IRQ SWI0_IRQn //!< The ESB event IRQ number when running on an nRF5 device.
  117. #define ESB_EVT_IRQHandler SWI0_IRQHandler //!< The handler for @ref ESB_EVT_IRQ when running on an nRF5 device.
  118. #if defined(NRF52_SERIES)
  119. #define ESB_IRQ_PRIORITY_MSK 0x07 //!< The mask used to enforce a valid IRQ priority.
  120. #else
  121. #define ESB_IRQ_PRIORITY_MSK 0x03 //!< The mask used to enforce a valid IRQ priority.
  122. #endif
  123. /** @brief Default address configuration for ESB.
  124. * @details Roughly equal to the nRF24Lxx default (except for the number of pipes, because more pipes are supported). */
  125. #define NRF_ESB_ADDR_DEFAULT \
  126. { \
  127. .base_addr_p0 = { 0xE7, 0xE7, 0xE7, 0xE7 }, \
  128. .base_addr_p1 = { 0xC2, 0xC2, 0xC2, 0xC2 }, \
  129. .pipe_prefixes = { 0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 }, \
  130. .addr_length = 5, \
  131. .num_pipes = NRF_ESB_PIPE_COUNT, \
  132. .rf_channel = 2, \
  133. .rx_pipes_enabled = 0xFF \
  134. }
  135. /** @brief Default radio parameters.
  136. * @details Roughly equal to the nRF24Lxx default parameters (except for CRC, which is set to 16 bit, and protocol, which is set to DPL). */
  137. #define NRF_ESB_DEFAULT_CONFIG {.protocol = NRF_ESB_PROTOCOL_ESB_DPL, \
  138. .mode = NRF_ESB_MODE_PTX, \
  139. .event_handler = 0, \
  140. .bitrate = NRF_ESB_BITRATE_2MBPS, \
  141. .crc = NRF_ESB_CRC_16BIT, \
  142. .tx_output_power = NRF_ESB_TX_POWER_0DBM, \
  143. .retransmit_delay = 250, \
  144. .retransmit_count = 3, \
  145. .tx_mode = NRF_ESB_TXMODE_AUTO, \
  146. .radio_irq_priority = 1, \
  147. .event_irq_priority = 2, \
  148. .payload_length = 32, \
  149. .selective_auto_ack = false \
  150. }
  151. /** @brief Default legacy radio parameters. Identical to the nRF24Lxx defaults. */
  152. #define NRF_ESB_LEGACY_CONFIG {.protocol = NRF_ESB_PROTOCOL_ESB, \
  153. .mode = NRF_ESB_MODE_PTX, \
  154. .event_handler = 0, \
  155. .bitrate = NRF_ESB_BITRATE_2MBPS, \
  156. .crc = NRF_ESB_CRC_8BIT, \
  157. .tx_output_power = NRF_ESB_TX_POWER_0DBM, \
  158. .retransmit_delay = 600, \
  159. .retransmit_count = 3, \
  160. .tx_mode = NRF_ESB_TXMODE_AUTO, \
  161. .radio_irq_priority = 1, \
  162. .event_irq_priority = 2, \
  163. .payload_length = 32, \
  164. .selective_auto_ack = false \
  165. }
  166. /** @brief Macro to create an initializer for a TX data packet.
  167. *
  168. * @details This macro generates an initializer. Using the initializer is more efficient
  169. * than setting the individual parameters dynamically.
  170. *
  171. * @param[in] _pipe The pipe to use for the data packet.
  172. * @param[in] ... Comma separated list of character data to put in the TX buffer.
  173. * Supported values consist of 1 to 63 characters.
  174. *
  175. * @return Initializer that sets up the pipe, length, and byte array for content of the TX data.
  176. */
  177. #define NRF_ESB_CREATE_PAYLOAD(_pipe, ...) \
  178. {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}}; \
  179. STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 63)
  180. /**@brief Enhanced ShockBurst protocols. */
  181. typedef enum {
  182. NRF_ESB_PROTOCOL_ESB, /**< Enhanced ShockBurst with fixed payload length. */
  183. NRF_ESB_PROTOCOL_ESB_DPL /**< Enhanced ShockBurst with dynamic payload length. */
  184. } nrf_esb_protocol_t;
  185. /**@brief Enhanced ShockBurst modes. */
  186. typedef enum {
  187. NRF_ESB_MODE_PTX, /**< Primary transmitter mode. */
  188. NRF_ESB_MODE_PRX /**< Primary receiver mode. */
  189. } nrf_esb_mode_t;
  190. /**@brief Enhanced ShockBurst bitrate modes. */
  191. typedef enum {
  192. NRF_ESB_BITRATE_2MBPS = RADIO_MODE_MODE_Nrf_2Mbit, /**< 2 Mb radio mode. */
  193. NRF_ESB_BITRATE_1MBPS = RADIO_MODE_MODE_Nrf_1Mbit, /**< 1 Mb radio mode. */
  194. #if defined(RADIO_MODE_MODE_Nrf_250Kbit)
  195. NRF_ESB_BITRATE_250KBPS = RADIO_MODE_MODE_Nrf_250Kbit, /**< 250 Kb radio mode. */
  196. #endif //!( defined(NRF52840_XXAA) || defined(NRF52810_XXAA) || defined(NRF52811_XXAA) )
  197. NRF_ESB_BITRATE_1MBPS_BLE = RADIO_MODE_MODE_Ble_1Mbit, /**< 1 Mb radio mode using @e Bluetooth low energy radio parameters. */
  198. #if defined(RADIO_MODE_MODE_Ble_2Mbit)
  199. NRF_ESB_BITRATE_2MBPS_BLE = RADIO_MODE_MODE_Ble_2Mbit /**< 2 Mb radio mode using @e Bluetooth low energy radio parameters. */
  200. #endif
  201. } nrf_esb_bitrate_t;
  202. /**@brief Enhanced ShockBurst CRC modes. */
  203. typedef enum {
  204. NRF_ESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two, /**< Use two-byte CRC. */
  205. NRF_ESB_CRC_8BIT = RADIO_CRCCNF_LEN_One, /**< Use one-byte CRC. */
  206. NRF_ESB_CRC_OFF = RADIO_CRCCNF_LEN_Disabled /**< Disable CRC. */
  207. } nrf_esb_crc_t;
  208. /**@brief Enhanced ShockBurst radio transmission power modes. */
  209. typedef enum {
  210. #if defined(RADIO_TXPOWER_TXPOWER_Pos8dBm)
  211. NRF_ESB_TX_POWER_8DBM = RADIO_TXPOWER_TXPOWER_Pos8dBm, /**< 8 dBm radio transmit power. */
  212. #endif
  213. #if defined(RADIO_TXPOWER_TXPOWER_Pos7dBm)
  214. NRF_ESB_TX_POWER_7DBM = RADIO_TXPOWER_TXPOWER_Pos7dBm, /**< 7 dBm radio transmit power. */
  215. #endif
  216. #if defined(RADIO_TXPOWER_TXPOWER_Pos6dBm)
  217. NRF_ESB_TX_POWER_6DBM = RADIO_TXPOWER_TXPOWER_Pos6dBm, /**< 6 dBm radio transmit power. */
  218. #endif
  219. #if defined(RADIO_TXPOWER_TXPOWER_Pos5dBm)
  220. NRF_ESB_TX_POWER_5DBM = RADIO_TXPOWER_TXPOWER_Pos5dBm, /**< 5 dBm radio transmit power. */
  221. #endif
  222. NRF_ESB_TX_POWER_4DBM = RADIO_TXPOWER_TXPOWER_Pos4dBm, /**< 4 dBm radio transmit power. */
  223. #if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm)
  224. NRF_ESB_TX_POWER_3DBM = RADIO_TXPOWER_TXPOWER_Pos3dBm, /**< 3 dBm radio transmit power. */
  225. #endif
  226. #if defined(RADIO_TXPOWER_TXPOWER_Pos2dBm)
  227. NRF_ESB_TX_POWER_2DBM = RADIO_TXPOWER_TXPOWER_Pos2dBm, /**< 2 dBm radio transmit power. */
  228. #endif
  229. NRF_ESB_TX_POWER_0DBM = RADIO_TXPOWER_TXPOWER_0dBm, /**< 0 dBm radio transmit power. */
  230. NRF_ESB_TX_POWER_NEG4DBM = RADIO_TXPOWER_TXPOWER_Neg4dBm, /**< -4 dBm radio transmit power. */
  231. NRF_ESB_TX_POWER_NEG8DBM = RADIO_TXPOWER_TXPOWER_Neg8dBm, /**< -8 dBm radio transmit power. */
  232. NRF_ESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm, /**< -12 dBm radio transmit power. */
  233. NRF_ESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm, /**< -16 dBm radio transmit power. */
  234. NRF_ESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm, /**< -20 dBm radio transmit power. */
  235. NRF_ESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm, /**< -30 dBm radio transmit power. */
  236. NRF_ESB_TX_POWER_NEG40DBM = RADIO_TXPOWER_TXPOWER_Neg40dBm /**< -40 dBm radio transmit power. */
  237. } nrf_esb_tx_power_t;
  238. /**@brief Enhanced ShockBurst transmission modes. */
  239. typedef enum {
  240. NRF_ESB_TXMODE_AUTO, /**< Automatic TX mode: When the TX FIFO contains packets and the radio is idle, packets are sent automatically. */
  241. NRF_ESB_TXMODE_MANUAL, /**< Manual TX mode: Packets are not sent until @ref nrf_esb_start_tx is called. This mode can be used to ensure consistent packet timing. */
  242. NRF_ESB_TXMODE_MANUAL_START /**< Manual start TX mode: Packets are not sent until @ref nrf_esb_start_tx is called. Then, transmission continues automatically until the TX FIFO is empty. */
  243. } nrf_esb_tx_mode_t;
  244. /**@brief Enhanced ShockBurst event IDs used to indicate the type of the event. */
  245. typedef enum
  246. {
  247. NRF_ESB_EVENT_TX_SUCCESS, /**< Event triggered on TX success. */
  248. NRF_ESB_EVENT_TX_FAILED, /**< Event triggered on TX failure. */
  249. NRF_ESB_EVENT_RX_RECEIVED /**< Event triggered on RX received. */
  250. } nrf_esb_evt_id_t;
  251. /**@brief Enhanced ShockBurst payload.
  252. *
  253. * @details The payload is used both for transmissions and for acknowledging a
  254. * received packet with a payload.
  255. */
  256. typedef struct
  257. {
  258. uint8_t length; //!< Length of the packet (maximum value is @ref NRF_ESB_MAX_PAYLOAD_LENGTH).
  259. uint8_t pipe; //!< Pipe used for this payload.
  260. int8_t rssi; //!< RSSI for the received packet.
  261. uint8_t noack; //!< Flag indicating that this packet will not be acknowledgement. Flag is ignored when selective auto ack is enabled.
  262. uint8_t pid; //!< PID assigned during communication.
  263. uint8_t data[NRF_ESB_MAX_PAYLOAD_LENGTH]; //!< The payload data.
  264. } nrf_esb_payload_t;
  265. /**@brief Enhanced ShockBurst event. */
  266. typedef struct
  267. {
  268. nrf_esb_evt_id_t evt_id; //!< Enhanced ShockBurst event ID.
  269. uint32_t tx_attempts; //!< Number of TX retransmission attempts.
  270. } nrf_esb_evt_t;
  271. /**@brief Definition of the event handler for the module. */
  272. typedef void (* nrf_esb_event_handler_t)(nrf_esb_evt_t const * p_event);
  273. /**@brief Main configuration structure for the module. */
  274. typedef struct
  275. {
  276. nrf_esb_protocol_t protocol; //!< Enhanced ShockBurst protocol.
  277. nrf_esb_mode_t mode; //!< Enhanced ShockBurst mode.
  278. nrf_esb_event_handler_t event_handler; //!< Enhanced ShockBurst event handler.
  279. // General RF parameters
  280. nrf_esb_bitrate_t bitrate; //!< Enhanced ShockBurst bitrate mode.
  281. nrf_esb_crc_t crc; //!< Enhanced ShockBurst CRC mode.
  282. nrf_esb_tx_power_t tx_output_power; //!< Enhanced ShockBurst radio transmission power mode.
  283. uint16_t retransmit_delay; //!< The delay between each retransmission of unacknowledged packets.
  284. uint16_t retransmit_count; //!< The number of retransmission attempts before transmission fail.
  285. // Control settings
  286. nrf_esb_tx_mode_t tx_mode; //!< Enhanced ShockBurst transmission mode.
  287. uint8_t radio_irq_priority; //!< nRF radio interrupt priority.
  288. uint8_t event_irq_priority; //!< ESB event interrupt priority.
  289. uint8_t payload_length; //!< Length of the payload (maximum length depends on the platforms that are used on each side).
  290. bool selective_auto_ack; //!< Enable or disable selective auto acknowledgement. When this feature is disabled, all packets will be acknowledged ignoring the noack field.
  291. } nrf_esb_config_t;
  292. /**@brief Function for initializing the Enhanced ShockBurst module.
  293. *
  294. * @param p_config Parameters for initializing the module.
  295. *
  296. * @retval NRF_SUCCESS If initialization was successful.
  297. * @retval NRF_ERROR_NULL If the @p p_config argument was NULL.
  298. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  299. */
  300. uint32_t nrf_esb_init(nrf_esb_config_t const * p_config);
  301. /**@brief Function for suspending the Enhanced ShockBurst module.
  302. *
  303. * Calling this function stops ongoing communications without changing the queues.
  304. *
  305. * @retval NRF_SUCCESS If Enhanced ShockBurst was suspended.
  306. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  307. */
  308. uint32_t nrf_esb_suspend(void);
  309. /**@brief Function for disabling the Enhanced ShockBurst module.
  310. *
  311. * Calling this function disables the Enhanced ShockBurst module immediately.
  312. * Doing so might stop ongoing communications.
  313. *
  314. * @note All queues are flushed by this function.
  315. *
  316. * @retval NRF_SUCCESS If Enhanced ShockBurst was disabled.
  317. */
  318. uint32_t nrf_esb_disable(void);
  319. /**@brief Function for checking if the Enhanced ShockBurst module is idle.
  320. *
  321. * @retval true If the module is idle.
  322. * @retval false If the module is busy.
  323. */
  324. bool nrf_esb_is_idle(void);
  325. /**@brief Function for writing a payload for transmission or acknowledgement.
  326. *
  327. * This function writes a payload that is added to the queue. When the module is in PTX mode, the
  328. * payload is queued for a regular transmission. When the module is in PRX mode, the payload
  329. * is queued for when a packet is received that requires an acknowledgement with payload.
  330. *
  331. * @param[in] p_payload Pointer to the structure that contains information and state of the payload.
  332. *
  333. * @retval NRF_SUCCESS If the payload was successfully queued for writing.
  334. * @retval NRF_ERROR_NULL If the required parameter was NULL.
  335. * @retval NRF_INVALID_STATE If the module is not initialized.
  336. * @retval NRF_ERROR_NO_MEM If the TX FIFO is full.
  337. * @retval NRF_ERROR_INVALID_LENGTH If the payload length was invalid (zero or larger than the allowed maximum).
  338. */
  339. uint32_t nrf_esb_write_payload(nrf_esb_payload_t const * p_payload);
  340. /**@brief Function for reading an RX payload.
  341. *
  342. * @param[in,out] p_payload Pointer to the structure that contains information and state of the payload.
  343. *
  344. * @retval NRF_SUCCESS If the data was read successfully.
  345. * @retval NRF_ERROR_NULL If the required parameter was NULL.
  346. * @retval NRF_INVALID_STATE If the module is not initialized.
  347. */
  348. uint32_t nrf_esb_read_rx_payload(nrf_esb_payload_t * p_payload);
  349. /**@brief Function for starting transmission.
  350. *
  351. * @retval NRF_SUCCESS If the TX started successfully.
  352. * @retval NRF_ERROR_BUFFER_EMPTY If the TX did not start because the FIFO buffer is empty.
  353. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  354. */
  355. uint32_t nrf_esb_start_tx(void);
  356. /**@brief Function for starting to transmit data from the FIFO buffer.
  357. *
  358. * @retval NRF_SUCCESS If the transmission was started successfully.
  359. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  360. */
  361. uint32_t nrf_esb_start_rx(void);
  362. /** @brief Function for stopping data reception.
  363. *
  364. * @retval NRF_SUCCESS If data reception was stopped successfully.
  365. * @retval NRF_ESB_ERROR_NOT_IN_RX_MODE If the function failed because the module is not in RX mode.
  366. */
  367. uint32_t nrf_esb_stop_rx(void);
  368. /**@brief Function for removing remaining items from the TX buffer.
  369. *
  370. * This function clears the TX FIFO buffer.
  371. *
  372. * @retval NRF_SUCCESS If pending items in the TX buffer were successfully cleared.
  373. * @retval NRF_INVALID_STATE If the module is not initialized.
  374. */
  375. uint32_t nrf_esb_flush_tx(void);
  376. /**@brief Function for removing the newest entry from the TX buffer.
  377. *
  378. * This function will remove the most recently added element from the FIFO queue.
  379. *
  380. * @retval NRF_SUCCESS If the operation completed successfully.
  381. * @retval NRF_INVALID_STATE If the module is not initialized.
  382. * @retval NRF_ERROR_BUFFER_EMPTY If there are no items in the queue to remove.
  383. */
  384. uint32_t nrf_esb_pop_tx(void);
  385. /**@brief Function for removing the oldest entry from the TX buffer.
  386. *
  387. * This function will remove the next element scheduled to be sent from the TX FIFO queue.
  388. * This is useful if you want to skip a packet which was never acknowledged.
  389. *
  390. * @retval NRF_SUCCESS If the operation completed successfully.
  391. * @retval NRF_INVALID_STATE If the module is not initialized.
  392. * @retval NRF_ERROR_BUFFER_EMPTY If there are no items in the queue to remove.
  393. */
  394. uint32_t nrf_esb_skip_tx(void);
  395. /**@brief Function for removing remaining items from the RX buffer.
  396. *
  397. * @retval NRF_SUCCESS If the pending items in the RX buffer were successfully cleared.
  398. * @retval NRF_INVALID_STATE If the module is not initialized.
  399. */
  400. uint32_t nrf_esb_flush_rx(void);
  401. /**@brief Function for setting the length of the address.
  402. *
  403. * @param[in] length Length of the ESB address (in bytes).
  404. *
  405. * @retval NRF_SUCCESS If the address length was set successfully.
  406. * @retval NRF_ERROR_INVALID_PARAM If the address length was invalid.
  407. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  408. */
  409. uint32_t nrf_esb_set_address_length(uint8_t length);
  410. /**@brief Function for setting the base address for pipe 0.
  411. *
  412. * @param[in] p_addr Pointer to the address data.
  413. *
  414. * @retval NRF_SUCCESS If the base address was set successfully.
  415. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  416. * @retval NRF_ERROR_INVALID_PARAM If the function failed because the address given was too close to a zero address.
  417. * @retval NRF_ERROR_NULL If the required parameter was NULL.
  418. */
  419. uint32_t nrf_esb_set_base_address_0(uint8_t const * p_addr);
  420. /**@brief Function for setting the base address for pipe 1 to pipe 7.
  421. *
  422. * @param[in] p_addr Pointer to the address data.
  423. *
  424. * @retval NRF_SUCCESS If the base address was set successfully.
  425. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  426. * @retval NRF_ERROR_INVALID_PARAM If the function failed because the address given was too close to a zero address.
  427. * @retval NRF_ERROR_NULL If the required parameter was NULL.
  428. */
  429. uint32_t nrf_esb_set_base_address_1(uint8_t const * p_addr);
  430. /**@brief Function for setting the number of pipes and the pipe prefix addresses.
  431. *
  432. * This function configures the number of available pipes, enables the pipes,
  433. * and sets their prefix addresses.
  434. *
  435. * @param[in] p_prefixes Pointer to a char array that contains the prefix for each pipe.
  436. * @param[in] num_pipes Number of pipes. Must be less than or equal to @ref NRF_ESB_PIPE_COUNT.
  437. *
  438. * @retval NRF_SUCCESS If the prefix addresses were set successfully.
  439. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  440. * @retval NRF_ERROR_NULL If a required parameter was NULL.
  441. * @retval NRF_ERROR_INVALID_PARAM If an invalid number of pipes was given or if the address given was too close to a zero address.
  442. */
  443. uint32_t nrf_esb_set_prefixes(uint8_t const * p_prefixes, uint8_t num_pipes);
  444. /**@brief Function for enabling pipes.
  445. *
  446. * The @p enable_mask parameter must contain the same number of pipes as has been configured
  447. * with @ref nrf_esb_set_prefixes. This number may not be greater than the number defined by
  448. * @ref NRF_ESB_PIPE_COUNT
  449. *
  450. * @param enable_mask Bitfield mask to enable or disable pipes. Setting a bit to
  451. * 0 disables the pipe. Setting a bit to 1 enables the pipe.
  452. *
  453. * @retval NRF_SUCCESS If the pipes were enabled and disabled successfully.
  454. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  455. * @retval NRF_ERROR_INVALID_PARAM If the function failed because the address given was too close to a zero address.
  456. */
  457. uint32_t nrf_esb_enable_pipes(uint8_t enable_mask);
  458. /**@brief Function for updating the prefix for a pipe.
  459. *
  460. * @param pipe Pipe for which to set the prefix.
  461. * @param prefix Prefix to set for the pipe.
  462. *
  463. * @retval NRF_SUCCESS If the operation completed successfully.
  464. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  465. * @retval NRF_ERROR_INVALID_PARAM If the given pipe number was invalid or if the address given was too close to a zero address.
  466. */
  467. uint32_t nrf_esb_update_prefix(uint8_t pipe, uint8_t prefix);
  468. /** @brief Function for setting the channel to use for the radio.
  469. *
  470. * The module must be in an idle state to call this function. As a PTX, the
  471. * application must wait for an idle state and as a PRX, the application must stop RX
  472. * before changing the channel. After changing the channel, operation can be resumed.
  473. *
  474. * @param[in] channel Channel to use for radio.
  475. *
  476. * @retval NRF_SUCCESS If the operation completed successfully.
  477. * @retval NRF_INVALID_STATE If the module is not initialized.
  478. * @retval NRF_ERROR_BUSY If the module was not in idle state.
  479. * @retval NRF_ERROR_INVALID_PARAM If the channel is invalid (larger than 100).
  480. */
  481. uint32_t nrf_esb_set_rf_channel(uint32_t channel);
  482. /**@brief Function for getting the current radio channel.
  483. *
  484. * @param[in, out] p_channel Pointer to the channel data.
  485. *
  486. * @retval NRF_SUCCESS If the operation completed successfully.
  487. * @retval NRF_ERROR_NULL If the required parameter was NULL.
  488. */
  489. uint32_t nrf_esb_get_rf_channel(uint32_t * p_channel);
  490. /**@brief Function for setting the radio output power.
  491. *
  492. * @param[in] tx_output_power Output power.
  493. *
  494. * @retval NRF_SUCCESS If the operation completed successfully.
  495. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  496. */
  497. uint32_t nrf_esb_set_tx_power(nrf_esb_tx_power_t tx_output_power);
  498. /**@brief Function for setting the packet retransmit delay.
  499. *
  500. * @param[in] delay Delay between retransmissions.
  501. *
  502. * @retval NRF_SUCCESS If the operation completed successfully.
  503. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  504. */
  505. uint32_t nrf_esb_set_retransmit_delay(uint16_t delay);
  506. /**@brief Function for setting the number of retransmission attempts.
  507. *
  508. * @param[in] count Number of retransmissions.
  509. *
  510. * @retval NRF_SUCCESS If the operation completed successfully.
  511. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  512. */
  513. uint32_t nrf_esb_set_retransmit_count(uint16_t count);
  514. /**@brief Function for setting the radio bitrate.
  515. *
  516. * @param[in] bitrate Radio bitrate.
  517. *
  518. * @retval NRF_SUCCESS If the operation completed successfully.
  519. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  520. */
  521. uint32_t nrf_esb_set_bitrate(nrf_esb_bitrate_t bitrate);
  522. /**@brief Function for reusing a packet ID for a specific pipe.
  523. *
  524. * The ESB protocol uses a 2-bit sequence number (packet ID) to identify
  525. * retransmitted packets. By default, the packet ID is incremented for every
  526. * uploaded packet. Use this function to prevent this and send two different
  527. * packets with the same packet ID.
  528. *
  529. * @param[in] pipe Pipe.
  530. *
  531. * @retval NRF_SUCCESS If the operation completed successfully.
  532. * @retval NRF_ERROR_BUSY If the function failed because the radio is busy.
  533. */
  534. uint32_t nrf_esb_reuse_pid(uint8_t pipe);
  535. /** @} */
  536. #ifdef __cplusplus
  537. }
  538. #endif
  539. #endif // NRF_ESB