mbed library for slider v2

Dependents:   kl46z_slider_v2

Committer:
mturner5
Date:
Wed Sep 14 07:04:27 2016 +0000
Revision:
0:b7116bd48af6
Tried to use the timer.

Who changed what in which revision?

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