Forked.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
0:9b334a45a8ff
Child:
149:156823d33999
This updates the lib to the mbed lib v125

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2006-2013 ARM Limited
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16 #ifndef MBED_SERIAL_API_H
<> 144:ef7eb2e8f9f7 17 #define MBED_SERIAL_API_H
<> 144:ef7eb2e8f9f7 18
<> 144:ef7eb2e8f9f7 19 #include "device.h"
<> 144:ef7eb2e8f9f7 20 #include "buffer.h"
<> 144:ef7eb2e8f9f7 21 #include "dma_api.h"
<> 144:ef7eb2e8f9f7 22
<> 144:ef7eb2e8f9f7 23 #if DEVICE_SERIAL
<> 144:ef7eb2e8f9f7 24
<> 144:ef7eb2e8f9f7 25 #define SERIAL_EVENT_TX_SHIFT (2)
<> 144:ef7eb2e8f9f7 26 #define SERIAL_EVENT_RX_SHIFT (8)
<> 144:ef7eb2e8f9f7 27
<> 144:ef7eb2e8f9f7 28 #define SERIAL_EVENT_TX_MASK (0x00FC)
<> 144:ef7eb2e8f9f7 29 #define SERIAL_EVENT_RX_MASK (0x3F00)
<> 144:ef7eb2e8f9f7 30
<> 144:ef7eb2e8f9f7 31 #define SERIAL_EVENT_ERROR (1 << 1)
<> 144:ef7eb2e8f9f7 32
<> 144:ef7eb2e8f9f7 33 /**
<> 144:ef7eb2e8f9f7 34 * @defgroup SerialTXEvents Serial TX Events Macros
<> 144:ef7eb2e8f9f7 35 *
<> 144:ef7eb2e8f9f7 36 * @{
<> 144:ef7eb2e8f9f7 37 */
<> 144:ef7eb2e8f9f7 38 #define SERIAL_EVENT_TX_COMPLETE (1 << (SERIAL_EVENT_TX_SHIFT + 0))
<> 144:ef7eb2e8f9f7 39 #define SERIAL_EVENT_TX_ALL (SERIAL_EVENT_TX_COMPLETE)
<> 144:ef7eb2e8f9f7 40 /**@}*/
<> 144:ef7eb2e8f9f7 41
<> 144:ef7eb2e8f9f7 42 /**
<> 144:ef7eb2e8f9f7 43 * @defgroup SerialRXEvents Serial RX Events Macros
<> 144:ef7eb2e8f9f7 44 *
<> 144:ef7eb2e8f9f7 45 * @{
<> 144:ef7eb2e8f9f7 46 */
<> 144:ef7eb2e8f9f7 47 #define SERIAL_EVENT_RX_COMPLETE (1 << (SERIAL_EVENT_RX_SHIFT + 0))
<> 144:ef7eb2e8f9f7 48 #define SERIAL_EVENT_RX_OVERRUN_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 1))
<> 144:ef7eb2e8f9f7 49 #define SERIAL_EVENT_RX_FRAMING_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 2))
<> 144:ef7eb2e8f9f7 50 #define SERIAL_EVENT_RX_PARITY_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 3))
<> 144:ef7eb2e8f9f7 51 #define SERIAL_EVENT_RX_OVERFLOW (1 << (SERIAL_EVENT_RX_SHIFT + 4))
<> 144:ef7eb2e8f9f7 52 #define SERIAL_EVENT_RX_CHARACTER_MATCH (1 << (SERIAL_EVENT_RX_SHIFT + 5))
<> 144:ef7eb2e8f9f7 53 #define SERIAL_EVENT_RX_ALL (SERIAL_EVENT_RX_OVERFLOW | SERIAL_EVENT_RX_PARITY_ERROR | \
<> 144:ef7eb2e8f9f7 54 SERIAL_EVENT_RX_FRAMING_ERROR | SERIAL_EVENT_RX_OVERRUN_ERROR | \
<> 144:ef7eb2e8f9f7 55 SERIAL_EVENT_RX_COMPLETE | SERIAL_EVENT_RX_CHARACTER_MATCH)
<> 144:ef7eb2e8f9f7 56 /**@}*/
<> 144:ef7eb2e8f9f7 57
<> 144:ef7eb2e8f9f7 58 #define SERIAL_RESERVED_CHAR_MATCH (255)
<> 144:ef7eb2e8f9f7 59
<> 144:ef7eb2e8f9f7 60 typedef enum {
<> 144:ef7eb2e8f9f7 61 ParityNone = 0,
<> 144:ef7eb2e8f9f7 62 ParityOdd = 1,
<> 144:ef7eb2e8f9f7 63 ParityEven = 2,
<> 144:ef7eb2e8f9f7 64 ParityForced1 = 3,
<> 144:ef7eb2e8f9f7 65 ParityForced0 = 4
<> 144:ef7eb2e8f9f7 66 } SerialParity;
<> 144:ef7eb2e8f9f7 67
<> 144:ef7eb2e8f9f7 68 typedef enum {
<> 144:ef7eb2e8f9f7 69 RxIrq,
<> 144:ef7eb2e8f9f7 70 TxIrq
<> 144:ef7eb2e8f9f7 71 } SerialIrq;
<> 144:ef7eb2e8f9f7 72
<> 144:ef7eb2e8f9f7 73 typedef enum {
<> 144:ef7eb2e8f9f7 74 FlowControlNone,
<> 144:ef7eb2e8f9f7 75 FlowControlRTS,
<> 144:ef7eb2e8f9f7 76 FlowControlCTS,
<> 144:ef7eb2e8f9f7 77 FlowControlRTSCTS
<> 144:ef7eb2e8f9f7 78 } FlowControl;
<> 144:ef7eb2e8f9f7 79
<> 144:ef7eb2e8f9f7 80 typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event);
<> 144:ef7eb2e8f9f7 81
<> 144:ef7eb2e8f9f7 82 #if DEVICE_SERIAL_ASYNCH
<> 144:ef7eb2e8f9f7 83 /** Asynch serial HAL structure
<> 144:ef7eb2e8f9f7 84 */
<> 144:ef7eb2e8f9f7 85 typedef struct {
<> 144:ef7eb2e8f9f7 86 struct serial_s serial; /**< Target specific serial structure */
<> 144:ef7eb2e8f9f7 87 struct buffer_s tx_buff; /**< TX buffer */
<> 144:ef7eb2e8f9f7 88 struct buffer_s rx_buff; /**< RX buffer */
<> 144:ef7eb2e8f9f7 89 uint8_t char_match; /**< Character to be matched */
<> 144:ef7eb2e8f9f7 90 uint8_t char_found; /**< State of the matched character */
<> 144:ef7eb2e8f9f7 91 } serial_t;
<> 144:ef7eb2e8f9f7 92
<> 144:ef7eb2e8f9f7 93 #else
<> 144:ef7eb2e8f9f7 94 /** Non-asynch serial HAL structure
<> 144:ef7eb2e8f9f7 95 */
<> 144:ef7eb2e8f9f7 96 typedef struct serial_s serial_t;
<> 144:ef7eb2e8f9f7 97
<> 144:ef7eb2e8f9f7 98 #endif
<> 144:ef7eb2e8f9f7 99
<> 144:ef7eb2e8f9f7 100 #ifdef __cplusplus
<> 144:ef7eb2e8f9f7 101 extern "C" {
<> 144:ef7eb2e8f9f7 102 #endif
<> 144:ef7eb2e8f9f7 103
<> 144:ef7eb2e8f9f7 104 /**
<> 144:ef7eb2e8f9f7 105 * \defgroup hal_GeneralSerial Serial Configuration Functions
<> 144:ef7eb2e8f9f7 106 * @{
<> 144:ef7eb2e8f9f7 107 */
<> 144:ef7eb2e8f9f7 108
<> 144:ef7eb2e8f9f7 109 /** Initialize the serial peripheral. It sets the default parameters for serial
<> 144:ef7eb2e8f9f7 110 * peripheral, and configures its specifieds pins.
<> 144:ef7eb2e8f9f7 111 *
<> 144:ef7eb2e8f9f7 112 * @param obj The serial object
<> 144:ef7eb2e8f9f7 113 * @param tx The TX pin name
<> 144:ef7eb2e8f9f7 114 * @param rx The RX pin name
<> 144:ef7eb2e8f9f7 115 */
<> 144:ef7eb2e8f9f7 116 void serial_init(serial_t *obj, PinName tx, PinName rx);
<> 144:ef7eb2e8f9f7 117
<> 144:ef7eb2e8f9f7 118 /** Release the serial peripheral, not currently invoked. It requires further
<> 144:ef7eb2e8f9f7 119 * resource management.
<> 144:ef7eb2e8f9f7 120 *
<> 144:ef7eb2e8f9f7 121 * @param obj The serial object
<> 144:ef7eb2e8f9f7 122 */
<> 144:ef7eb2e8f9f7 123 void serial_free(serial_t *obj);
<> 144:ef7eb2e8f9f7 124
<> 144:ef7eb2e8f9f7 125 /** Configure the baud rate
<> 144:ef7eb2e8f9f7 126 *
<> 144:ef7eb2e8f9f7 127 * @param obj The serial object
<> 144:ef7eb2e8f9f7 128 * @param baudrate The baud rate to be configured
<> 144:ef7eb2e8f9f7 129 */
<> 144:ef7eb2e8f9f7 130 void serial_baud(serial_t *obj, int baudrate);
<> 144:ef7eb2e8f9f7 131
<> 144:ef7eb2e8f9f7 132 /** Configure the format. Set the number of bits, parity and the number of stop bits
<> 144:ef7eb2e8f9f7 133 *
<> 144:ef7eb2e8f9f7 134 * @param obj The serial object
<> 144:ef7eb2e8f9f7 135 * @param data_bits The number of data bits
<> 144:ef7eb2e8f9f7 136 * @param parity The parity
<> 144:ef7eb2e8f9f7 137 * @param stop_bits The number of stop bits
<> 144:ef7eb2e8f9f7 138 */
<> 144:ef7eb2e8f9f7 139 void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
<> 144:ef7eb2e8f9f7 140
<> 144:ef7eb2e8f9f7 141 /** The serial interrupt handler registration
<> 144:ef7eb2e8f9f7 142 *
<> 144:ef7eb2e8f9f7 143 * @param obj The serial object
<> 144:ef7eb2e8f9f7 144 * @param handler The interrupt handler which will be invoked when the interrupt fires
<> 144:ef7eb2e8f9f7 145 * @param id The SerialBase object
<> 144:ef7eb2e8f9f7 146 */
<> 144:ef7eb2e8f9f7 147 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);
<> 144:ef7eb2e8f9f7 148
<> 144:ef7eb2e8f9f7 149 /** Configure serial interrupt. This function is used for word-approach
<> 144:ef7eb2e8f9f7 150 *
<> 144:ef7eb2e8f9f7 151 * @param obj The serial object
<> 144:ef7eb2e8f9f7 152 * @param irq The serial IRQ type (RX or TX)
<> 144:ef7eb2e8f9f7 153 * @param enable Set to non-zero to enable events, or zero to disable them
<> 144:ef7eb2e8f9f7 154 */
<> 144:ef7eb2e8f9f7 155 void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable);
<> 144:ef7eb2e8f9f7 156
<> 144:ef7eb2e8f9f7 157 /** Get character. This is a blocking call, waiting for a character
<> 144:ef7eb2e8f9f7 158 *
<> 144:ef7eb2e8f9f7 159 * @param obj The serial object
<> 144:ef7eb2e8f9f7 160 */
<> 144:ef7eb2e8f9f7 161 int serial_getc(serial_t *obj);
<> 144:ef7eb2e8f9f7 162
<> 144:ef7eb2e8f9f7 163 /** Send a character. This is a blocking call, waiting for a peripheral to be available
<> 144:ef7eb2e8f9f7 164 * for writing
<> 144:ef7eb2e8f9f7 165 *
<> 144:ef7eb2e8f9f7 166 * @param obj The serial object
<> 144:ef7eb2e8f9f7 167 * @param c The character to be sent
<> 144:ef7eb2e8f9f7 168 */
<> 144:ef7eb2e8f9f7 169 void serial_putc(serial_t *obj, int c);
<> 144:ef7eb2e8f9f7 170
<> 144:ef7eb2e8f9f7 171 /** Check if the serial peripheral is readable
<> 144:ef7eb2e8f9f7 172 *
<> 144:ef7eb2e8f9f7 173 * @param obj The serial object
<> 144:ef7eb2e8f9f7 174 * @return Non-zero value if a character can be read, 0 if nothing to read
<> 144:ef7eb2e8f9f7 175 */
<> 144:ef7eb2e8f9f7 176 int serial_readable(serial_t *obj);
<> 144:ef7eb2e8f9f7 177
<> 144:ef7eb2e8f9f7 178 /** Check if the serial peripheral is writable
<> 144:ef7eb2e8f9f7 179 *
<> 144:ef7eb2e8f9f7 180 * @param obj The serial object
<> 144:ef7eb2e8f9f7 181 * @return Non-zero value if a character can be written, 0 otherwise.
<> 144:ef7eb2e8f9f7 182 */
<> 144:ef7eb2e8f9f7 183 int serial_writable(serial_t *obj);
<> 144:ef7eb2e8f9f7 184
<> 144:ef7eb2e8f9f7 185 /** Clear the serial peripheral
<> 144:ef7eb2e8f9f7 186 *
<> 144:ef7eb2e8f9f7 187 * @param obj The serial object
<> 144:ef7eb2e8f9f7 188 */
<> 144:ef7eb2e8f9f7 189 void serial_clear(serial_t *obj);
<> 144:ef7eb2e8f9f7 190
<> 144:ef7eb2e8f9f7 191 /** Set the break
<> 144:ef7eb2e8f9f7 192 *
<> 144:ef7eb2e8f9f7 193 * @param obj The serial object
<> 144:ef7eb2e8f9f7 194 */
<> 144:ef7eb2e8f9f7 195 void serial_break_set(serial_t *obj);
<> 144:ef7eb2e8f9f7 196
<> 144:ef7eb2e8f9f7 197 /** Clear the break
<> 144:ef7eb2e8f9f7 198 *
<> 144:ef7eb2e8f9f7 199 * @param obj The serial object
<> 144:ef7eb2e8f9f7 200 */
<> 144:ef7eb2e8f9f7 201 void serial_break_clear(serial_t *obj);
<> 144:ef7eb2e8f9f7 202
<> 144:ef7eb2e8f9f7 203 /** Configure the TX pin for UART function.
<> 144:ef7eb2e8f9f7 204 *
<> 144:ef7eb2e8f9f7 205 * @param tx The pin name used for TX
<> 144:ef7eb2e8f9f7 206 */
<> 144:ef7eb2e8f9f7 207 void serial_pinout_tx(PinName tx);
<> 144:ef7eb2e8f9f7 208
<> 144:ef7eb2e8f9f7 209 /** Configure the serial for the flow control. It sets flow control in the hardware
<> 144:ef7eb2e8f9f7 210 * if a serial peripheral supports it, otherwise software emulation is used.
<> 144:ef7eb2e8f9f7 211 *
<> 144:ef7eb2e8f9f7 212 * @param obj The serial object
<> 144:ef7eb2e8f9f7 213 * @param type The type of the flow control. Look at the available FlowControl types.
<> 144:ef7eb2e8f9f7 214 * @param rxflow The TX pin name
<> 144:ef7eb2e8f9f7 215 * @param txflow The RX pin name
<> 144:ef7eb2e8f9f7 216 */
<> 144:ef7eb2e8f9f7 217 void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow);
<> 144:ef7eb2e8f9f7 218
<> 144:ef7eb2e8f9f7 219 #if DEVICE_SERIAL_ASYNCH
<> 144:ef7eb2e8f9f7 220
<> 144:ef7eb2e8f9f7 221 /**@}*/
<> 144:ef7eb2e8f9f7 222
<> 144:ef7eb2e8f9f7 223 /**
<> 144:ef7eb2e8f9f7 224 * \defgroup hal_AsynchSerial Asynchronous Serial Hardware Abstraction Layer
<> 144:ef7eb2e8f9f7 225 * @{
<> 144:ef7eb2e8f9f7 226 */
<> 144:ef7eb2e8f9f7 227
<> 144:ef7eb2e8f9f7 228 /** Begin asynchronous TX transfer. The used buffer is specified in the serial object,
<> 144:ef7eb2e8f9f7 229 * tx_buff
<> 144:ef7eb2e8f9f7 230 *
<> 144:ef7eb2e8f9f7 231 * @param obj The serial object
<> 144:ef7eb2e8f9f7 232 * @param tx The transmit buffer
<> 144:ef7eb2e8f9f7 233 * @param tx_length The number of bytes to transmit
<> 144:ef7eb2e8f9f7 234 * @param tx_width Deprecated argument
<> 144:ef7eb2e8f9f7 235 * @param handler The serial handler
<> 144:ef7eb2e8f9f7 236 * @param event The logical OR of events to be registered
<> 144:ef7eb2e8f9f7 237 * @param hint A suggestion for how to use DMA with this transfer
<> 144:ef7eb2e8f9f7 238 * @return Returns number of data transfered, otherwise returns 0
<> 144:ef7eb2e8f9f7 239 */
<> 144:ef7eb2e8f9f7 240 int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint);
<> 144:ef7eb2e8f9f7 241
<> 144:ef7eb2e8f9f7 242 /** Begin asynchronous RX transfer (enable interrupt for data collecting)
<> 144:ef7eb2e8f9f7 243 * The used buffer is specified in the serial object - rx_buff
<> 144:ef7eb2e8f9f7 244 *
<> 144:ef7eb2e8f9f7 245 * @param obj The serial object
<> 144:ef7eb2e8f9f7 246 * @param rx The receive buffer
<> 144:ef7eb2e8f9f7 247 * @param rx_length The number of bytes to receive
<> 144:ef7eb2e8f9f7 248 * @param rx_width Deprecated argument
<> 144:ef7eb2e8f9f7 249 * @param handler The serial handler
<> 144:ef7eb2e8f9f7 250 * @param event The logical OR of events to be registered
<> 144:ef7eb2e8f9f7 251 * @param handler The serial handler
<> 144:ef7eb2e8f9f7 252 * @param char_match A character in range 0-254 to be matched
<> 144:ef7eb2e8f9f7 253 * @param hint A suggestion for how to use DMA with this transfer
<> 144:ef7eb2e8f9f7 254 */
<> 144:ef7eb2e8f9f7 255 void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint);
<> 144:ef7eb2e8f9f7 256
<> 144:ef7eb2e8f9f7 257 /** Attempts to determine if the serial peripheral is already in use for TX
<> 144:ef7eb2e8f9f7 258 *
<> 144:ef7eb2e8f9f7 259 * @param obj The serial object
<> 144:ef7eb2e8f9f7 260 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
<> 144:ef7eb2e8f9f7 261 */
<> 144:ef7eb2e8f9f7 262 uint8_t serial_tx_active(serial_t *obj);
<> 144:ef7eb2e8f9f7 263
<> 144:ef7eb2e8f9f7 264 /** Attempts to determine if the serial peripheral is already in use for RX
<> 144:ef7eb2e8f9f7 265 *
<> 144:ef7eb2e8f9f7 266 * @param obj The serial object
<> 144:ef7eb2e8f9f7 267 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
<> 144:ef7eb2e8f9f7 268 */
<> 144:ef7eb2e8f9f7 269 uint8_t serial_rx_active(serial_t *obj);
<> 144:ef7eb2e8f9f7 270
<> 144:ef7eb2e8f9f7 271 /** The asynchronous TX and RX handler.
<> 144:ef7eb2e8f9f7 272 *
<> 144:ef7eb2e8f9f7 273 * @param obj The serial object
<> 144:ef7eb2e8f9f7 274 * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0
<> 144:ef7eb2e8f9f7 275 */
<> 144:ef7eb2e8f9f7 276 int serial_irq_handler_asynch(serial_t *obj);
<> 144:ef7eb2e8f9f7 277
<> 144:ef7eb2e8f9f7 278 /** Abort the ongoing TX transaction. It disables the enabled interupt for TX and
<> 144:ef7eb2e8f9f7 279 * flushes the TX hardware buffer if TX FIFO is used
<> 144:ef7eb2e8f9f7 280 *
<> 144:ef7eb2e8f9f7 281 * @param obj The serial object
<> 144:ef7eb2e8f9f7 282 */
<> 144:ef7eb2e8f9f7 283 void serial_tx_abort_asynch(serial_t *obj);
<> 144:ef7eb2e8f9f7 284
<> 144:ef7eb2e8f9f7 285 /** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and
<> 144:ef7eb2e8f9f7 286 * flushes the RX hardware buffer if RX FIFO is used
<> 144:ef7eb2e8f9f7 287 *
<> 144:ef7eb2e8f9f7 288 * @param obj The serial object
<> 144:ef7eb2e8f9f7 289 */
<> 144:ef7eb2e8f9f7 290 void serial_rx_abort_asynch(serial_t *obj);
<> 144:ef7eb2e8f9f7 291
<> 144:ef7eb2e8f9f7 292 /**@}*/
<> 144:ef7eb2e8f9f7 293
<> 144:ef7eb2e8f9f7 294 #endif
<> 144:ef7eb2e8f9f7 295
<> 144:ef7eb2e8f9f7 296 #ifdef __cplusplus
<> 144:ef7eb2e8f9f7 297 }
<> 144:ef7eb2e8f9f7 298 #endif
<> 144:ef7eb2e8f9f7 299
<> 144:ef7eb2e8f9f7 300 #endif
<> 144:ef7eb2e8f9f7 301
<> 144:ef7eb2e8f9f7 302 #endif