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