S32 SDK
flexio_i2s_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_I2S_DRIVER_H
20 #define FLEXIO_I2S_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 
53 /*******************************************************************************
54  * Enumerations.
55  ******************************************************************************/
56 
57 
58 /*******************************************************************************
59 * Definitions
60 ******************************************************************************/
61 
62 
69 typedef struct
70 {
72  uint32_t baudRate;
73  uint8_t bitsWidth;
74  uint8_t txPin;
75  uint8_t rxPin;
76  uint8_t sckPin;
77  uint8_t wsPin;
82  void *callbackParam;
83  uint8_t rxDMAChannel;
84  uint8_t txDMAChannel;
86 
87 
94 typedef struct
95 {
97  uint8_t bitsWidth;
98  uint8_t txPin;
99  uint8_t rxPin;
100  uint8_t sckPin;
101  uint8_t wsPin;
107  uint8_t rxDMAChannel;
108  uint8_t txDMAChannel;
110 
111 
120 typedef struct
121 {
123  flexio_common_state_t flexioCommon; /* Common flexio drivers structure */
124  const uint8_t *txData; /* Transmit buffer. */
125  uint8_t *rxData; /* Receive buffer. */
126  uint32_t txRemainingBytes; /* Number of remaining bytes to be transmitted. */
127  uint32_t rxRemainingBytes; /* Number of remaining bytes to be received. */
128  uint32_t dummyDmaData; /* Dummy location for DMA transfers. */
129  uint8_t rxDMAChannel; /* Rx DMA channel number */
130  uint8_t txDMAChannel; /* Tx DMA channel number */
131  uint8_t bitsWidth; /* Number of bits in a word */
132  uint8_t byteWidth; /* Number of bytes in a word */
133  bool master; /* Current instance is in master mode */
134  flexio_driver_type_t driverType; /* Driver type: interrupts/polling/DMA */
135  status_t status; /* Current status of the driver */
136  bool driverIdle; /* Idle/busy state of the driver */
137  semaphore_t idleSemaphore; /* Semaphore used by blocking functions */
138  bool blocking; /* Specifies if the current transfer is blocking */
139  flexio_callback_t callback; /* User callback function */
140  void *callbackParam; /* Parameter for the callback function */
143 
153 
154 
155 /*******************************************************************************
156  * API
157  ******************************************************************************/
163 #if defined(__cplusplus)
164 extern "C" {
165 #endif
166 
183 status_t FLEXIO_I2S_DRV_MasterInit(uint32_t instance,
184  const flexio_i2s_master_user_config_t * userConfigPtr,
185  flexio_i2s_master_state_t * master);
186 
187 
199 
200 
218  uint32_t baudRate,
219  uint8_t bitsWidth);
220 
221 
232 
233 
249  const uint8_t * txBuff,
250  uint32_t txSize);
251 
252 
253 
267  const uint8_t * txBuff,
268  uint32_t txSize,
269  uint32_t timeout);
270 
271 
287  uint8_t * rxBuff,
288  uint32_t rxSize);
289 
290 
303  uint8_t * rxBuff,
304  uint32_t rxSize,
305  uint32_t timeout);
306 
307 
317 
318 
333 status_t FLEXIO_I2S_DRV_MasterGetStatus(flexio_i2s_master_state_t * master, uint32_t *bytesRemaining);
334 
335 
349  uint8_t * rxBuff,
350  uint32_t rxSize);
351 
352 
366  const uint8_t * txBuff,
367  uint32_t txSize);
368 
369 
386 status_t FLEXIO_I2S_DRV_SlaveInit(uint32_t instance,
387  const flexio_i2s_slave_user_config_t * userConfigPtr,
388  flexio_i2s_slave_state_t * slave);
389 
390 
403 {
404  return FLEXIO_I2S_DRV_MasterDeinit(slave);
405 }
406 
407 
418  uint8_t bitsWidth);
419 
420 
437  const uint8_t * txBuff,
438  uint32_t txSize)
439 {
440  return FLEXIO_I2S_DRV_MasterSendData(slave, txBuff, txSize);
441 }
442 
443 
444 
459  const uint8_t * txBuff,
460  uint32_t txSize,
461  uint32_t timeout)
462 {
463  return FLEXIO_I2S_DRV_MasterSendDataBlocking(slave, txBuff, txSize, timeout);
464 }
465 
466 
483  uint8_t * rxBuff,
484  uint32_t rxSize)
485 {
486  return FLEXIO_I2S_DRV_MasterReceiveData(slave, rxBuff, rxSize);
487 }
488 
489 
503  uint8_t * rxBuff,
504  uint32_t rxSize,
505  uint32_t timeout)
506 {
507  return FLEXIO_I2S_DRV_MasterReceiveDataBlocking(slave, rxBuff, rxSize, timeout);
508 }
509 
510 
521 {
523 }
524 
525 
541 static inline status_t FLEXIO_I2S_DRV_SlaveGetStatus(flexio_i2s_slave_state_t * slave, uint32_t *bytesRemaining)
542 {
543  return FLEXIO_I2S_DRV_MasterGetStatus(slave, bytesRemaining);
544 }
545 
546 
561  uint8_t * rxBuff,
562  uint32_t rxSize)
563 {
564  return FLEXIO_I2S_DRV_MasterSetRxBuffer(slave, rxBuff, rxSize);
565 }
566 
567 
582  const uint8_t * txBuff,
583  uint32_t txSize)
584 {
585  return FLEXIO_I2S_DRV_MasterSetTxBuffer(slave, txBuff, txSize);
586 }
587 
588 
590 #if defined(__cplusplus)
591 }
592 #endif
593 
596 #endif /* FLEXIO_I2S_DRIVER_H */
597 /*******************************************************************************
598  * EOF
599  ******************************************************************************/
status_t FLEXIO_I2S_DRV_MasterReceiveDataBlocking(flexio_i2s_master_state_t *master, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Perform a blocking receive transaction on the I2S bus.
status_t FLEXIO_I2S_DRV_MasterReceiveData(flexio_i2s_master_state_t *master, uint8_t *rxBuff, uint32_t rxSize)
Perform a non-blocking receive transaction on the I2S bus.
static status_t FLEXIO_I2S_DRV_SlaveTransferAbort(flexio_i2s_slave_state_t *slave)
Aborts a non-blocking I2S slave transaction.
status_t FLEXIO_I2S_DRV_MasterSetTxBuffer(flexio_i2s_master_state_t *master, const uint8_t *txBuff, uint32_t txSize)
Provide a buffer for transmitting data.
status_t FLEXIO_I2S_DRV_MasterSendData(flexio_i2s_master_state_t *master, const uint8_t *txBuff, uint32_t txSize)
Perform a non-blocking send transaction on the I2S bus.
Master internal context structure.
Slave configuration structure.
void(* flexio_callback_t)(void *driverState, flexio_event_t event, void *userData)
flexio callback function
Definition: flexio.h:81
static status_t FLEXIO_I2S_DRV_SlaveSetTxBuffer(flexio_i2s_slave_state_t *slave, const uint8_t *txBuff, uint32_t txSize)
Provide a buffer for transmitting data.
flexio_i2s_master_state_t flexio_i2s_slave_state_t
Slave internal context structure.
status_t FLEXIO_I2S_DRV_MasterDeinit(flexio_i2s_master_state_t *master)
De-initialize the FLEXIO_I2S master mode driver.
status_t FLEXIO_I2S_DRV_SlaveInit(uint32_t instance, const flexio_i2s_slave_user_config_t *userConfigPtr, flexio_i2s_slave_state_t *slave)
Initialize the FLEXIO_I2S slave mode driver.
static status_t FLEXIO_I2S_DRV_SlaveSendData(flexio_i2s_slave_state_t *slave, const uint8_t *txBuff, uint32_t txSize)
Perform a non-blocking send transaction on the I2S bus.
status_t FLEXIO_I2S_DRV_MasterSendDataBlocking(flexio_i2s_master_state_t *master, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Perform a blocking send transaction on the I2S bus.
status_t FLEXIO_I2S_DRV_MasterSetConfig(flexio_i2s_master_state_t *master, uint32_t baudRate, uint8_t bitsWidth)
Set the baud rate and bit width for any subsequent I2S communication.
status_t FLEXIO_I2S_DRV_MasterGetStatus(flexio_i2s_master_state_t *master, uint32_t *bytesRemaining)
Get the status of the current non-blocking I2S master transaction.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
flexio_driver_type_t driverType
static status_t FLEXIO_I2S_DRV_SlaveSetRxBuffer(flexio_i2s_slave_state_t *slave, uint8_t *rxBuff, uint32_t rxSize)
Provide a buffer for receiving data.
status_t FLEXIO_I2S_DRV_MasterInit(uint32_t instance, const flexio_i2s_master_user_config_t *userConfigPtr, flexio_i2s_master_state_t *master)
Initialize the FLEXIO_I2S master mode driver.
static status_t FLEXIO_I2S_DRV_SlaveGetStatus(flexio_i2s_slave_state_t *slave, uint32_t *bytesRemaining)
Get the status of the current non-blocking I2S slave transaction.
flexio_driver_type_t
Driver type: interrupts/polling/DMA Implements : flexio_driver_type_t_Class.
Definition: flexio.h:49
status_t FLEXIO_I2S_DRV_MasterSetRxBuffer(flexio_i2s_master_state_t *master, uint8_t *rxBuff, uint32_t rxSize)
Provide a buffer for receiving data.
Master configuration structure.
status_t FLEXIO_I2S_DRV_MasterGetBaudRate(flexio_i2s_master_state_t *master, uint32_t *baudRate)
Get the currently configured baud rate.
status_t FLEXIO_I2S_DRV_MasterTransferAbort(flexio_i2s_master_state_t *master)
Aborts a non-blocking I2S master transaction.
static status_t FLEXIO_I2S_DRV_SlaveReceiveData(flexio_i2s_slave_state_t *slave, uint8_t *rxBuff, uint32_t rxSize)
Perform a non-blocking receive transaction on the I2S bus.
static status_t FLEXIO_I2S_DRV_SlaveDeinit(flexio_i2s_slave_state_t *slave)
De-initialize the FLEXIO_I2S slave mode driver.
static status_t FLEXIO_I2S_DRV_SlaveReceiveDataBlocking(flexio_i2s_slave_state_t *slave, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Perform a blocking receive transaction on the I2S bus.
static status_t FLEXIO_I2S_DRV_SlaveSendDataBlocking(flexio_i2s_slave_state_t *slave, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Perform a blocking send transaction on the I2S bus.
status_t FLEXIO_I2S_DRV_SlaveSetConfig(flexio_i2s_slave_state_t *slave, uint8_t bitsWidth)
Set the bit width for any subsequent I2S communication.