nrf_esb.h 30 KB

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