flexio_uart_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #ifndef FLEXIO_UART_DRIVER_H
20 #define FLEXIO_UART_DRIVER_H
21 
22 #include <stddef.h>
23 #include <stdbool.h>
24 #include "device_registers.h"
25 #include "flexio.h"
26 #include "edma_driver.h"
27 #include "callbacks.h"
28 
34 /*******************************************************************************
35  * Enumerations.
36  ******************************************************************************/
37 
38 
45 typedef enum
46 {
50 
51 
52 /*******************************************************************************
53 * Definitions
54 ******************************************************************************/
55 
56 
63 typedef struct
64 {
66  uint32_t baudRate;
67  uint8_t bitCount;
69  uint8_t dataPin;
74  void *callbackParam;
75  uint8_t dmaChannel;
77 
78 
87 typedef struct
88 {
90  flexio_common_state_t flexioCommon; /* Common flexio drivers structure */
91  uint8_t *data; /* Transmit/Receive buffer. */
92  uint32_t remainingBytes; /* Number of remaining bytes to be transferred. */
93  uint8_t dmaChannel; /* DMA channel number */
94  uart_callback_t callback; /* User callback function */
95  void *callbackParam; /* Parameter for the callback function */
96  flexio_uart_driver_direction_t direction; /* Driver direction: Tx or Rx */
97  flexio_driver_type_t driverType; /* Driver type: interrupts/polling/DMA */
98  status_t status; /* Current status of the driver */
99  bool driverIdle; /* Idle/busy state of the receiver */
100  semaphore_t idleSemaphore; /* Semaphore used by blocking functions */
101  bool blocking; /* Specifies if the current transfer is blocking */
102  uint8_t bitCount; /* Number of bits per word */
103  uint8_t txFlush; /* Used for flushing Tx buffer before ending a transmission */
106 
107 
108 /*******************************************************************************
109  * API
110  ******************************************************************************/
116 #if defined(__cplusplus)
117 extern "C" {
118 #endif
119 
120 
137 status_t FLEXIO_UART_DRV_Init(uint32_t instance,
138  const flexio_uart_user_config_t * userConfigPtr,
139  flexio_uart_state_t * state);
140 
152 
153 
171  uint32_t baudRate,
172  uint8_t bitCount);
173 
174 
184 status_t FLEXIO_UART_DRV_GetBaudRate(flexio_uart_state_t *state, uint32_t *baudRate);
185 
186 
200  const uint8_t * txBuff,
201  uint32_t txSize,
202  uint32_t timeout);
203 
218  const uint8_t * txBuff,
219  uint32_t txSize);
220 
221 
235  uint8_t * rxBuff,
236  uint32_t rxSize,
237  uint32_t timeout);
238 
253  uint8_t * rxBuff,
254  uint32_t rxSize);
255 
256 
257 
277  uint32_t *bytesRemaining);
278 
279 
280 
290 
291 
305  uint8_t * rxBuff,
306  uint32_t rxSize);
307 
308 
322  const uint8_t * txBuff,
323  uint32_t txSize);
324 
325 
327 #if defined(__cplusplus)
328 }
329 #endif
330 
333 #endif /* FLEXIO_UART_DRIVER_H */
334 /*******************************************************************************
335  * EOF
336  ******************************************************************************/
status_t FLEXIO_UART_DRV_ReceiveData(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
Perform a non-blocking UART reception.
status_t FLEXIO_UART_DRV_SetTxBuffer(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
Provide a buffer for transmitting data.
status_t FLEXIO_UART_DRV_SetConfig(flexio_uart_state_t *state, uint32_t baudRate, uint8_t bitCount)
Set the baud rate and bit width for any subsequent UART communication.
status_t FLEXIO_UART_DRV_SendData(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
Perform a non-blocking UART transmission.
status_t FLEXIO_UART_DRV_SendDataBlocking(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Perform a blocking UART transmission.
flexio_uart_driver_direction_t direction
status_t FLEXIO_UART_DRV_ReceiveDataBlocking(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Perform a blocking UART reception.
status_t FLEXIO_UART_DRV_GetBaudRate(flexio_uart_state_t *state, uint32_t *baudRate)
Get the currently configured baud rate.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
status_t FLEXIO_UART_DRV_GetStatus(flexio_uart_state_t *state, uint32_t *bytesRemaining)
Get the status of the current non-blocking UART transfer.
status_t FLEXIO_UART_DRV_SetRxBuffer(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
Provide a buffer for receiving data.
Driver internal context structure.
status_t FLEXIO_UART_DRV_Deinit(flexio_uart_state_t *state)
De-initialize the FLEXIO_UART driver.
status_t FLEXIO_UART_DRV_TransferAbort(flexio_uart_state_t *state)
Aborts a non-blocking UART transfer.
flexio_driver_type_t
Driver type: interrupts/polling/DMA Implements : flexio_driver_type_t_Class.
Definition: flexio.h:49
void(* uart_callback_t)(void *driverState, uart_event_t event, void *userData)
Callback for all peripherals which support UART features.
Definition: callbacks.h:103
flexio_driver_type_t driverType
Driver configuration structure.
status_t FLEXIO_UART_DRV_Init(uint32_t instance, const flexio_uart_user_config_t *userConfigPtr, flexio_uart_state_t *state)
Initialize the FLEXIO_UART driver.
flexio_uart_driver_direction_t
flexio_uart driver direction (tx or rx)