nrf_uarte.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /**
  2. * Copyright (c) 2015 - 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_UARTE_H__
  41. #define NRF_UARTE_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. #define NRF_UARTE_PSEL_DISCONNECTED 0xFFFFFFFF
  47. /**
  48. * @defgroup nrf_uarte_hal UARTE HAL
  49. * @{
  50. * @ingroup nrf_uarte
  51. * @brief Hardware access layer for managing the UARTE peripheral.
  52. */
  53. /** @brief UARTE tasks. */
  54. typedef enum
  55. {
  56. NRF_UARTE_TASK_STARTRX = offsetof(NRF_UARTE_Type, TASKS_STARTRX), ///< Start UART receiver.
  57. NRF_UARTE_TASK_STOPRX = offsetof(NRF_UARTE_Type, TASKS_STOPRX), ///< Stop UART receiver.
  58. NRF_UARTE_TASK_STARTTX = offsetof(NRF_UARTE_Type, TASKS_STARTTX), ///< Start UART transmitter.
  59. NRF_UARTE_TASK_STOPTX = offsetof(NRF_UARTE_Type, TASKS_STOPTX), ///< Stop UART transmitter.
  60. NRF_UARTE_TASK_FLUSHRX = offsetof(NRF_UARTE_Type, TASKS_FLUSHRX) ///< Flush RX FIFO in RX buffer.
  61. } nrf_uarte_task_t;
  62. /** @brief UARTE events. */
  63. typedef enum
  64. {
  65. NRF_UARTE_EVENT_CTS = offsetof(NRF_UARTE_Type, EVENTS_CTS), ///< CTS is activated.
  66. NRF_UARTE_EVENT_NCTS = offsetof(NRF_UARTE_Type, EVENTS_NCTS), ///< CTS is deactivated.
  67. NRF_UARTE_EVENT_RXDRDY = offsetof(NRF_UARTE_Type, EVENTS_RXDRDY), ///< Data received in RXD (but potentially not yet transferred to Data RAM).
  68. NRF_UARTE_EVENT_ENDRX = offsetof(NRF_UARTE_Type, EVENTS_ENDRX), ///< Receive buffer is filled up.
  69. NRF_UARTE_EVENT_TXDRDY = offsetof(NRF_UARTE_Type, EVENTS_TXDRDY), ///< Data sent from TXD.
  70. NRF_UARTE_EVENT_ENDTX = offsetof(NRF_UARTE_Type, EVENTS_ENDTX), ///< Last TX byte transmitted.
  71. NRF_UARTE_EVENT_ERROR = offsetof(NRF_UARTE_Type, EVENTS_ERROR), ///< Error detected.
  72. NRF_UARTE_EVENT_RXTO = offsetof(NRF_UARTE_Type, EVENTS_RXTO), ///< Receiver timeout.
  73. NRF_UARTE_EVENT_RXSTARTED = offsetof(NRF_UARTE_Type, EVENTS_RXSTARTED), ///< Receiver has started.
  74. NRF_UARTE_EVENT_TXSTARTED = offsetof(NRF_UARTE_Type, EVENTS_TXSTARTED), ///< Transmitter has started.
  75. NRF_UARTE_EVENT_TXSTOPPED = offsetof(NRF_UARTE_Type, EVENTS_TXSTOPPED) ///< Transmitted stopped.
  76. } nrf_uarte_event_t;
  77. /** @brief Types of UARTE shortcuts. */
  78. typedef enum
  79. {
  80. NRF_UARTE_SHORT_ENDRX_STARTRX = UARTE_SHORTS_ENDRX_STARTRX_Msk, ///< Shortcut between ENDRX event and STARTRX task.
  81. NRF_UARTE_SHORT_ENDRX_STOPRX = UARTE_SHORTS_ENDRX_STOPRX_Msk ///< Shortcut between ENDRX event and STOPRX task.
  82. } nrf_uarte_short_t;
  83. /** @brief UARTE interrupts. */
  84. typedef enum
  85. {
  86. NRF_UARTE_INT_CTS_MASK = UARTE_INTENSET_CTS_Msk, ///< Interrupt on CTS event.
  87. NRF_UARTE_INT_NCTS_MASK = UARTE_INTENSET_NCTS_Msk, ///< Interrupt on NCTS event.
  88. NRF_UARTE_INT_RXDRDY_MASK = UARTE_INTENSET_RXDRDY_Msk, ///< Interrupt on RXDRDY event.
  89. NRF_UARTE_INT_ENDRX_MASK = UARTE_INTENSET_ENDRX_Msk, ///< Interrupt on ENDRX event.
  90. NRF_UARTE_INT_TXDRDY_MASK = UARTE_INTENSET_TXDRDY_Msk, ///< Interrupt on TXDRDY event.
  91. NRF_UARTE_INT_ENDTX_MASK = UARTE_INTENSET_ENDTX_Msk, ///< Interrupt on ENDTX event.
  92. NRF_UARTE_INT_ERROR_MASK = UARTE_INTENSET_ERROR_Msk, ///< Interrupt on ERROR event.
  93. NRF_UARTE_INT_RXTO_MASK = UARTE_INTENSET_RXTO_Msk, ///< Interrupt on RXTO event.
  94. NRF_UARTE_INT_RXSTARTED_MASK = UARTE_INTENSET_RXSTARTED_Msk, ///< Interrupt on RXSTARTED event.
  95. NRF_UARTE_INT_TXSTARTED_MASK = UARTE_INTENSET_TXSTARTED_Msk, ///< Interrupt on TXSTARTED event.
  96. NRF_UARTE_INT_TXSTOPPED_MASK = UARTE_INTENSET_TXSTOPPED_Msk ///< Interrupt on TXSTOPPED event.
  97. } nrf_uarte_int_mask_t;
  98. /** @brief Baudrates supported by UARTE. */
  99. typedef enum
  100. {
  101. NRF_UARTE_BAUDRATE_1200 = UARTE_BAUDRATE_BAUDRATE_Baud1200, ///< 1200 baud.
  102. NRF_UARTE_BAUDRATE_2400 = UARTE_BAUDRATE_BAUDRATE_Baud2400, ///< 2400 baud.
  103. NRF_UARTE_BAUDRATE_4800 = UARTE_BAUDRATE_BAUDRATE_Baud4800, ///< 4800 baud.
  104. NRF_UARTE_BAUDRATE_9600 = UARTE_BAUDRATE_BAUDRATE_Baud9600, ///< 9600 baud.
  105. NRF_UARTE_BAUDRATE_14400 = UARTE_BAUDRATE_BAUDRATE_Baud14400, ///< 14400 baud.
  106. NRF_UARTE_BAUDRATE_19200 = UARTE_BAUDRATE_BAUDRATE_Baud19200, ///< 19200 baud.
  107. NRF_UARTE_BAUDRATE_28800 = UARTE_BAUDRATE_BAUDRATE_Baud28800, ///< 28800 baud.
  108. NRF_UARTE_BAUDRATE_31250 = UARTE_BAUDRATE_BAUDRATE_Baud31250, ///< 31250 baud.
  109. NRF_UARTE_BAUDRATE_38400 = UARTE_BAUDRATE_BAUDRATE_Baud38400, ///< 38400 baud.
  110. NRF_UARTE_BAUDRATE_56000 = UARTE_BAUDRATE_BAUDRATE_Baud56000, ///< 56000 baud.
  111. NRF_UARTE_BAUDRATE_57600 = UARTE_BAUDRATE_BAUDRATE_Baud57600, ///< 57600 baud.
  112. NRF_UARTE_BAUDRATE_76800 = UARTE_BAUDRATE_BAUDRATE_Baud76800, ///< 76800 baud.
  113. NRF_UARTE_BAUDRATE_115200 = UARTE_BAUDRATE_BAUDRATE_Baud115200, ///< 115200 baud.
  114. NRF_UARTE_BAUDRATE_230400 = UARTE_BAUDRATE_BAUDRATE_Baud230400, ///< 230400 baud.
  115. NRF_UARTE_BAUDRATE_250000 = UARTE_BAUDRATE_BAUDRATE_Baud250000, ///< 250000 baud.
  116. NRF_UARTE_BAUDRATE_460800 = UARTE_BAUDRATE_BAUDRATE_Baud460800, ///< 460800 baud.
  117. NRF_UARTE_BAUDRATE_921600 = UARTE_BAUDRATE_BAUDRATE_Baud921600, ///< 921600 baud.
  118. NRF_UARTE_BAUDRATE_1000000 = UARTE_BAUDRATE_BAUDRATE_Baud1M ///< 1000000 baud.
  119. } nrf_uarte_baudrate_t;
  120. /** @brief Types of UARTE error masks. */
  121. typedef enum
  122. {
  123. NRF_UARTE_ERROR_OVERRUN_MASK = UARTE_ERRORSRC_OVERRUN_Msk, ///< Overrun error.
  124. NRF_UARTE_ERROR_PARITY_MASK = UARTE_ERRORSRC_PARITY_Msk, ///< Parity error.
  125. NRF_UARTE_ERROR_FRAMING_MASK = UARTE_ERRORSRC_FRAMING_Msk, ///< Framing error.
  126. NRF_UARTE_ERROR_BREAK_MASK = UARTE_ERRORSRC_BREAK_Msk ///< Break error.
  127. } nrf_uarte_error_mask_t;
  128. /** @brief Types of UARTE parity modes. */
  129. typedef enum
  130. {
  131. NRF_UARTE_PARITY_EXCLUDED = UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos, ///< Parity excluded.
  132. NRF_UARTE_PARITY_INCLUDED = UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos ///< Parity included.
  133. } nrf_uarte_parity_t;
  134. /** @brief Types of UARTE flow control modes. */
  135. typedef enum
  136. {
  137. NRF_UARTE_HWFC_DISABLED = UARTE_CONFIG_HWFC_Disabled << UARTE_CONFIG_HWFC_Pos, ///< Hardware flow control disabled.
  138. NRF_UARTE_HWFC_ENABLED = UARTE_CONFIG_HWFC_Enabled << UARTE_CONFIG_HWFC_Pos ///< Hardware flow control enabled.
  139. } nrf_uarte_hwfc_t;
  140. /**
  141. * @brief Function for clearing the specified UARTE event.
  142. *
  143. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  144. * @param[in] event Event to clear.
  145. */
  146. __STATIC_INLINE void nrf_uarte_event_clear(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event);
  147. /**
  148. * @brief Function for retrieving the state of the UARTE event.
  149. *
  150. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  151. * @param[in] event Event to be checked.
  152. *
  153. * @retval true The event has been generated.
  154. * @retval false The event has not been generated.
  155. */
  156. __STATIC_INLINE bool nrf_uarte_event_check(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event);
  157. /**
  158. * @brief Function for returning the address of the specified UARTE event register.
  159. *
  160. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  161. * @param[in] event The specified event.
  162. *
  163. * @return Address of specified event register.
  164. */
  165. __STATIC_INLINE uint32_t nrf_uarte_event_address_get(NRF_UARTE_Type * p_reg,
  166. nrf_uarte_event_t event);
  167. /**
  168. * @brief Function for enabling UARTE shortcuts.
  169. *
  170. * @param p_reg Pointer to the structure of registers of the peripheral.
  171. * @param mask Shortcuts to be enabled.
  172. */
  173. __STATIC_INLINE void nrf_uarte_shorts_enable(NRF_UARTE_Type * p_reg, uint32_t mask);
  174. /**
  175. * @brief Function for disabling UARTE shortcuts.
  176. *
  177. * @param p_reg Pointer to the structure of registers of the peripheral.
  178. * @param mask Shortcuts to be disabled.
  179. */
  180. __STATIC_INLINE void nrf_uarte_shorts_disable(NRF_UARTE_Type * p_reg, uint32_t mask);
  181. /**
  182. * @brief Function for enabling UARTE interrupts.
  183. *
  184. * @param p_reg Pointer to the structure of registers of the peripheral.
  185. * @param mask Mask of interrupts to be enabled.
  186. */
  187. __STATIC_INLINE void nrf_uarte_int_enable(NRF_UARTE_Type * p_reg, uint32_t mask);
  188. /**
  189. * @brief Function for retrieving the state of the specified interrupt.
  190. *
  191. * @param p_reg Pointer to the structure of registers of the peripheral.
  192. * @param mask Mask of interrupts to be checked.
  193. *
  194. * @retval true The interrupt is enabled.
  195. * @retval false The interrupt is not enabled.
  196. */
  197. __STATIC_INLINE bool nrf_uarte_int_enable_check(NRF_UARTE_Type * p_reg, nrf_uarte_int_mask_t mask);
  198. /**
  199. * @brief Function for disabling the specified interrupts.
  200. *
  201. * @param p_reg Pointer to the structure of registers of the peripheral.
  202. * @param mask Mask of interrupts to be disabled.
  203. */
  204. __STATIC_INLINE void nrf_uarte_int_disable(NRF_UARTE_Type * p_reg, uint32_t mask);
  205. #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  206. /**
  207. * @brief Function for setting the subscribe configuration for a given
  208. * UARTE task.
  209. *
  210. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  211. * @param[in] task Task for which to set the configuration.
  212. * @param[in] channel Channel through which to subscribe events.
  213. */
  214. __STATIC_INLINE void nrf_uarte_subscribe_set(NRF_UARTE_Type * p_reg,
  215. nrf_uarte_task_t task,
  216. uint8_t channel);
  217. /**
  218. * @brief Function for clearing the subscribe configuration for a given
  219. * UARTE task.
  220. *
  221. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  222. * @param[in] task Task for which to clear the configuration.
  223. */
  224. __STATIC_INLINE void nrf_uarte_subscribe_clear(NRF_UARTE_Type * p_reg,
  225. nrf_uarte_task_t task);
  226. /**
  227. * @brief Function for setting the publish configuration for a given
  228. * UARTE event.
  229. *
  230. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  231. * @param[in] event Event for which to set the configuration.
  232. * @param[in] channel Channel through which to publish the event.
  233. */
  234. __STATIC_INLINE void nrf_uarte_publish_set(NRF_UARTE_Type * p_reg,
  235. nrf_uarte_event_t event,
  236. uint8_t channel);
  237. /**
  238. * @brief Function for clearing the publish configuration for a given
  239. * UARTE event.
  240. *
  241. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  242. * @param[in] event Event for which to clear the configuration.
  243. */
  244. __STATIC_INLINE void nrf_uarte_publish_clear(NRF_UARTE_Type * p_reg,
  245. nrf_uarte_event_t event);
  246. #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  247. /**
  248. * @brief Function for getting error source mask. Function is clearing error source flags after reading.
  249. *
  250. * @param p_reg Pointer to the structure of registers of the peripheral.
  251. *
  252. * @return Mask with error source flags.
  253. */
  254. __STATIC_INLINE uint32_t nrf_uarte_errorsrc_get_and_clear(NRF_UARTE_Type * p_reg);
  255. /**
  256. * @brief Function for enabling UARTE.
  257. *
  258. * @param p_reg Pointer to the structure of registers of the peripheral.
  259. */
  260. __STATIC_INLINE void nrf_uarte_enable(NRF_UARTE_Type * p_reg);
  261. /**
  262. * @brief Function for disabling UARTE.
  263. *
  264. * @param p_reg Pointer to the structure of registers of the peripheral.
  265. */
  266. __STATIC_INLINE void nrf_uarte_disable(NRF_UARTE_Type * p_reg);
  267. /**
  268. * @brief Function for configuring TX/RX pins.
  269. *
  270. * @param p_reg Pointer to the structure of registers of the peripheral.
  271. * @param pseltxd TXD pin number.
  272. * @param pselrxd RXD pin number.
  273. */
  274. __STATIC_INLINE void nrf_uarte_txrx_pins_set(NRF_UARTE_Type * p_reg,
  275. uint32_t pseltxd,
  276. uint32_t pselrxd);
  277. /**
  278. * @brief Function for disconnecting TX/RX pins.
  279. *
  280. * @param p_reg Pointer to the structure of registers of the peripheral.
  281. */
  282. __STATIC_INLINE void nrf_uarte_txrx_pins_disconnect(NRF_UARTE_Type * p_reg);
  283. /**
  284. * @brief Function for getting TX pin.
  285. *
  286. * @param p_reg Pointer to the structure of registers of the peripheral.
  287. *
  288. * @return TX pin number.
  289. */
  290. __STATIC_INLINE uint32_t nrf_uarte_tx_pin_get(NRF_UARTE_Type * p_reg);
  291. /**
  292. * @brief Function for getting RX pin.
  293. *
  294. * @param p_reg Pointer to the structure of registers of the peripheral.
  295. *
  296. * @return RX pin number.
  297. */
  298. __STATIC_INLINE uint32_t nrf_uarte_rx_pin_get(NRF_UARTE_Type * p_reg);
  299. /**
  300. * @brief Function for getting RTS pin.
  301. *
  302. * @param p_reg Pointer to the structure of registers of the peripheral.
  303. *
  304. * @return RTS pin number.
  305. */
  306. __STATIC_INLINE uint32_t nrf_uarte_rts_pin_get(NRF_UARTE_Type * p_reg);
  307. /**
  308. * @brief Function for getting CTS pin.
  309. *
  310. * @param p_reg Pointer to the structure of registers of the peripheral.
  311. *
  312. * @return CTS pin number.
  313. */
  314. __STATIC_INLINE uint32_t nrf_uarte_cts_pin_get(NRF_UARTE_Type * p_reg);
  315. /**
  316. * @brief Function for configuring flow control pins.
  317. *
  318. * @param p_reg Pointer to the structure of registers of the peripheral.
  319. * @param pselrts RTS pin number.
  320. * @param pselcts CTS pin number.
  321. */
  322. __STATIC_INLINE void nrf_uarte_hwfc_pins_set(NRF_UARTE_Type * p_reg,
  323. uint32_t pselrts,
  324. uint32_t pselcts);
  325. /**
  326. * @brief Function for disconnecting flow control pins.
  327. *
  328. * @param p_reg Pointer to the structure of registers of the peripheral.
  329. */
  330. __STATIC_INLINE void nrf_uarte_hwfc_pins_disconnect(NRF_UARTE_Type * p_reg);
  331. /**
  332. * @brief Function for starting an UARTE task.
  333. *
  334. * @param p_reg Pointer to the structure of registers of the peripheral.
  335. * @param task Task.
  336. */
  337. __STATIC_INLINE void nrf_uarte_task_trigger(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
  338. /**
  339. * @brief Function for returning the address of the specified task register.
  340. *
  341. * @param p_reg Pointer to the structure of registers of the peripheral.
  342. * @param task Task.
  343. *
  344. * @return Task address.
  345. */
  346. __STATIC_INLINE uint32_t nrf_uarte_task_address_get(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
  347. /**
  348. * @brief Function for configuring UARTE.
  349. *
  350. * @param p_reg Pointer to the structure of registers of the peripheral.
  351. * @param hwfc Hardware flow control. Enabled if true.
  352. * @param parity Parity. Included if true.
  353. */
  354. __STATIC_INLINE void nrf_uarte_configure(NRF_UARTE_Type * p_reg,
  355. nrf_uarte_parity_t parity,
  356. nrf_uarte_hwfc_t hwfc);
  357. /**
  358. * @brief Function for setting UARTE baud rate.
  359. *
  360. * @param p_reg Pointer to the structure of registers of the peripheral.
  361. * @param baudrate Baud rate.
  362. */
  363. __STATIC_INLINE void nrf_uarte_baudrate_set(NRF_UARTE_Type * p_reg, nrf_uarte_baudrate_t baudrate);
  364. /**
  365. * @brief Function for setting the transmit buffer.
  366. *
  367. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  368. * @param[in] p_buffer Pointer to the buffer with data to send.
  369. * @param[in] length Maximum number of data bytes to transmit.
  370. */
  371. __STATIC_INLINE void nrf_uarte_tx_buffer_set(NRF_UARTE_Type * p_reg,
  372. uint8_t const * p_buffer,
  373. size_t length);
  374. /**
  375. * @brief Function for getting number of bytes transmitted in the last transaction.
  376. *
  377. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  378. *
  379. * @retval Amount of bytes transmitted.
  380. */
  381. __STATIC_INLINE uint32_t nrf_uarte_tx_amount_get(NRF_UARTE_Type * p_reg);
  382. /**
  383. * @brief Function for setting the receive buffer.
  384. *
  385. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  386. * @param[in] p_buffer Pointer to the buffer for received data.
  387. * @param[in] length Maximum number of data bytes to receive.
  388. */
  389. __STATIC_INLINE void nrf_uarte_rx_buffer_set(NRF_UARTE_Type * p_reg,
  390. uint8_t * p_buffer,
  391. size_t length);
  392. /**
  393. * @brief Function for getting number of bytes received in the last transaction.
  394. *
  395. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  396. *
  397. * @retval Amount of bytes received.
  398. */
  399. __STATIC_INLINE uint32_t nrf_uarte_rx_amount_get(NRF_UARTE_Type * p_reg);
  400. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  401. __STATIC_INLINE void nrf_uarte_event_clear(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event)
  402. {
  403. *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
  404. #if __CORTEX_M == 0x04
  405. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
  406. (void)dummy;
  407. #endif
  408. }
  409. __STATIC_INLINE bool nrf_uarte_event_check(NRF_UARTE_Type * p_reg, nrf_uarte_event_t event)
  410. {
  411. return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
  412. }
  413. __STATIC_INLINE uint32_t nrf_uarte_event_address_get(NRF_UARTE_Type * p_reg,
  414. nrf_uarte_event_t event)
  415. {
  416. return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
  417. }
  418. __STATIC_INLINE void nrf_uarte_shorts_enable(NRF_UARTE_Type * p_reg, uint32_t mask)
  419. {
  420. p_reg->SHORTS |= mask;
  421. }
  422. __STATIC_INLINE void nrf_uarte_shorts_disable(NRF_UARTE_Type * p_reg, uint32_t mask)
  423. {
  424. p_reg->SHORTS &= ~(mask);
  425. }
  426. __STATIC_INLINE void nrf_uarte_int_enable(NRF_UARTE_Type * p_reg, uint32_t mask)
  427. {
  428. p_reg->INTENSET = mask;
  429. }
  430. __STATIC_INLINE bool nrf_uarte_int_enable_check(NRF_UARTE_Type * p_reg, nrf_uarte_int_mask_t mask)
  431. {
  432. return (bool)(p_reg->INTENSET & mask);
  433. }
  434. __STATIC_INLINE void nrf_uarte_int_disable(NRF_UARTE_Type * p_reg, uint32_t mask)
  435. {
  436. p_reg->INTENCLR = mask;
  437. }
  438. #if defined(DPPI_PRESENT)
  439. __STATIC_INLINE void nrf_uarte_subscribe_set(NRF_UARTE_Type * p_reg,
  440. nrf_uarte_task_t task,
  441. uint8_t channel)
  442. {
  443. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
  444. ((uint32_t)channel | UARTE_SUBSCRIBE_STARTRX_EN_Msk);
  445. }
  446. __STATIC_INLINE void nrf_uarte_subscribe_clear(NRF_UARTE_Type * p_reg,
  447. nrf_uarte_task_t task)
  448. {
  449. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
  450. }
  451. __STATIC_INLINE void nrf_uarte_publish_set(NRF_UARTE_Type * p_reg,
  452. nrf_uarte_event_t event,
  453. uint8_t channel)
  454. {
  455. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
  456. ((uint32_t)channel | UARTE_PUBLISH_CTS_EN_Msk);
  457. }
  458. __STATIC_INLINE void nrf_uarte_publish_clear(NRF_UARTE_Type * p_reg,
  459. nrf_uarte_event_t event)
  460. {
  461. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
  462. }
  463. #endif // defined(DPPI_PRESENT)
  464. __STATIC_INLINE uint32_t nrf_uarte_errorsrc_get_and_clear(NRF_UARTE_Type * p_reg)
  465. {
  466. uint32_t errsrc_mask = p_reg->ERRORSRC;
  467. p_reg->ERRORSRC = errsrc_mask;
  468. return errsrc_mask;
  469. }
  470. __STATIC_INLINE void nrf_uarte_enable(NRF_UARTE_Type * p_reg)
  471. {
  472. p_reg->ENABLE = UARTE_ENABLE_ENABLE_Enabled;
  473. }
  474. __STATIC_INLINE void nrf_uarte_disable(NRF_UARTE_Type * p_reg)
  475. {
  476. p_reg->ENABLE = UARTE_ENABLE_ENABLE_Disabled;
  477. }
  478. __STATIC_INLINE void nrf_uarte_txrx_pins_set(NRF_UARTE_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd)
  479. {
  480. p_reg->PSEL.TXD = pseltxd;
  481. p_reg->PSEL.RXD = pselrxd;
  482. }
  483. __STATIC_INLINE void nrf_uarte_txrx_pins_disconnect(NRF_UARTE_Type * p_reg)
  484. {
  485. nrf_uarte_txrx_pins_set(p_reg, NRF_UARTE_PSEL_DISCONNECTED, NRF_UARTE_PSEL_DISCONNECTED);
  486. }
  487. __STATIC_INLINE uint32_t nrf_uarte_tx_pin_get(NRF_UARTE_Type * p_reg)
  488. {
  489. return p_reg->PSEL.TXD;
  490. }
  491. __STATIC_INLINE uint32_t nrf_uarte_rx_pin_get(NRF_UARTE_Type * p_reg)
  492. {
  493. return p_reg->PSEL.RXD;
  494. }
  495. __STATIC_INLINE uint32_t nrf_uarte_rts_pin_get(NRF_UARTE_Type * p_reg)
  496. {
  497. return p_reg->PSEL.RTS;
  498. }
  499. __STATIC_INLINE uint32_t nrf_uarte_cts_pin_get(NRF_UARTE_Type * p_reg)
  500. {
  501. return p_reg->PSEL.CTS;
  502. }
  503. __STATIC_INLINE void nrf_uarte_hwfc_pins_set(NRF_UARTE_Type * p_reg, uint32_t pselrts, uint32_t pselcts)
  504. {
  505. p_reg->PSEL.RTS = pselrts;
  506. p_reg->PSEL.CTS = pselcts;
  507. }
  508. __STATIC_INLINE void nrf_uarte_hwfc_pins_disconnect(NRF_UARTE_Type * p_reg)
  509. {
  510. nrf_uarte_hwfc_pins_set(p_reg, NRF_UARTE_PSEL_DISCONNECTED, NRF_UARTE_PSEL_DISCONNECTED);
  511. }
  512. __STATIC_INLINE void nrf_uarte_task_trigger(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task)
  513. {
  514. *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
  515. }
  516. __STATIC_INLINE uint32_t nrf_uarte_task_address_get(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task)
  517. {
  518. return (uint32_t)p_reg + (uint32_t)task;
  519. }
  520. __STATIC_INLINE void nrf_uarte_configure(NRF_UARTE_Type * p_reg,
  521. nrf_uarte_parity_t parity,
  522. nrf_uarte_hwfc_t hwfc)
  523. {
  524. p_reg->CONFIG = (uint32_t)parity | (uint32_t)hwfc;
  525. }
  526. __STATIC_INLINE void nrf_uarte_baudrate_set(NRF_UARTE_Type * p_reg, nrf_uarte_baudrate_t baudrate)
  527. {
  528. p_reg->BAUDRATE = baudrate;
  529. }
  530. __STATIC_INLINE void nrf_uarte_tx_buffer_set(NRF_UARTE_Type * p_reg,
  531. uint8_t const * p_buffer,
  532. size_t length)
  533. {
  534. p_reg->TXD.PTR = (uint32_t)p_buffer;
  535. p_reg->TXD.MAXCNT = length;
  536. }
  537. __STATIC_INLINE uint32_t nrf_uarte_tx_amount_get(NRF_UARTE_Type * p_reg)
  538. {
  539. return p_reg->TXD.AMOUNT;
  540. }
  541. __STATIC_INLINE void nrf_uarte_rx_buffer_set(NRF_UARTE_Type * p_reg,
  542. uint8_t * p_buffer,
  543. size_t length)
  544. {
  545. p_reg->RXD.PTR = (uint32_t)p_buffer;
  546. p_reg->RXD.MAXCNT = length;
  547. }
  548. __STATIC_INLINE uint32_t nrf_uarte_rx_amount_get(NRF_UARTE_Type * p_reg)
  549. {
  550. return p_reg->RXD.AMOUNT;
  551. }
  552. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  553. /** @} */
  554. #ifdef __cplusplus
  555. }
  556. #endif
  557. #endif //NRF_UARTE_H__