mbed library sources. Supersedes mbed-src. removed serial

Fork of mbed-dev by mbed official

Committer:
mrcrsch
Date:
Mon Feb 13 14:26:36 2017 +0000
Revision:
158:aa577577efe0
Parent:
149:156823d33999
removed stdio and serial to reduce size

Who changed what in which revision?

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