Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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