5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

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