temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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