Copy of nRF51822 library
Fork of nRF51822 by
nordic/nrf-sdk/app_common/app_uart.h@0:eff01767de02, 2014-03-26 (annotated)
- Committer:
- bogdanm
- Date:
- Wed Mar 26 14:38:17 2014 +0000
- Revision:
- 0:eff01767de02
- Child:
- 37:c29c330d942c
Initial import of the nRF51822 code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
bogdanm | 0:eff01767de02 | 2 | * |
bogdanm | 0:eff01767de02 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
bogdanm | 0:eff01767de02 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
bogdanm | 0:eff01767de02 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
bogdanm | 0:eff01767de02 | 6 | * |
bogdanm | 0:eff01767de02 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
bogdanm | 0:eff01767de02 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
bogdanm | 0:eff01767de02 | 9 | * the file. |
bogdanm | 0:eff01767de02 | 10 | * |
bogdanm | 0:eff01767de02 | 11 | */ |
bogdanm | 0:eff01767de02 | 12 | |
bogdanm | 0:eff01767de02 | 13 | /**@file |
bogdanm | 0:eff01767de02 | 14 | * |
bogdanm | 0:eff01767de02 | 15 | * @defgroup app_uart UART module |
bogdanm | 0:eff01767de02 | 16 | * @{ |
bogdanm | 0:eff01767de02 | 17 | * @ingroup app_common |
bogdanm | 0:eff01767de02 | 18 | * |
bogdanm | 0:eff01767de02 | 19 | * @brief UART module interface. |
bogdanm | 0:eff01767de02 | 20 | */ |
bogdanm | 0:eff01767de02 | 21 | |
bogdanm | 0:eff01767de02 | 22 | #ifndef APP_UART_H__ |
bogdanm | 0:eff01767de02 | 23 | #define APP_UART_H__ |
bogdanm | 0:eff01767de02 | 24 | |
bogdanm | 0:eff01767de02 | 25 | #include <stdint.h> |
bogdanm | 0:eff01767de02 | 26 | #include <stdbool.h> |
bogdanm | 0:eff01767de02 | 27 | #include "nordic_global.h" |
bogdanm | 0:eff01767de02 | 28 | #include "app_util.h" |
bogdanm | 0:eff01767de02 | 29 | |
bogdanm | 0:eff01767de02 | 30 | #define UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */ |
bogdanm | 0:eff01767de02 | 31 | |
bogdanm | 0:eff01767de02 | 32 | /**@brief UART Flow Control modes for the peripheral. |
bogdanm | 0:eff01767de02 | 33 | */ |
bogdanm | 0:eff01767de02 | 34 | typedef enum |
bogdanm | 0:eff01767de02 | 35 | { |
bogdanm | 0:eff01767de02 | 36 | APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */ |
bogdanm | 0:eff01767de02 | 37 | APP_UART_FLOW_CONTROL_ENABLED, /**< Standard UART Hw Flow Control is enabled. */ |
bogdanm | 0:eff01767de02 | 38 | APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the nRF51 to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the nRF51 to safe power by only using the UART module when it is needed by the remote site. */ |
bogdanm | 0:eff01767de02 | 39 | } app_uart_flow_control_t; |
bogdanm | 0:eff01767de02 | 40 | |
bogdanm | 0:eff01767de02 | 41 | /**@brief UART communication structure holding configuration settings for the peripheral. |
bogdanm | 0:eff01767de02 | 42 | */ |
bogdanm | 0:eff01767de02 | 43 | typedef struct |
bogdanm | 0:eff01767de02 | 44 | { |
bogdanm | 0:eff01767de02 | 45 | uint8_t rx_pin_no; /**< RX pin number. */ |
bogdanm | 0:eff01767de02 | 46 | uint8_t tx_pin_no; /**< TX pin number. */ |
bogdanm | 0:eff01767de02 | 47 | uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */ |
bogdanm | 0:eff01767de02 | 48 | uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */ |
bogdanm | 0:eff01767de02 | 49 | app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */ |
bogdanm | 0:eff01767de02 | 50 | bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */ |
bogdanm | 0:eff01767de02 | 51 | uint32_t baud_rate; /**< Baud rate configuration. */ |
bogdanm | 0:eff01767de02 | 52 | } app_uart_comm_params_t; |
bogdanm | 0:eff01767de02 | 53 | |
bogdanm | 0:eff01767de02 | 54 | /**@brief UART buffer for transmitting/receiving data. |
bogdanm | 0:eff01767de02 | 55 | */ |
bogdanm | 0:eff01767de02 | 56 | typedef struct |
bogdanm | 0:eff01767de02 | 57 | { |
bogdanm | 0:eff01767de02 | 58 | uint8_t * rx_buf; /**< Pointer to the RX buffer. */ |
bogdanm | 0:eff01767de02 | 59 | uint32_t rx_buf_size; /**< Size of the RX buffer. */ |
bogdanm | 0:eff01767de02 | 60 | uint8_t * tx_buf; /**< Pointer to the TX buffer. */ |
bogdanm | 0:eff01767de02 | 61 | uint32_t tx_buf_size; /**< Size of the TX buffer. */ |
bogdanm | 0:eff01767de02 | 62 | } app_uart_buffers_t; |
bogdanm | 0:eff01767de02 | 63 | |
bogdanm | 0:eff01767de02 | 64 | /**@brief Enumeration describing current state of the UART. |
bogdanm | 0:eff01767de02 | 65 | * |
bogdanm | 0:eff01767de02 | 66 | * @details The connection state can be fetched by the application using the function call |
bogdanm | 0:eff01767de02 | 67 | * @ref app_uart_get_connection_state. |
bogdanm | 0:eff01767de02 | 68 | * When hardware flow control is used |
bogdanm | 0:eff01767de02 | 69 | * - APP_UART_CONNECTED: Communication is ongoing. |
bogdanm | 0:eff01767de02 | 70 | * - APP_UART_DISCONNECTED: No communication is ongoing. |
bogdanm | 0:eff01767de02 | 71 | * |
bogdanm | 0:eff01767de02 | 72 | * When no hardware flow control is used |
bogdanm | 0:eff01767de02 | 73 | * - APP_UART_CONNECTED: Always returned as bytes can always be received/transmitted. |
bogdanm | 0:eff01767de02 | 74 | */ |
bogdanm | 0:eff01767de02 | 75 | typedef enum |
bogdanm | 0:eff01767de02 | 76 | { |
bogdanm | 0:eff01767de02 | 77 | APP_UART_DISCONNECTED, /**< State indicating that the UART is disconnected and cannot receive or transmit bytes. */ |
bogdanm | 0:eff01767de02 | 78 | APP_UART_CONNECTED /**< State indicating that the UART is connected and ready to receive or transmit bytes. If flow control is disabled, the state will always be connected. */ |
bogdanm | 0:eff01767de02 | 79 | } app_uart_connection_state_t; |
bogdanm | 0:eff01767de02 | 80 | |
bogdanm | 0:eff01767de02 | 81 | /**@brief Enumeration which defines events used by the UART module upon data reception or error. |
bogdanm | 0:eff01767de02 | 82 | * |
bogdanm | 0:eff01767de02 | 83 | * @details The event type is used to indicate the type of additional information in the event |
bogdanm | 0:eff01767de02 | 84 | * @ref app_uart_evt_t. |
bogdanm | 0:eff01767de02 | 85 | */ |
bogdanm | 0:eff01767de02 | 86 | typedef enum |
bogdanm | 0:eff01767de02 | 87 | { |
bogdanm | 0:eff01767de02 | 88 | APP_UART_DATA_READY, /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */ |
bogdanm | 0:eff01767de02 | 89 | APP_UART_FIFO_ERROR, /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */ |
bogdanm | 0:eff01767de02 | 90 | APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */ |
bogdanm | 0:eff01767de02 | 91 | APP_UART_TX_EMPTY, /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */ |
bogdanm | 0:eff01767de02 | 92 | APP_UART_DATA, /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */ |
bogdanm | 0:eff01767de02 | 93 | } app_uart_evt_type_t; |
bogdanm | 0:eff01767de02 | 94 | |
bogdanm | 0:eff01767de02 | 95 | /**@brief Struct containing events from the UART module. |
bogdanm | 0:eff01767de02 | 96 | * |
bogdanm | 0:eff01767de02 | 97 | * @details The app_uart_evt_t is used to notify the application of asynchronous events when data |
bogdanm | 0:eff01767de02 | 98 | * are received on the UART peripheral or in case an error occured during data reception. |
bogdanm | 0:eff01767de02 | 99 | */ |
bogdanm | 0:eff01767de02 | 100 | typedef struct |
bogdanm | 0:eff01767de02 | 101 | { |
bogdanm | 0:eff01767de02 | 102 | app_uart_evt_type_t evt_type; /**< Type of event. */ |
bogdanm | 0:eff01767de02 | 103 | union |
bogdanm | 0:eff01767de02 | 104 | { |
bogdanm | 0:eff01767de02 | 105 | uint32_t error_communication;/**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from @ref nrf51_bitfields.h can be used to parse the error code. See also the nRF51 Series Reference Manual for specification. */ |
bogdanm | 0:eff01767de02 | 106 | uint32_t error_code; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ |
bogdanm | 0:eff01767de02 | 107 | uint8_t value; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ |
bogdanm | 0:eff01767de02 | 108 | } data; |
bogdanm | 0:eff01767de02 | 109 | } app_uart_evt_t; |
bogdanm | 0:eff01767de02 | 110 | |
bogdanm | 0:eff01767de02 | 111 | /**@brief Function for handling app_uart event callback. |
bogdanm | 0:eff01767de02 | 112 | * |
bogdanm | 0:eff01767de02 | 113 | * @details Upon an event in the app_uart module this callback function will be called to notify |
bogdanm | 0:eff01767de02 | 114 | * the applicatioon about the event. |
bogdanm | 0:eff01767de02 | 115 | * |
bogdanm | 0:eff01767de02 | 116 | * @param[in] p_app_uart_event Pointer to UART event. |
bogdanm | 0:eff01767de02 | 117 | */ |
bogdanm | 0:eff01767de02 | 118 | typedef void (*app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event); |
bogdanm | 0:eff01767de02 | 119 | |
bogdanm | 0:eff01767de02 | 120 | /**@brief Macro for safe initialization of the UART module in a single user instance when using |
bogdanm | 0:eff01767de02 | 121 | * a FIFO together with UART. |
bogdanm | 0:eff01767de02 | 122 | * |
bogdanm | 0:eff01767de02 | 123 | * @param[in] P_COMM_PARAMS Pointer to a UART communication structure: app_uart_comm_params_t |
bogdanm | 0:eff01767de02 | 124 | * @param[in] RX_BUF_SIZE Size of desired RX buffer, must be a power of 2 or ZERO (No FIFO). |
bogdanm | 0:eff01767de02 | 125 | * @param[in] TX_BUF_SIZE Size of desired TX buffer, must be a power of 2 or ZERO (No FIFO). |
bogdanm | 0:eff01767de02 | 126 | * @param[in] EVENT_HANDLER Event handler function to be called when an event occurs in the |
bogdanm | 0:eff01767de02 | 127 | * UART module. |
bogdanm | 0:eff01767de02 | 128 | * @param[in] IRQ_PRIO IRQ priority, app_irq_priority_t, for the UART module irq handler. |
bogdanm | 0:eff01767de02 | 129 | * @param[out] ERR_CODE The return value of the UART initialization function will be |
bogdanm | 0:eff01767de02 | 130 | * written to this parameter. |
bogdanm | 0:eff01767de02 | 131 | * |
bogdanm | 0:eff01767de02 | 132 | * @note Since this macro allocates a buffer and registers the module as a GPIOTE user when flow |
bogdanm | 0:eff01767de02 | 133 | * control is enabled, it must only be called once. |
bogdanm | 0:eff01767de02 | 134 | */ |
bogdanm | 0:eff01767de02 | 135 | #define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE)\ |
bogdanm | 0:eff01767de02 | 136 | do \ |
bogdanm | 0:eff01767de02 | 137 | { \ |
bogdanm | 0:eff01767de02 | 138 | uint16_t APP_UART_UID = 0; \ |
bogdanm | 0:eff01767de02 | 139 | app_uart_buffers_t buffers; \ |
bogdanm | 0:eff01767de02 | 140 | static uint8_t rx_buf[RX_BUF_SIZE]; \ |
bogdanm | 0:eff01767de02 | 141 | static uint8_t tx_buf[TX_BUF_SIZE]; \ |
bogdanm | 0:eff01767de02 | 142 | \ |
bogdanm | 0:eff01767de02 | 143 | buffers.rx_buf = rx_buf; \ |
bogdanm | 0:eff01767de02 | 144 | buffers.rx_buf_size = sizeof(rx_buf); \ |
bogdanm | 0:eff01767de02 | 145 | buffers.tx_buf = tx_buf; \ |
bogdanm | 0:eff01767de02 | 146 | buffers.tx_buf_size = sizeof(tx_buf); \ |
bogdanm | 0:eff01767de02 | 147 | ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO, &APP_UART_UID); \ |
bogdanm | 0:eff01767de02 | 148 | } while (0) |
bogdanm | 0:eff01767de02 | 149 | |
bogdanm | 0:eff01767de02 | 150 | /**@brief Macro for safe initialization of the UART module in a single user instance. |
bogdanm | 0:eff01767de02 | 151 | * |
bogdanm | 0:eff01767de02 | 152 | * @param[in] P_COMM_PARAMS Pointer to a UART communication structure: app_uart_comm_params_t |
bogdanm | 0:eff01767de02 | 153 | * @param[in] EVENT_HANDLER Event handler function to be called when an event occurs in the |
bogdanm | 0:eff01767de02 | 154 | * UART module. |
bogdanm | 0:eff01767de02 | 155 | * @param[in] IRQ_PRIO IRQ priority, app_irq_priority_t, for the UART module irq handler. |
bogdanm | 0:eff01767de02 | 156 | * @param[out] ERR_CODE The return value of the UART initialization function will be |
bogdanm | 0:eff01767de02 | 157 | * written to this parameter. |
bogdanm | 0:eff01767de02 | 158 | * |
bogdanm | 0:eff01767de02 | 159 | * @note Since this macro allocates registers the module as a GPIOTE user when flow control is |
bogdanm | 0:eff01767de02 | 160 | * enabled, it must only be called once. |
bogdanm | 0:eff01767de02 | 161 | */ |
bogdanm | 0:eff01767de02 | 162 | #define APP_UART_INIT(P_COMM_PARAMS, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \ |
bogdanm | 0:eff01767de02 | 163 | do \ |
bogdanm | 0:eff01767de02 | 164 | { \ |
bogdanm | 0:eff01767de02 | 165 | uint16_t APP_UART_UID = 0; \ |
bogdanm | 0:eff01767de02 | 166 | ERR_CODE = app_uart_init(P_COMM_PARAMS, NULL, EVT_HANDLER, IRQ_PRIO, &APP_UART_UID); \ |
bogdanm | 0:eff01767de02 | 167 | } while (0) |
bogdanm | 0:eff01767de02 | 168 | |
bogdanm | 0:eff01767de02 | 169 | /**@brief Function for initializing the UART module. Use this initialization when several instances of the UART |
bogdanm | 0:eff01767de02 | 170 | * module are needed. |
bogdanm | 0:eff01767de02 | 171 | * |
bogdanm | 0:eff01767de02 | 172 | * @details This initialization will return a UART user id for the caller. The UART user id must be |
bogdanm | 0:eff01767de02 | 173 | * used upon re-initialization of the UART or closing of the module for the user. |
bogdanm | 0:eff01767de02 | 174 | * If single instance usage is needed, the APP_UART_INIT() macro should be used instead. |
bogdanm | 0:eff01767de02 | 175 | * |
bogdanm | 0:eff01767de02 | 176 | * @note Normally single instance initialization should be done using the APP_UART_INIT() or |
bogdanm | 0:eff01767de02 | 177 | * APP_UART_INIT_FIFO() macro depending on whether the FIFO should be used by the UART, as |
bogdanm | 0:eff01767de02 | 178 | * that will allocate the buffers needed by the UART module (including aligning the buffer |
bogdanm | 0:eff01767de02 | 179 | * correctly). |
bogdanm | 0:eff01767de02 | 180 | |
bogdanm | 0:eff01767de02 | 181 | * @param[in] p_comm_params Pin and communication parameters. |
bogdanm | 0:eff01767de02 | 182 | * @param[in] p_buffers RX and TX buffers, NULL is FIFO is not used. |
bogdanm | 0:eff01767de02 | 183 | * @param[in] error_handler Function to be called in case of an error. |
bogdanm | 0:eff01767de02 | 184 | * @param[in] app_irq_priority Interrupt priority level. |
bogdanm | 0:eff01767de02 | 185 | * @param[in,out] p_uart_uid User id for the UART module. The p_uart_uid must be used if |
bogdanm | 0:eff01767de02 | 186 | * re-initialization and/or closing of the UART module is needed. |
bogdanm | 0:eff01767de02 | 187 | * If the value pointed to by p_uart_uid is zero, this is |
bogdanm | 0:eff01767de02 | 188 | * considdered a first time initialization. Otherwise this is |
bogdanm | 0:eff01767de02 | 189 | * considered a re-initialization for the user with id *p_uart_uid. |
bogdanm | 0:eff01767de02 | 190 | * |
bogdanm | 0:eff01767de02 | 191 | * @retval NRF_SUCCESS If successful initialization. |
bogdanm | 0:eff01767de02 | 192 | * @retval NRF_ERROR_INVALID_LENGTH If a provided buffer is not a power of two. |
bogdanm | 0:eff01767de02 | 193 | * @retval NRF_ERROR_NULL If one of the provided buffers is a NULL pointer. |
bogdanm | 0:eff01767de02 | 194 | * |
bogdanm | 0:eff01767de02 | 195 | * Those errors are propagated by the UART module to the caller upon registration when Hardware Flow |
bogdanm | 0:eff01767de02 | 196 | * Control is enabled. When Hardware Flow Control is not used, those errors cannot occur. |
bogdanm | 0:eff01767de02 | 197 | * @retval NRF_ERROR_INVALID_STATE The GPIOTE module is not in a valid state when registering |
bogdanm | 0:eff01767de02 | 198 | * the UART module as a user. |
bogdanm | 0:eff01767de02 | 199 | * @retval NRF_ERROR_INVALID_PARAM The UART module provides an invalid callback function when |
bogdanm | 0:eff01767de02 | 200 | * registering the UART module as a user. |
bogdanm | 0:eff01767de02 | 201 | * Or the value pointed to by *p_uart_uid is not a valid |
bogdanm | 0:eff01767de02 | 202 | * GPIOTE number. |
bogdanm | 0:eff01767de02 | 203 | * @retval NRF_ERROR_NO_MEM GPIOTE module has reached the maximum number of users. |
bogdanm | 0:eff01767de02 | 204 | */ |
bogdanm | 0:eff01767de02 | 205 | uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params, |
bogdanm | 0:eff01767de02 | 206 | app_uart_buffers_t * p_buffers, |
bogdanm | 0:eff01767de02 | 207 | app_uart_event_handler_t error_handler, |
bogdanm | 0:eff01767de02 | 208 | app_irq_priority_t irq_priority, |
bogdanm | 0:eff01767de02 | 209 | uint16_t * p_uart_uid); |
bogdanm | 0:eff01767de02 | 210 | |
bogdanm | 0:eff01767de02 | 211 | /**@brief Function for getting a byte from the UART. |
bogdanm | 0:eff01767de02 | 212 | * |
bogdanm | 0:eff01767de02 | 213 | * @details This function will get the next byte from the RX buffer. If the RX buffer is empty |
bogdanm | 0:eff01767de02 | 214 | * an error code will be returned and the app_uart module will generate an event upon |
bogdanm | 0:eff01767de02 | 215 | * reception of the first byte which is added to the RX buffer. |
bogdanm | 0:eff01767de02 | 216 | * |
bogdanm | 0:eff01767de02 | 217 | * @param[out] p_byte Pointer to an address where next byte received on the UART will be copied. |
bogdanm | 0:eff01767de02 | 218 | * |
bogdanm | 0:eff01767de02 | 219 | * @retval NRF_SUCCESS If a byte has been received and pushed to the pointer provided. |
bogdanm | 0:eff01767de02 | 220 | * @retval NRF_ERROR_NOT_FOUND If no byte is available in the RX buffer of the app_uart module. |
bogdanm | 0:eff01767de02 | 221 | */ |
bogdanm | 0:eff01767de02 | 222 | uint32_t app_uart_get(uint8_t * p_byte); |
bogdanm | 0:eff01767de02 | 223 | |
bogdanm | 0:eff01767de02 | 224 | /**@brief Function for putting a byte on the UART. |
bogdanm | 0:eff01767de02 | 225 | * |
bogdanm | 0:eff01767de02 | 226 | * @details This call is non-blocking. |
bogdanm | 0:eff01767de02 | 227 | * |
bogdanm | 0:eff01767de02 | 228 | * @param[in] byte Byte to be transmitted on the UART. |
bogdanm | 0:eff01767de02 | 229 | * |
bogdanm | 0:eff01767de02 | 230 | * @retval NRF_SUCCESS If the byte was succesfully put on the TX buffer for transmission. |
bogdanm | 0:eff01767de02 | 231 | * @retval NRF_ERROR_NO_MEM If no more space is available in the TX buffer. |
bogdanm | 0:eff01767de02 | 232 | * NRF_ERROR_NO_MEM may occur if flow control is enabled and CTS signal |
bogdanm | 0:eff01767de02 | 233 | * is high for a long period and the buffer fills up. |
bogdanm | 0:eff01767de02 | 234 | */ |
bogdanm | 0:eff01767de02 | 235 | uint32_t app_uart_put(uint8_t byte); |
bogdanm | 0:eff01767de02 | 236 | |
bogdanm | 0:eff01767de02 | 237 | /**@brief Function for getting the current state of the UART. |
bogdanm | 0:eff01767de02 | 238 | * |
bogdanm | 0:eff01767de02 | 239 | * @details If flow control is disabled, the state is assumed to always be APP_UART_CONNECTED. |
bogdanm | 0:eff01767de02 | 240 | * |
bogdanm | 0:eff01767de02 | 241 | * When using flow control the state will be controlled by the CTS. If CTS is set active |
bogdanm | 0:eff01767de02 | 242 | * by the remote side, or the app_uart module is in the process of transmitting a byte, |
bogdanm | 0:eff01767de02 | 243 | * app_uart is in APP_UART_CONNECTED state. If CTS is set inactive by remote side app_uart |
bogdanm | 0:eff01767de02 | 244 | * will not get into APP_UART_DISCONNECTED state until the last byte in the TXD register |
bogdanm | 0:eff01767de02 | 245 | * is fully transmitted. |
bogdanm | 0:eff01767de02 | 246 | * |
bogdanm | 0:eff01767de02 | 247 | * Internal states in the state machine are mapped to the general connected/disconnected |
bogdanm | 0:eff01767de02 | 248 | * states in the following ways: |
bogdanm | 0:eff01767de02 | 249 | * |
bogdanm | 0:eff01767de02 | 250 | * - UART_ON = CONNECTED |
bogdanm | 0:eff01767de02 | 251 | * - UART_READY = CONNECTED |
bogdanm | 0:eff01767de02 | 252 | * - UART_WAIT = CONNECTED |
bogdanm | 0:eff01767de02 | 253 | * - UART_OFF = DISCONNECTED. |
bogdanm | 0:eff01767de02 | 254 | * |
bogdanm | 0:eff01767de02 | 255 | * @param[out] p_connection_state Current connection state of the UART. |
bogdanm | 0:eff01767de02 | 256 | * |
bogdanm | 0:eff01767de02 | 257 | * @retval NRF_SUCCESS The connection state was succesfully retrieved. |
bogdanm | 0:eff01767de02 | 258 | */ |
bogdanm | 0:eff01767de02 | 259 | uint32_t app_uart_get_connection_state(app_uart_connection_state_t * p_connection_state); |
bogdanm | 0:eff01767de02 | 260 | |
bogdanm | 0:eff01767de02 | 261 | /**@brief Function for flushing the RX and TX buffers (Only valid if FIFO is used). |
bogdanm | 0:eff01767de02 | 262 | * This function does nothing if FIFO is not used. |
bogdanm | 0:eff01767de02 | 263 | * |
bogdanm | 0:eff01767de02 | 264 | * @retval NRF_SUCCESS Flushing completed (Current implementation will always succeed). |
bogdanm | 0:eff01767de02 | 265 | */ |
bogdanm | 0:eff01767de02 | 266 | uint32_t app_uart_flush(void); |
bogdanm | 0:eff01767de02 | 267 | |
bogdanm | 0:eff01767de02 | 268 | /**@brief Function for closing the UART module. |
bogdanm | 0:eff01767de02 | 269 | * |
bogdanm | 0:eff01767de02 | 270 | * @details This function will close any on-going UART transmissions and disable itself in the |
bogdanm | 0:eff01767de02 | 271 | * GPTIO module. |
bogdanm | 0:eff01767de02 | 272 | * |
bogdanm | 0:eff01767de02 | 273 | * @param[in] app_uart_uid User id for the UART module. The app_uart_uid must be identical to the |
bogdanm | 0:eff01767de02 | 274 | * UART id returned on initialization and which is currently in use. |
bogdanm | 0:eff01767de02 | 275 | |
bogdanm | 0:eff01767de02 | 276 | * @retval NRF_SUCCESS If successfully closed. |
bogdanm | 0:eff01767de02 | 277 | * @retval NRF_ERROR_INVALID_PARAM If an invalid user id is provided or the user id differs from |
bogdanm | 0:eff01767de02 | 278 | * the current active user. |
bogdanm | 0:eff01767de02 | 279 | */ |
bogdanm | 0:eff01767de02 | 280 | uint32_t app_uart_close(uint16_t app_uart_id); |
bogdanm | 0:eff01767de02 | 281 | |
bogdanm | 0:eff01767de02 | 282 | |
bogdanm | 0:eff01767de02 | 283 | #endif // APP_UART_H__ |
bogdanm | 0:eff01767de02 | 284 | |
bogdanm | 0:eff01767de02 | 285 | /** @} */ |