RTEMS 6.1-rc1
fsl_flexio_uart.h
1/*
2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_FLEXIO_UART_H_
10#define _FSL_FLEXIO_UART_H_
11
12#include "fsl_common.h"
13#include "fsl_flexio.h"
14
20/*******************************************************************************
21 * Definitions
22 ******************************************************************************/
23
27#define FSL_FLEXIO_UART_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
31#ifndef UART_RETRY_TIMES
32#define UART_RETRY_TIMES 0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */
33#endif
34
36enum
37{
49};
50
53{
58
61{
64};
65
68{
72};
73
75typedef struct _flexio_uart_type
76{
78 uint8_t TxPinIndex;
79 uint8_t RxPinIndex;
80 uint8_t shifterIndex[2];
81 uint8_t timerIndex[2];
83
85typedef struct _flexio_uart_config
86{
93 uint32_t baudRate_Bps;
96
99{
100 /*
101 * Use separate TX and RX data pointer, because TX data is const data.
102 * The member data is kept for backward compatibility.
103 */
104 union
105 {
106 uint8_t *data;
107 uint8_t *rxData;
108 const uint8_t *txData;
109 };
110 size_t dataSize;
112
113/* Forward declaration of the handle typedef. */
115
118 flexio_uart_handle_t *handle,
119 status_t status,
120 void *userData);
121
124{
125 const uint8_t *volatile txData;
126 volatile size_t txDataSize;
127 uint8_t *volatile rxData;
128 volatile size_t rxDataSize;
132 uint8_t *rxRingBuffer;
134 volatile uint16_t rxRingBufferHead;
135 volatile uint16_t rxRingBufferTail;
138 void *userData;
140 volatile uint8_t txState;
141 volatile uint8_t rxState;
142};
143
144/*******************************************************************************
145 * API
146 ******************************************************************************/
147
148#if defined(__cplusplus)
149extern "C" {
150#endif /*_cplusplus*/
151
188status_t FLEXIO_UART_Init(FLEXIO_UART_Type *base, const flexio_uart_config_t *userConfig, uint32_t srcClock_Hz);
189
198
210
211/* @} */
212
226
238void FLEXIO_UART_ClearStatusFlags(FLEXIO_UART_Type *base, uint32_t mask);
239
240/* @} */
241
255void FLEXIO_UART_EnableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
256
265void FLEXIO_UART_DisableInterrupts(FLEXIO_UART_Type *base, uint32_t mask);
266
267/* @} */
268
282static inline uint32_t FLEXIO_UART_GetTxDataRegisterAddress(FLEXIO_UART_Type *base)
283{
284 return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, base->shifterIndex[0]);
285}
286
295static inline uint32_t FLEXIO_UART_GetRxDataRegisterAddress(FLEXIO_UART_Type *base)
296{
297 return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBufferByteSwapped, base->shifterIndex[1]);
298}
299
308static inline void FLEXIO_UART_EnableTxDMA(FLEXIO_UART_Type *base, bool enable)
309{
310 FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[0], enable);
311}
312
321static inline void FLEXIO_UART_EnableRxDMA(FLEXIO_UART_Type *base, bool enable)
322{
323 FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterIndex[1], enable);
324}
325
326/* @} */
327
339static inline void FLEXIO_UART_Enable(FLEXIO_UART_Type *base, bool enable)
340{
341 if (enable)
342 {
343 base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
344 }
345}
346
357static inline void FLEXIO_UART_WriteByte(FLEXIO_UART_Type *base, const uint8_t *buffer)
358{
359 base->flexioBase->SHIFTBUF[base->shifterIndex[0]] = *buffer;
360}
361
371static inline void FLEXIO_UART_ReadByte(FLEXIO_UART_Type *base, uint8_t *buffer)
372{
373 *buffer = (uint8_t)(base->flexioBase->SHIFTBUFBYS[base->shifterIndex[1]]);
374}
375
387status_t FLEXIO_UART_WriteBlocking(FLEXIO_UART_Type *base, const uint8_t *txData, size_t txSize);
388
400status_t FLEXIO_UART_ReadBlocking(FLEXIO_UART_Type *base, uint8_t *rxData, size_t rxSize);
401
402/* @} */
403
430 flexio_uart_handle_t *handle,
432 void *userData);
433
452 flexio_uart_handle_t *handle,
453 uint8_t *ringBuffer,
454 size_t ringBufferSize);
455
465
484 flexio_uart_handle_t *handle,
486
497
510
537 flexio_uart_handle_t *handle,
539 size_t *receivedBytes);
540
550
563
572void FLEXIO_UART_TransferHandleIRQ(void *uartType, void *uartHandle);
573
576#if defined(__cplusplus)
577}
578#endif /*_cplusplus*/
581#endif /*_FSL_FLEXIO_UART_H_*/
uint32_t FLEXIO_GetShifterBufferAddress(FLEXIO_Type *base, flexio_shifter_buffer_type_t type, uint8_t index)
Gets the shifter buffer address for the DMA transfer usage.
Definition: fsl_flexio.c:173
@ kFLEXIO_ShifterBuffer
Definition: fsl_flexio.h:223
@ kFLEXIO_ShifterBufferByteSwapped
Definition: fsl_flexio.h:225
bool enableFastAccess
Definition: fsl_flexio_uart.h:90
void FLEXIO_UART_TransferAbortSend(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
Aborts the interrupt-driven data transmit.
Definition: fsl_flexio_uart.c:649
const uint8_t * txData
Definition: fsl_flexio_uart.h:108
void FLEXIO_UART_TransferStartRingBuffer(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
Sets up the RX ring buffer.
Definition: fsl_flexio_uart.c:547
void * userData
Definition: fsl_flexio_uart.h:138
void FLEXIO_UART_ClearStatusFlags(FLEXIO_UART_Type *base, uint32_t mask)
Gets the FlexIO UART status flags.
Definition: fsl_flexio_uart.c:379
volatile uint16_t rxRingBufferHead
Definition: fsl_flexio_uart.h:134
void(* flexio_uart_transfer_callback_t)(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)
FlexIO UART transfer callback function.
Definition: fsl_flexio_uart.h:117
void FLEXIO_UART_TransferAbortReceive(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
Aborts the receive data which was using IRQ.
Definition: fsl_flexio_uart.c:834
const uint8_t *volatile txData
Definition: fsl_flexio_uart.h:125
volatile uint8_t rxState
Definition: fsl_flexio_uart.h:141
status_t FLEXIO_UART_TransferGetReceiveCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count)
Gets the number of bytes received.
Definition: fsl_flexio_uart.c:858
void FLEXIO_UART_TransferHandleIRQ(void *uartType, void *uartHandle)
FlexIO UART IRQ handler function.
Definition: fsl_flexio_uart.c:881
size_t rxDataSizeAll
Definition: fsl_flexio_uart.h:130
status_t FLEXIO_UART_TransferGetSendCount(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count)
Gets the number of bytes sent.
Definition: fsl_flexio_uart.c:669
struct _flexio_uart_type FLEXIO_UART_Type
Define FlexIO UART access structure typedef.
volatile uint16_t rxRingBufferTail
Definition: fsl_flexio_uart.h:135
void FLEXIO_UART_Deinit(FLEXIO_UART_Type *base)
Resets the FlexIO UART shifter and timer config.
Definition: fsl_flexio_uart.c:260
uint32_t baudRate_Bps
Definition: fsl_flexio_uart.h:93
flexio_uart_bit_count_per_char_t bitCountPerChar
Definition: fsl_flexio_uart.h:94
uint8_t shifterIndex[2]
Definition: fsl_flexio_uart.h:80
struct _flexio_uart_transfer flexio_uart_transfer_t
Define FlexIO UART transfer structure.
uint8_t * rxData
Definition: fsl_flexio_uart.h:107
size_t rxRingBufferSize
Definition: fsl_flexio_uart.h:133
void FLEXIO_UART_EnableInterrupts(FLEXIO_UART_Type *base, uint32_t mask)
Enables the FlexIO UART interrupt.
Definition: fsl_flexio_uart.c:315
uint8_t RxPinIndex
Definition: fsl_flexio_uart.h:79
status_t FLEXIO_UART_ReadBlocking(FLEXIO_UART_Type *base, uint8_t *rxData, size_t rxSize)
Receives a buffer of bytes.
Definition: fsl_flexio_uart.c:449
status_t FLEXIO_UART_Init(FLEXIO_UART_Type *base, const flexio_uart_config_t *userConfig, uint32_t srcClock_Hz)
Ungates the FlexIO clock, resets the FlexIO module, configures FlexIO UART hardware,...
Definition: fsl_flexio_uart.c:124
size_t txDataSizeAll
Definition: fsl_flexio_uart.h:129
enum _flexio_uart_bit_count_per_char flexio_uart_bit_count_per_char_t
FlexIO UART bit count per char.
volatile size_t txDataSize
Definition: fsl_flexio_uart.h:126
flexio_uart_transfer_callback_t callback
Definition: fsl_flexio_uart.h:137
uint8_t * data
Definition: fsl_flexio_uart.h:106
size_t dataSize
Definition: fsl_flexio_uart.h:110
bool enableInDebug
Definition: fsl_flexio_uart.h:89
uint8_t TxPinIndex
Definition: fsl_flexio_uart.h:78
status_t FLEXIO_UART_WriteBlocking(FLEXIO_UART_Type *base, const uint8_t *txData, size_t txSize)
Sends a buffer of data bytes.
Definition: fsl_flexio_uart.c:406
void FLEXIO_UART_TransferStopRingBuffer(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
Aborts the background transfer and uninstalls the ring buffer.
Definition: fsl_flexio_uart.c:575
_flexio_uart_interrupt_enable
Define FlexIO UART interrupt mask.
Definition: fsl_flexio_uart.h:61
uint8_t *volatile rxData
Definition: fsl_flexio_uart.h:127
status_t FLEXIO_UART_TransferSendNonBlocking(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_t *xfer)
Transmits a buffer of data using the interrupt method.
Definition: fsl_flexio_uart.c:607
status_t FLEXIO_UART_TransferReceiveNonBlocking(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_t *xfer, size_t *receivedBytes)
Receives a buffer of data using the interrupt method.
Definition: fsl_flexio_uart.c:709
void FLEXIO_UART_GetDefaultConfig(flexio_uart_config_t *userConfig)
Gets the default configuration to configure the FlexIO UART. The configuration can be used directly f...
Definition: fsl_flexio_uart.c:290
_flexio_uart_status_flags
Define FlexIO UART status mask.
Definition: fsl_flexio_uart.h:68
_flexio_uart_bit_count_per_char
FlexIO UART bit count per char.
Definition: fsl_flexio_uart.h:53
uint8_t * rxRingBuffer
Definition: fsl_flexio_uart.h:132
bool enableInDoze
Definition: fsl_flexio_uart.h:88
status_t FLEXIO_UART_TransferCreateHandle(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_callback_t callback, void *userData)
Initializes the UART handle.
Definition: fsl_flexio_uart.c:501
struct _flexio_uart_config flexio_uart_config_t
Define FlexIO UART user configuration structure.
FLEXIO_Type * flexioBase
Definition: fsl_flexio_uart.h:77
volatile size_t rxDataSize
Definition: fsl_flexio_uart.h:128
bool enableUart
Definition: fsl_flexio_uart.h:87
uint32_t FLEXIO_UART_GetStatusFlags(FLEXIO_UART_Type *base)
Gets the FlexIO UART status flags.
Definition: fsl_flexio_uart.c:354
void FLEXIO_UART_DisableInterrupts(FLEXIO_UART_Type *base, uint32_t mask)
Disables the FlexIO UART interrupt.
Definition: fsl_flexio_uart.c:335
uint8_t timerIndex[2]
Definition: fsl_flexio_uart.h:81
volatile uint8_t txState
Definition: fsl_flexio_uart.h:140
@ kFLEXIO_UART_TxDataRegEmptyInterruptEnable
Definition: fsl_flexio_uart.h:62
@ kFLEXIO_UART_RxDataRegFullInterruptEnable
Definition: fsl_flexio_uart.h:63
@ kFLEXIO_UART_RxOverRunFlag
Definition: fsl_flexio_uart.h:71
@ kFLEXIO_UART_RxDataRegFullFlag
Definition: fsl_flexio_uart.h:70
@ kFLEXIO_UART_TxDataRegEmptyFlag
Definition: fsl_flexio_uart.h:69
@ kFLEXIO_UART_9BitsPerChar
Definition: fsl_flexio_uart.h:56
@ kFLEXIO_UART_8BitsPerChar
Definition: fsl_flexio_uart.h:55
@ kFLEXIO_UART_7BitsPerChar
Definition: fsl_flexio_uart.h:54
@ kStatus_FLEXIO_UART_BaudrateNotSupport
Definition: fsl_flexio_uart.h:47
@ kStatus_FLEXIO_UART_ERROR
Definition: fsl_flexio_uart.h:42
@ kStatus_FLEXIO_UART_RxIdle
Definition: fsl_flexio_uart.h:41
@ kStatus_FLEXIO_UART_RxRingBufferOverrun
Definition: fsl_flexio_uart.h:43
@ kStatus_FLEXIO_UART_Timeout
Definition: fsl_flexio_uart.h:46
@ kStatus_FLEXIO_UART_TxBusy
Definition: fsl_flexio_uart.h:38
@ kStatus_FLEXIO_UART_TxIdle
Definition: fsl_flexio_uart.h:40
@ kStatus_FLEXIO_UART_RxBusy
Definition: fsl_flexio_uart.h:39
@ kStatus_FLEXIO_UART_RxHardwareOverrun
Definition: fsl_flexio_uart.h:45
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_FLEXIO_UART
Definition: fsl_common.h:90
Definition: MIMXRT1052.h:20511
Define FlexIO UART user configuration structure.
Definition: fsl_flexio_uart.h:86
Define FLEXIO UART handle structure.
Definition: fsl_flexio_uart.h:124
Define FlexIO UART transfer structure.
Definition: fsl_flexio_uart.h:99
Define FlexIO UART access structure typedef.
Definition: fsl_flexio_uart.h:76