RTEMS 6.1-rc1
fsl_flexio_i2s.h
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8#ifndef _FSL_FLEXIO_I2S_H_
9#define _FSL_FLEXIO_I2S_H_
10
11#include "fsl_common.h"
12#include "fsl_flexio.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
26#define FSL_FLEXIO_I2S_DRIVER_VERSION (MAKE_VERSION(2, 2, 0))
30#ifndef I2S_RETRY_TIMES
31#define I2S_RETRY_TIMES 0U /* Define to zero means keep waiting until the flag is assert/deassert. */
32#endif
33
35enum
36{
44};
45
47typedef struct _flexio_i2s_type
48{
50 uint8_t txPinIndex;
51 uint8_t rxPinIndex;
52 uint8_t bclkPinIndex;
53 uint8_t fsPinIndex;
57 uint8_t fsTimerIndex;
59
62{
64 kFLEXIO_I2S_Slave = 0x1U
66
68enum
69{
72};
73
75enum
76{
79};
80
82typedef struct _flexio_i2s_config
83{
84 bool enableI2S;
93
95typedef struct _flexio_i2s_format
96{
97 uint8_t bitWidth;
98 uint32_t sampleRate_Hz;
100
102#define FLEXIO_I2S_XFER_QUEUE_SIZE (4U)
103
106{
118
121{
127
130{
131 uint8_t *data;
132 size_t dataSize;
134
136
139 flexio_i2s_handle_t *handle,
140 status_t status,
141 void *userData);
142
145{
146 uint32_t state;
148 void *userData;
149 uint8_t bitWidth;
152 volatile uint8_t queueUser;
153 volatile uint8_t queueDriver;
154};
155
156/*******************************************************************************
157 * API
158 ******************************************************************************/
159
160#if defined(__cplusplus)
161extern "C" {
162#endif /*_cplusplus*/
163
184
195
205
212static inline void FLEXIO_I2S_Enable(FLEXIO_I2S_Type *base, bool enable)
213{
214 if (enable)
215 {
216 base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
217 }
218}
219
234
250void FLEXIO_I2S_EnableInterrupts(FLEXIO_I2S_Type *base, uint32_t mask);
251
260void FLEXIO_I2S_DisableInterrupts(FLEXIO_I2S_Type *base, uint32_t mask);
261
275static inline void FLEXIO_I2S_TxEnableDMA(FLEXIO_I2S_Type *base, bool enable)
276{
277 FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->txShifterIndex, enable);
278}
279
286static inline void FLEXIO_I2S_RxEnableDMA(FLEXIO_I2S_Type *base, bool enable)
287{
288 FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->rxShifterIndex, enable);
289}
290
299static inline uint32_t FLEXIO_I2S_TxGetDataRegisterAddress(FLEXIO_I2S_Type *base)
300{
301 return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBufferBitSwapped, base->txShifterIndex);
302}
303
312static inline uint32_t FLEXIO_I2S_RxGetDataRegisterAddress(FLEXIO_I2S_Type *base)
313{
314 return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBufferBitSwapped, base->rxShifterIndex);
315}
316
334void FLEXIO_I2S_MasterSetFormat(FLEXIO_I2S_Type *base, flexio_i2s_format_t *format, uint32_t srcClock_Hz);
335
346
359status_t FLEXIO_I2S_WriteBlocking(FLEXIO_I2S_Type *base, uint8_t bitWidth, uint8_t *txData, size_t size);
360
368static inline void FLEXIO_I2S_WriteData(FLEXIO_I2S_Type *base, uint8_t bitWidth, uint32_t data)
369{
370 base->flexioBase->SHIFTBUFBIS[base->txShifterIndex] = (data << (32U - bitWidth));
371}
372
385status_t FLEXIO_I2S_ReadBlocking(FLEXIO_I2S_Type *base, uint8_t bitWidth, uint8_t *rxData, size_t size);
386
393static inline uint32_t FLEXIO_I2S_ReadData(FLEXIO_I2S_Type *base)
394{
395 return base->flexioBase->SHIFTBUFBIS[base->rxShifterIndex];
396}
397
418 flexio_i2s_handle_t *handle,
419 flexio_i2s_callback_t callback,
420 void *userData);
421
434 flexio_i2s_handle_t *handle,
436 uint32_t srcClock_Hz);
437
451 flexio_i2s_handle_t *handle,
452 flexio_i2s_callback_t callback,
453 void *userData);
454
470 flexio_i2s_handle_t *handle,
472
488 flexio_i2s_handle_t *handle,
490
501
512
523
535
542void FLEXIO_I2S_TransferTxHandleIRQ(void *i2sBase, void *i2sHandle);
543
550void FLEXIO_I2S_TransferRxHandleIRQ(void *i2sBase, void *i2sHandle);
551
554#if defined(__cplusplus)
555}
556#endif /*_cplusplus*/
557
560#endif /* _FSL_FLEXIO_I2S_H_ */
enum _flexio_pin_polarity flexio_pin_polarity_t
Definition of pin polarity.
enum _flexio_shifter_timer_polarity flexio_shifter_timer_polarity_t
Define type of timer polarity for shifter control.
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_ShifterBufferBitSwapped
Definition: fsl_flexio.h:224
struct _flexio_i2s_config flexio_i2s_config_t
FlexIO I2S configure structure.
struct _flexio_i2s_transfer flexio_i2s_transfer_t
Define FlexIO I2S transfer structure.
void FLEXIO_I2S_EnableInterrupts(FLEXIO_I2S_Type *base, uint32_t mask)
Enables the FlexIO I2S interrupt.
Definition: fsl_flexio_i2s.c:302
void FLEXIO_I2S_MasterSetFormat(FLEXIO_I2S_Type *base, flexio_i2s_format_t *format, uint32_t srcClock_Hz)
Configures the FlexIO I2S audio format in master mode.
Definition: fsl_flexio_i2s.c:360
#define FLEXIO_I2S_XFER_QUEUE_SIZE
FlexIO I2S transfer queue size, user can refine it according to use case.
Definition: fsl_flexio_i2s.h:102
status_t FLEXIO_I2S_TransferSendNonBlocking(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, flexio_i2s_transfer_t *xfer)
Performs an interrupt non-blocking send transfer on FlexIO I2S.
Definition: fsl_flexio_i2s.c:626
void FLEXIO_I2S_Init(FLEXIO_I2S_Type *base, const flexio_i2s_config_t *config)
Initializes the FlexIO I2S.
Definition: fsl_flexio_i2s.c:115
_flexio_i2s_master_slave
Master or slave mode.
Definition: fsl_flexio_i2s.h:62
void FLEXIO_I2S_TransferTxCreateHandle(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, flexio_i2s_callback_t callback, void *userData)
Initializes the FlexIO I2S handle.
Definition: fsl_flexio_i2s.c:515
void FLEXIO_I2S_SlaveSetFormat(FLEXIO_I2S_Type *base, flexio_i2s_format_t *format)
Configures the FlexIO I2S audio format in slave mode.
Definition: fsl_flexio_i2s.c:387
void FLEXIO_I2S_TransferRxCreateHandle(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, flexio_i2s_callback_t callback, void *userData)
Initializes the FlexIO I2S receive handle.
Definition: fsl_flexio_i2s.c:553
void FLEXIO_I2S_Deinit(FLEXIO_I2S_Type *base)
De-initializes the FlexIO I2S.
Definition: fsl_flexio_i2s.c:280
void FLEXIO_I2S_TransferAbortSend(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle)
Aborts the current send.
Definition: fsl_flexio_i2s.c:717
status_t FLEXIO_I2S_TransferReceiveNonBlocking(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, flexio_i2s_transfer_t *xfer)
Performs an interrupt non-blocking receive transfer on FlexIO I2S.
Definition: fsl_flexio_i2s.c:673
enum _flexio_i2s_word_width flexio_i2s_word_width_t
Audio word width.
enum _flexio_i2s_sample_rate flexio_i2s_sample_rate_t
Audio sample rate.
status_t FLEXIO_I2S_TransferGetSendCount(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, size_t *count)
Gets the remaining bytes to be sent.
Definition: fsl_flexio_i2s.c:763
_flexio_i2s_sample_rate
Audio sample rate.
Definition: fsl_flexio_i2s.h:106
void(* flexio_i2s_callback_t)(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, status_t status, void *userData)
FlexIO I2S xfer callback prototype.
Definition: fsl_flexio_i2s.h:138
struct _flexio_i2s_type FLEXIO_I2S_Type
Define FlexIO I2S access structure typedef.
void FLEXIO_I2S_GetDefaultConfig(flexio_i2s_config_t *config)
Sets the FlexIO I2S configuration structure to default values.
Definition: fsl_flexio_i2s.c:257
uint32_t FLEXIO_I2S_GetStatusFlags(FLEXIO_I2S_Type *base)
Gets the FlexIO I2S status flags.
Definition: fsl_flexio_i2s.c:320
void FLEXIO_I2S_TransferSetFormat(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, flexio_i2s_format_t *format, uint32_t srcClock_Hz)
Configures the FlexIO I2S audio format.
Definition: fsl_flexio_i2s.c:590
struct _flexio_i2s_format flexio_i2s_format_t
FlexIO I2S audio format, FlexIO I2S only support the same format in Tx and Rx.
void FLEXIO_I2S_TransferAbortReceive(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle)
Aborts the current receive.
Definition: fsl_flexio_i2s.c:740
status_t FLEXIO_I2S_TransferGetReceiveCount(FLEXIO_I2S_Type *base, flexio_i2s_handle_t *handle, size_t *count)
Gets the remaining bytes to be received.
Definition: fsl_flexio_i2s.c:791
void FLEXIO_I2S_TransferTxHandleIRQ(void *i2sBase, void *i2sHandle)
Tx interrupt handler.
Definition: fsl_flexio_i2s.c:816
status_t FLEXIO_I2S_ReadBlocking(FLEXIO_I2S_Type *base, uint8_t bitWidth, uint8_t *rxData, size_t size)
Receives a piece of data using a blocking method.
Definition: fsl_flexio_i2s.c:470
void FLEXIO_I2S_DisableInterrupts(FLEXIO_I2S_Type *base, uint32_t mask)
Disables the FlexIO I2S interrupt.
Definition: fsl_flexio_i2s.c:338
void FLEXIO_I2S_TransferRxHandleIRQ(void *i2sBase, void *i2sHandle)
Rx interrupt handler.
Definition: fsl_flexio_i2s.c:866
_flexio_i2s_word_width
Audio word width.
Definition: fsl_flexio_i2s.h:121
status_t FLEXIO_I2S_WriteBlocking(FLEXIO_I2S_Type *base, uint8_t bitWidth, uint8_t *txData, size_t size)
Sends data using a blocking method.
Definition: fsl_flexio_i2s.c:408
enum _flexio_i2s_master_slave flexio_i2s_master_slave_t
Master or slave mode.
@ kFLEXIO_I2S_TxDataRegEmptyInterruptEnable
Definition: fsl_flexio_i2s.h:70
@ kFLEXIO_I2S_RxDataRegFullInterruptEnable
Definition: fsl_flexio_i2s.h:71
@ kFLEXIO_I2S_Master
Definition: fsl_flexio_i2s.h:63
@ kFLEXIO_I2S_Slave
Definition: fsl_flexio_i2s.h:64
@ kFLEXIO_I2S_SampleRate32KHz
Definition: fsl_flexio_i2s.h:113
@ kFLEXIO_I2S_SampleRate22050Hz
Definition: fsl_flexio_i2s.h:111
@ kFLEXIO_I2S_SampleRate12KHz
Definition: fsl_flexio_i2s.h:109
@ kFLEXIO_I2S_SampleRate24KHz
Definition: fsl_flexio_i2s.h:112
@ kFLEXIO_I2S_SampleRate16KHz
Definition: fsl_flexio_i2s.h:110
@ kFLEXIO_I2S_SampleRate96KHz
Definition: fsl_flexio_i2s.h:116
@ kFLEXIO_I2S_SampleRate11025Hz
Definition: fsl_flexio_i2s.h:108
@ kFLEXIO_I2S_SampleRate48KHz
Definition: fsl_flexio_i2s.h:115
@ kFLEXIO_I2S_SampleRate44100Hz
Definition: fsl_flexio_i2s.h:114
@ kFLEXIO_I2S_SampleRate8KHz
Definition: fsl_flexio_i2s.h:107
@ kStatus_FLEXIO_I2S_Timeout
Definition: fsl_flexio_i2s.h:42
@ kStatus_FLEXIO_I2S_TxBusy
Definition: fsl_flexio_i2s.h:38
@ kStatus_FLEXIO_I2S_Error
Definition: fsl_flexio_i2s.h:40
@ kStatus_FLEXIO_I2S_Idle
Definition: fsl_flexio_i2s.h:37
@ kStatus_FLEXIO_I2S_QueueFull
Definition: fsl_flexio_i2s.h:41
@ kStatus_FLEXIO_I2S_RxBusy
Definition: fsl_flexio_i2s.h:39
@ kFLEXIO_I2S_WordWidth16bits
Definition: fsl_flexio_i2s.h:123
@ kFLEXIO_I2S_WordWidth8bits
Definition: fsl_flexio_i2s.h:122
@ kFLEXIO_I2S_WordWidth32bits
Definition: fsl_flexio_i2s.h:125
@ kFLEXIO_I2S_WordWidth24bits
Definition: fsl_flexio_i2s.h:124
@ kFLEXIO_I2S_TxDataRegEmptyFlag
Definition: fsl_flexio_i2s.h:77
@ kFLEXIO_I2S_RxDataRegFullFlag
Definition: fsl_flexio_i2s.h:78
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_I2S
Definition: fsl_common.h:106
Definition: MIMXRT1052.h:20511
FlexIO I2S configure structure.
Definition: fsl_flexio_i2s.h:83
flexio_shifter_timer_polarity_t txTimerPolarity
Definition: fsl_flexio_i2s.h:90
flexio_shifter_timer_polarity_t rxTimerPolarity
Definition: fsl_flexio_i2s.h:91
flexio_pin_polarity_t rxPinPolarity
Definition: fsl_flexio_i2s.h:87
flexio_pin_polarity_t txPinPolarity
Definition: fsl_flexio_i2s.h:86
flexio_pin_polarity_t bclkPinPolarity
Definition: fsl_flexio_i2s.h:88
bool enableI2S
Definition: fsl_flexio_i2s.h:84
flexio_i2s_master_slave_t masterSlave
Definition: fsl_flexio_i2s.h:85
flexio_pin_polarity_t fsPinPolarity
Definition: fsl_flexio_i2s.h:89
FlexIO I2S audio format, FlexIO I2S only support the same format in Tx and Rx.
Definition: fsl_flexio_i2s.h:96
uint32_t sampleRate_Hz
Definition: fsl_flexio_i2s.h:98
uint8_t bitWidth
Definition: fsl_flexio_i2s.h:97
Define FlexIO I2S handle structure.
Definition: fsl_flexio_i2s.h:145
flexio_i2s_callback_t callback
Definition: fsl_flexio_i2s.h:147
volatile uint8_t queueUser
Definition: fsl_flexio_i2s.h:152
void * userData
Definition: fsl_flexio_i2s.h:148
flexio_i2s_transfer_t queue[FLEXIO_I2S_XFER_QUEUE_SIZE]
Definition: fsl_flexio_i2s.h:150
volatile uint8_t queueDriver
Definition: fsl_flexio_i2s.h:153
size_t transferSize[FLEXIO_I2S_XFER_QUEUE_SIZE]
Definition: fsl_flexio_i2s.h:151
uint8_t bitWidth
Definition: fsl_flexio_i2s.h:149
uint32_t state
Definition: fsl_flexio_i2s.h:146
Define FlexIO I2S transfer structure.
Definition: fsl_flexio_i2s.h:130
uint8_t * data
Definition: fsl_flexio_i2s.h:131
size_t dataSize
Definition: fsl_flexio_i2s.h:132
Define FlexIO I2S access structure typedef.
Definition: fsl_flexio_i2s.h:48
uint8_t fsPinIndex
Definition: fsl_flexio_i2s.h:53
uint8_t rxShifterIndex
Definition: fsl_flexio_i2s.h:55
uint8_t rxPinIndex
Definition: fsl_flexio_i2s.h:51
uint8_t txShifterIndex
Definition: fsl_flexio_i2s.h:54
uint8_t txPinIndex
Definition: fsl_flexio_i2s.h:50
uint8_t bclkPinIndex
Definition: fsl_flexio_i2s.h:52
FLEXIO_Type * flexioBase
Definition: fsl_flexio_i2s.h:49
uint8_t fsTimerIndex
Definition: fsl_flexio_i2s.h:57
uint8_t bclkTimerIndex
Definition: fsl_flexio_i2s.h:56
Definition: deflate.c:114
Definition: mknod-pack_dev.c:254
unsigned size
Definition: tte.h:1