mbed.h library with any bug fixes AV finds.

Dependents:   micromouse4_encoder_testing PID_Test Lab1_Test WorkingPID ... more

Committer:
aravindsv
Date:
Mon Nov 02 02:26:59 2015 +0000
Revision:
0:ba7650f404af
Reduced HSE_STARTUP_TIMEOUT to 500 ms, fixed some compiler warnings

Who changed what in which revision?

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