RTEMS 6.1-rc1
fsl_spdif.h
1/*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2017-2020 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10#ifndef _FSL_SPDIF_H_
11#define _FSL_SPDIF_H_
12
13#include "fsl_common.h"
14
20/*******************************************************************************
21 * Definitions
22 ******************************************************************************/
23
26#define FSL_SPDIF_DRIVER_VERSION (MAKE_VERSION(2, 0, 6))
28
30enum
31{
49};
50
53{
59
62{
68
71{
76
79{
88
90typedef enum _spdif_tx_source
91{
95
98{
102
104enum
105{
106 kSPDIF_RxDPLLLocked = SPDIF_SIE_LOCK_MASK,
107 kSPDIF_TxFIFOError = SPDIF_SIE_TXUNOV_MASK,
108 kSPDIF_TxFIFOResync = SPDIF_SIE_TXRESYN_MASK,
109 kSPDIF_RxControlChannelChange = SPDIF_SIE_CNEW_MASK,
110 kSPDIF_ValidityFlagNoGood = SPDIF_SIE_VALNOGOOD_MASK,
111 kSPDIF_RxIllegalSymbol = SPDIF_SIE_SYMERR_MASK,
112 kSPDIF_RxParityBitError = SPDIF_SIE_BITERR_MASK,
113 kSPDIF_UChannelReceiveRegisterFull = SPDIF_SIE_URXFUL_MASK,
115 kSPDIF_QChannelReceiveRegisterFull = SPDIF_SIE_QRXFUL_MASK,
117 kSPDIF_UQChannelSync = SPDIF_SIE_UQSYNC_MASK,
118 kSPDIF_UQChannelFrameError = SPDIF_SIE_UQERR_MASK,
119 kSPDIF_RxFIFOError = SPDIF_SIE_RXFIFOUNOV_MASK,
120 kSPDIF_RxFIFOResync = SPDIF_SIE_RXFIFORESYN_MASK,
121 kSPDIF_LockLoss = SPDIF_SIE_LOCKLOSS_MASK,
122 kSPDIF_TxFIFOEmpty = SPDIF_SIE_TXEM_MASK,
123 kSPDIF_RxFIFOFull = SPDIF_SIE_RXFIFOFUL_MASK,
131};
132
134enum
135{
136 kSPDIF_RxDMAEnable = SPDIF_SCR_DMA_RX_EN_MASK,
137 kSPDIF_TxDMAEnable = SPDIF_SCR_DMA_TX_EN_MASK,
138};
139
141typedef struct _spdif_config
142{
146 uint8_t txClkSource;
154
156#define SPDIF_XFER_QUEUE_SIZE (4U)
157
159typedef struct _spdif_transfer
160{
161 uint8_t *data;
162 uint8_t *qdata;
163 uint8_t *udata;
164 size_t dataSize;
166
167typedef struct _spdif_handle spdif_handle_t;
168
170typedef void (*spdif_transfer_callback_t)(SPDIF_Type *base, spdif_handle_t *handle, status_t status, void *userData);
171
174{
175 uint32_t state;
177 void *userData;
180 volatile uint8_t queueUser;
181 volatile uint8_t queueDriver;
182 uint8_t watermark;
183};
184
185/*******************************************************************************
186 * API
187 ******************************************************************************/
188
189#if defined(__cplusplus)
190extern "C" {
191#endif /*_cplusplus*/
192
212void SPDIF_Init(SPDIF_Type *base, const spdif_config_t *config);
213
229
237void SPDIF_Deinit(SPDIF_Type *base);
238
244uint32_t SPDIF_GetInstance(SPDIF_Type *base);
245
253static inline void SPDIF_TxFIFOReset(SPDIF_Type *base)
254{
255 base->SCR |= SPDIF_SCR_RXFIFO_RST_MASK;
256}
257
265static inline void SPDIF_RxFIFOReset(SPDIF_Type *base)
266{
267 base->SCR |= SPDIF_SCR_RXFIFO_RST_MASK;
268}
269
276void SPDIF_TxEnable(SPDIF_Type *base, bool enable);
277
284static inline void SPDIF_RxEnable(SPDIF_Type *base, bool enable)
285{
286 if (enable)
287 {
288 /* Open Rx FIFO */
289 base->SCR &= ~(SPDIF_SCR_RXFIFO_CTRL_MASK | SPDIF_SCR_RXFIFO_OFF_ON_MASK);
290 }
291 else
292 {
293 base->SCR |= SPDIF_SCR_RXFIFO_OFF_ON_MASK;
294 }
295}
296
310static inline uint32_t SPDIF_GetStatusFlag(SPDIF_Type *base)
311{
312 return base->SIS;
313}
314
326static inline void SPDIF_ClearStatusFlags(SPDIF_Type *base, uint32_t mask)
327{
328 base->SIC = mask;
329}
330
350static inline void SPDIF_EnableInterrupts(SPDIF_Type *base, uint32_t mask)
351{
352 base->SIE |= mask;
353}
354
367static inline void SPDIF_DisableInterrupts(SPDIF_Type *base, uint32_t mask)
368{
369 base->SIE &= ~mask;
370}
371
387static inline void SPDIF_EnableDMA(SPDIF_Type *base, uint32_t mask, bool enable)
388{
389 if (enable)
390 {
391 base->SCR |= mask;
392 }
393 else
394 {
395 base->SCR &= ~mask;
396 }
397}
398
407static inline uint32_t SPDIF_TxGetLeftDataRegisterAddress(SPDIF_Type *base)
408{
409 return (uint32_t)(&(base->STL));
410}
411
420static inline uint32_t SPDIF_TxGetRightDataRegisterAddress(SPDIF_Type *base)
421{
422 return (uint32_t)(&(base->STR));
423}
424
433static inline uint32_t SPDIF_RxGetLeftDataRegisterAddress(SPDIF_Type *base)
434{
435 return (uint32_t)(&(base->SRL));
436}
437
446static inline uint32_t SPDIF_RxGetRightDataRegisterAddress(SPDIF_Type *base)
447{
448 return (uint32_t)(&(base->SRR));
449}
450
467void SPDIF_TxSetSampleRate(SPDIF_Type *base, uint32_t sampleRate_Hz, uint32_t sourceClockFreq_Hz);
468
478uint32_t SPDIF_GetRxSampleRate(SPDIF_Type *base, uint32_t clockSourceFreq_Hz);
479
489void SPDIF_WriteBlocking(SPDIF_Type *base, uint8_t *buffer, uint32_t size);
490
497static inline void SPDIF_WriteLeftData(SPDIF_Type *base, uint32_t data)
498{
499 base->STL = data;
500}
501
508static inline void SPDIF_WriteRightData(SPDIF_Type *base, uint32_t data)
509{
510 base->STR = data;
511}
512
519static inline void SPDIF_WriteChannelStatusHigh(SPDIF_Type *base, uint32_t data)
520{
521 base->STCSCH = data;
522}
523
530static inline void SPDIF_WriteChannelStatusLow(SPDIF_Type *base, uint32_t data)
531{
532 base->STCSCL = data;
533}
534
544void SPDIF_ReadBlocking(SPDIF_Type *base, uint8_t *buffer, uint32_t size);
545
552static inline uint32_t SPDIF_ReadLeftData(SPDIF_Type *base)
553{
554 return base->SRL;
555}
556
563static inline uint32_t SPDIF_ReadRightData(SPDIF_Type *base)
564{
565 return base->SRR;
566}
567
574static inline uint32_t SPDIF_ReadChannelStatusHigh(SPDIF_Type *base)
575{
576 return base->SRCSH;
577}
578
585static inline uint32_t SPDIF_ReadChannelStatusLow(SPDIF_Type *base)
586{
587 return base->SRCSL;
588}
589
596static inline uint32_t SPDIF_ReadQChannel(SPDIF_Type *base)
597{
598 return base->SRQ;
599}
600
607static inline uint32_t SPDIF_ReadUChannel(SPDIF_Type *base)
608{
609 return base->SRU;
610}
611
631 spdif_handle_t *handle,
633 void *userData);
634
647 spdif_handle_t *handle,
649 void *userData);
650
667
684
694status_t SPDIF_TransferGetSendCount(SPDIF_Type *base, spdif_handle_t *handle, size_t *count);
695
706
717
728
736
744
747#if defined(__cplusplus)
748}
749#endif /*_cplusplus*/
750
753#endif /* _FSL_SPDIF_H_ */
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_SPDIF
Definition: fsl_common.h:147
void SPDIF_TransferAbortSend(SPDIF_Type *base, spdif_handle_t *handle)
Aborts the current send.
Definition: fsl_spdif.c:599
status_t SPDIF_TransferReceiveNonBlocking(SPDIF_Type *base, spdif_handle_t *handle, spdif_transfer_t *xfer)
Performs an interrupt non-blocking receive transfer on SPDIF.
Definition: fsl_spdif.c:492
enum _spdif_uchannel_source spdif_uchannel_source_t
SPDIF U channel source.
void SPDIF_GetDefaultConfig(spdif_config_t *config)
Sets the SPDIF configuration structure to default values.
Definition: fsl_spdif.c:156
void SPDIF_TransferTxHandleIRQ(SPDIF_Type *base, spdif_handle_t *handle)
Tx interrupt handler.
Definition: fsl_spdif.c:646
status_t SPDIF_TransferSendNonBlocking(SPDIF_Type *base, spdif_handle_t *handle, spdif_transfer_t *xfer)
Performs an interrupt non-blocking send transfer on SPDIF.
Definition: fsl_spdif.c:449
_spdif_validity_config
SPDIF tx data source.
Definition: fsl_spdif.h:98
void SPDIF_Deinit(SPDIF_Type *base)
De-initializes the SPDIF peripheral.
Definition: fsl_spdif.c:133
void SPDIF_TransferTxCreateHandle(SPDIF_Type *base, spdif_handle_t *handle, spdif_transfer_callback_t callback, void *userData)
Initializes the SPDIF Tx handle.
Definition: fsl_spdif.c:375
void SPDIF_ReadBlocking(SPDIF_Type *base, uint8_t *buffer, uint32_t size)
Receives data using a blocking method.
Definition: fsl_spdif.c:330
#define SPDIF_XFER_QUEUE_SIZE
SPDIF transfer queue size, user can refine it according to use case.
Definition: fsl_spdif.h:156
status_t SPDIF_TransferGetSendCount(SPDIF_Type *base, spdif_handle_t *handle, size_t *count)
Gets a set byte count.
Definition: fsl_spdif.c:543
void SPDIF_TxEnable(SPDIF_Type *base, bool enable)
Enables/disables the SPDIF Tx.
Definition: fsl_spdif.c:179
void SPDIF_TransferAbortReceive(SPDIF_Type *base, spdif_handle_t *handle)
Aborts the current IRQ receive.
Definition: fsl_spdif.c:623
_spdif_gain_select
SPDIF clock gain.
Definition: fsl_spdif.h:79
void SPDIF_Init(SPDIF_Type *base, const spdif_config_t *config)
Initializes the SPDIF peripheral.
Definition: fsl_spdif.c:90
_spdif_uchannel_source
SPDIF U channel source.
Definition: fsl_spdif.h:71
void(* spdif_transfer_callback_t)(SPDIF_Type *base, spdif_handle_t *handle, status_t status, void *userData)
SPDIF transfer callback prototype.
Definition: fsl_spdif.h:170
enum _spdif_gain_select spdif_gain_select_t
SPDIF clock gain.
_spdif_txempty_select
SPDIF tx FIFO EMPTY falg select, it decides when assert the tx empty flag.
Definition: fsl_spdif.h:62
void SPDIF_TransferRxHandleIRQ(SPDIF_Type *base, spdif_handle_t *handle)
Tx interrupt handler.
Definition: fsl_spdif.c:709
status_t SPDIF_TransferGetReceiveCount(SPDIF_Type *base, spdif_handle_t *handle, size_t *count)
Gets a received byte count.
Definition: fsl_spdif.c:571
void SPDIF_WriteBlocking(SPDIF_Type *base, uint8_t *buffer, uint32_t size)
Sends data using a blocking method.
Definition: fsl_spdif.c:286
enum _spdif_rxfull_select spdif_rxfull_select_t
SPDIF Rx FIFO full falg select, it decides when assert the rx full flag.
void SPDIF_TransferRxCreateHandle(SPDIF_Type *base, spdif_handle_t *handle, spdif_transfer_callback_t callback, void *userData)
Initializes the SPDIF Rx handle.
Definition: fsl_spdif.c:410
enum _spdif_tx_source spdif_tx_source_t
SPDIF tx data source.
uint32_t SPDIF_GetInstance(SPDIF_Type *base)
Get the instance number for SPDIF.
Definition: fsl_spdif.c:58
enum _spdif_validity_config spdif_validity_config_t
SPDIF tx data source.
void SPDIF_TxSetSampleRate(SPDIF_Type *base, uint32_t sampleRate_Hz, uint32_t sourceClockFreq_Hz)
Configures the SPDIF Tx sample rate.
Definition: fsl_spdif.c:209
struct _spdif_config spdif_config_t
SPDIF user configuration structure.
_spdif_tx_source
SPDIF tx data source.
Definition: fsl_spdif.h:91
struct _spdif_transfer spdif_transfer_t
SPDIF transfer structure.
_spdif_rxfull_select
SPDIF Rx FIFO full falg select, it decides when assert the rx full flag.
Definition: fsl_spdif.h:53
uint32_t SPDIF_GetRxSampleRate(SPDIF_Type *base, uint32_t clockSourceFreq_Hz)
Configures the SPDIF Rx audio format.
Definition: fsl_spdif.c:256
enum _spdif_txempty_select spdif_txempty_select_t
SPDIF tx FIFO EMPTY falg select, it decides when assert the tx empty flag.
@ kSPDIF_validityFlagAlwaysClear
Definition: fsl_spdif.h:100
@ kSPDIF_validityFlagAlwaysSet
Definition: fsl_spdif.h:99
@ kSPDIF_RxDMAEnable
Definition: fsl_spdif.h:136
@ kSPDIF_TxDMAEnable
Definition: fsl_spdif.h:137
@ kSPDIF_GAIN_3
Definition: fsl_spdif.h:86
@ kSPDIF_GAIN_6
Definition: fsl_spdif.h:84
@ kSPDIF_GAIN_4
Definition: fsl_spdif.h:85
@ kSPDIF_GAIN_16
Definition: fsl_spdif.h:81
@ kSPDIF_GAIN_8
Definition: fsl_spdif.h:83
@ kSPDIF_GAIN_24
Definition: fsl_spdif.h:80
@ kSPDIF_GAIN_12
Definition: fsl_spdif.h:82
@ kSPDIF_RxParityBitError
Definition: fsl_spdif.h:112
@ kSPDIF_RxFIFOError
Definition: fsl_spdif.h:119
@ kSPDIF_LockLoss
Definition: fsl_spdif.h:121
@ kSPDIF_UChannelReceiveRegisterOverrun
Definition: fsl_spdif.h:114
@ kSPDIF_RxControlChannelChange
Definition: fsl_spdif.h:109
@ kSPDIF_QChannelReceiveRegisterOverrun
Definition: fsl_spdif.h:116
@ kSPDIF_UQChannelSync
Definition: fsl_spdif.h:117
@ kSPDIF_TxFIFOError
Definition: fsl_spdif.h:107
@ kSPDIF_ValidityFlagNoGood
Definition: fsl_spdif.h:110
@ kSPDIF_QChannelReceiveRegisterFull
Definition: fsl_spdif.h:115
@ kSPDIF_TxFIFOEmpty
Definition: fsl_spdif.h:122
@ kSPDIF_RxFIFOFull
Definition: fsl_spdif.h:123
@ kSPDIF_RxIllegalSymbol
Definition: fsl_spdif.h:111
@ kSPDIF_RxDPLLLocked
Definition: fsl_spdif.h:106
@ kSPDIF_UQChannelFrameError
Definition: fsl_spdif.h:118
@ kSPDIF_UChannelReceiveRegisterFull
Definition: fsl_spdif.h:113
@ kSPDIF_RxFIFOResync
Definition: fsl_spdif.h:120
@ kSPDIF_TxFIFOResync
Definition: fsl_spdif.h:108
@ kSPDIF_AllInterrupt
Definition: fsl_spdif.h:124
@ kSPDIF_UChannelFromTx
Definition: fsl_spdif.h:74
@ kSPDIF_UChannelFromRx
Definition: fsl_spdif.h:73
@ kSPDIF_NoUChannel
Definition: fsl_spdif.h:72
@ kSPDIF_TxEmpty4Samples
Definition: fsl_spdif.h:64
@ kSPDIF_TxEmpty0Sample
Definition: fsl_spdif.h:63
@ kSPDIF_TxEmpty12Samples
Definition: fsl_spdif.h:66
@ kSPDIF_TxEmpty8Samples
Definition: fsl_spdif.h:65
@ kStatus_SPDIF_UChannelOverrun
Definition: fsl_spdif.h:39
@ kStatus_SPDIF_RxDPLLLocked
Definition: fsl_spdif.h:32
@ kStatus_SPDIF_TxFIFOResync
Definition: fsl_spdif.h:34
@ kStatus_SPDIF_QChannelOverrun
Definition: fsl_spdif.h:40
@ kStatus_SPDIF_RxFIFOError
Definition: fsl_spdif.h:43
@ kStatus_SPDIF_RxCnew
Definition: fsl_spdif.h:35
@ kStatus_SPDIF_TxFIFOError
Definition: fsl_spdif.h:33
@ kStatus_SPDIF_RxIllegalSymbol
Definition: fsl_spdif.h:37
@ kStatus_SPDIF_UQChannelSync
Definition: fsl_spdif.h:41
@ kStatus_SPDIF_TxIdle
Definition: fsl_spdif.h:46
@ kStatus_SPDIF_ValidatyNoGood
Definition: fsl_spdif.h:36
@ kStatus_SPDIF_QueueFull
Definition: fsl_spdif.h:48
@ kStatus_SPDIF_LockLoss
Definition: fsl_spdif.h:45
@ kStatus_SPDIF_RxFIFOResync
Definition: fsl_spdif.h:44
@ kStatus_SPDIF_RxIdle
Definition: fsl_spdif.h:47
@ kStatus_SPDIF_UQChannelFrameError
Definition: fsl_spdif.h:42
@ kStatus_SPDIF_RxParityBitError
Definition: fsl_spdif.h:38
@ kSPDIF_txNormal
Definition: fsl_spdif.h:93
@ kSPDIF_txFromReceiver
Definition: fsl_spdif.h:92
@ kSPDIF_RxFull8Samples
Definition: fsl_spdif.h:56
@ kSPDIF_RxFull4Samples
Definition: fsl_spdif.h:55
@ kSPDIF_RxFull16Samples
Definition: fsl_spdif.h:57
@ kSPDIF_RxFull1Sample
Definition: fsl_spdif.h:54
Definition: MIMXRT1052.h:42276
SPDIF user configuration structure.
Definition: fsl_spdif.h:142
uint8_t txClkSource
Definition: fsl_spdif.h:146
uint8_t DPLLClkSource
Definition: fsl_spdif.h:145
spdif_gain_select_t gain
Definition: fsl_spdif.h:152
bool isRxAutoSync
Definition: fsl_spdif.h:144
spdif_tx_source_t txSource
Definition: fsl_spdif.h:150
spdif_validity_config_t validityConfig
Definition: fsl_spdif.h:151
spdif_txempty_select_t txFullSelect
Definition: fsl_spdif.h:148
bool isTxAutoSync
Definition: fsl_spdif.h:143
spdif_rxfull_select_t rxFullSelect
Definition: fsl_spdif.h:147
spdif_uchannel_source_t uChannelSrc
Definition: fsl_spdif.h:149
SPDIF handle structure.
Definition: fsl_spdif.h:174
uint8_t watermark
Definition: fsl_spdif.h:182
size_t transferSize[SPDIF_XFER_QUEUE_SIZE]
Definition: fsl_spdif.h:179
uint32_t state
Definition: fsl_spdif.h:175
volatile uint8_t queueUser
Definition: fsl_spdif.h:180
spdif_transfer_callback_t callback
Definition: fsl_spdif.h:176
void * userData
Definition: fsl_spdif.h:177
volatile uint8_t queueDriver
Definition: fsl_spdif.h:181
spdif_transfer_t spdifQueue[SPDIF_XFER_QUEUE_SIZE]
Definition: fsl_spdif.h:178
SPDIF transfer structure.
Definition: fsl_spdif.h:160
size_t dataSize
Definition: fsl_spdif.h:164
uint8_t * udata
Definition: fsl_spdif.h:163
uint8_t * qdata
Definition: fsl_spdif.h:162
uint8_t * data
Definition: fsl_spdif.h:161
Definition: deflate.c:114
unsigned size
Definition: tte.h:1