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