1 /*
2  * Copyright 2019-2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_ASRC_H_
9 #define _FSL_ASRC_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup asrc_driver
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*@{*/
24 #define FSL_ASRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 6)) /*!< Version 2.0.6 */
25 /*@}*/
26 
27 /*! @brief ASRC fifo depth */
28 #define FSL_ASRC_INPUT_FIFO_DEPTH  (128U)
29 #define FSL_ASRC_OUTPUT_FIFO_DEPTH (64U)
30 /*! @brief ASRC support maximum channel number of context */
31 #define ASRC_SUPPORT_MAXIMUM_CONTEXT_PROCESSOR_NUMBER 4U
32 
33 /*! @brief ASRC return status, _asrc_status*/
34 enum
35 {
36     kStatus_ASRCIdle                     = MAKE_STATUS(kStatusGroup_ASRC, 0),  /*!< ASRC  is idle. */
37     kStatus_ASRCBusy                     = MAKE_STATUS(kStatusGroup_ASRC, 1),  /*!< ASRC  is busy. */
38     kStatus_ASRCInvalidArgument          = MAKE_STATUS(kStatusGroup_ASRC, 2),  /*!< ASRC invalid argument. */
39     kStatus_ASRCConfigureFailed          = MAKE_STATUS(kStatusGroup_ASRC, 3),  /*!< ASRC configure failed */
40     kStatus_ASRCConvertError             = MAKE_STATUS(kStatusGroup_ASRC, 4),  /*!< ASRC convert error failed */
41     kStatus_ASRCNotSupport               = MAKE_STATUS(kStatusGroup_ASRC, 5),  /*!< ASRC not support */
42     kStatus_ASRCQueueFull                = MAKE_STATUS(kStatusGroup_ASRC, 6),  /*!< ASRC queue full */
43     kStatus_ASRCQueueIdle                = MAKE_STATUS(kStatusGroup_ASRC, 7),  /*!< ASRC quue idle */
44     kStatus_ASRCLoadFirmwareFailed       = MAKE_STATUS(kStatusGroup_ASRC, 8),  /*!< ASRC load firmware failed*/
45     kStatus_ASRCResamplerConfigureFailed = MAKE_STATUS(kStatusGroup_ASRC, 9),  /*!< ASRC resampler configured failed */
46     kStatus_ASRCPrefilterConfigureFailed = MAKE_STATUS(kStatusGroup_ASRC, 10), /*!< ASRC prefilter configured failed */
47 };
48 
49 /*! @brief asrc context id */
50 typedef enum _asrc_context
51 {
52     kASRC_Context0 = 0, /*!< Context 0 value */
53     kASRC_Context1 = 1, /*!< Context 1 value */
54     kASRC_Context2 = 2, /*!< Context 2 value */
55     kASRC_Context3 = 3, /*!< Context 3 value */
56 } asrc_context_t;
57 
58 /*! @brief The ASRC interrupt enable flag, _asrc_interrupt_mask*/
59 enum
60 {
61     kASRC_Context0InputFifoOverflow = 1U,       /*!< context 0 input fifo overflow */
62     kASRC_Context1InputFifoOverflow = 1U << 1U, /*!< context 1 input fifo overflow */
63     kASRC_Context2InputFifoOverflow = 1U << 2U, /*!< context 2 input fifo overflow */
64     kASRC_Context3InputFifoOverflow = 1U << 3U, /*!< context 3 input fifo overflow */
65 
66     kASRC_Context0OutFifoReadEmpty = 1U << 4U, /*!< context 0 out fifo read empty */
67     kASRC_Context1OutFifoReadEmpty = 1U << 5U, /*!< context 1 out fifo read empty */
68     kASRC_Context2OutFifoReadEmpty = 1U << 6U, /*!< context 2 out fifo read empty */
69     kASRC_Context3OutFifoReadEmpty = 1U << 7U, /*!< context 3 out fifo read empty */
70 
71     kASRC_Context0RunStopDone       = 1U << 8U,  /*!< context 0 run stop done interrupt */
72     kASRC_Context1RunStopDone       = 1U << 9U,  /*!< context 1 run stop done interrupt */
73     kASRC_Context2RunStopDone       = 1U << 10U, /*!< context 2 run stop done interrupt */
74     kASRC_Context3RunStopDone       = 1U << 11U, /*!< context 3 run stop done interrupt */
75     kASRC_ContextAllInterruptStatus = 0xFFFU,    /*!< all the context interrupt status */
76 };
77 
78 /*! @brief ASRC fifo status, _asrc_fifo_status*/
79 enum
80 {
81     kASRC_FifoStatusInputFifoWatermarkFlag =
82         ASRC_SAMPLE_FIFO_STATUS_INFIFO_WTMK_MASK, /*!< input water mark flag raised */
83     kASRC_FifoStatusOutputFifoWatermarkFlag =
84         ASRC_SAMPLE_FIFO_STATUS_OUTFIFO_WTMK_MASK, /*!< output water mark flag raised */
85 };
86 
87 /*! @brief arsc data endianness */
88 typedef enum _asrc_data_endianness
89 {
90     kASRC_DataEndianLittle = 0U, /*!< context data little endian */
91     kASRC_DataEndianBig    = 1U, /*!< context data big endian */
92 } asrc_data_endianness_t;
93 
94 /*! @brief data width */
95 typedef enum _asrc_data_width
96 {
97     kASRC_DataWidth32Bit = 3U, /*!< data width 32bit */
98     kASRC_DataWidth24Bit = 2U, /*!< data width 24bit */
99     kASRC_DataWidth20Bit = 1U, /*!< data width 20bit */
100     kASRC_DataWidth16Bit = 0U, /*!< data width 16bit */
101 } asrc_data_width_t;
102 
103 /*! @brief data type */
104 typedef enum _asrc_data_type
105 {
106     kASRC_DataTypeInteger = 0U, /*!< data type int */
107     kASRC_DataTypeFloat   = 1U, /*!< data type float, single precision floating point format */
108 } asrc_data_type_t;
109 
110 /*! @brief sign extension */
111 typedef enum _asrc_data_sign
112 {
113     kASRC_DataSigned   = 0U, /*!< input data is signed */
114     kASRC_DataUnsigned = 1U, /*!< input data is unsinged */
115 } asrc_data_sign_t;
116 
117 /*! @brief  asrc prefilter and resampler sample buffer init mode */
118 typedef enum _asrc_sampleBuffer_init_mode
119 {
120     kASRC_SampleBufferNoPreFillOnInit = 0U, /*!< do not pre-fill */
121     kASRC_SampleBufferFillFirstSampleOnInit =
122         1U, /*!< replicate the first sample to fill the right half of the sample buffer */
123     kASRC_SampleBufferFillZeroOnInit = 2U, /*!< zero fill the right half og the sample buffer */
124 } asrc_sampleBuffer_init_mode_t;
125 
126 /*! @brief  asrc prefilter and resampler sample buffer stop mode */
127 typedef enum _asrc_sampleBuffer_stop_mode
128 {
129     kASRC_SampleBufferFillLastSampleOnStop =
130         0U,                                /*!< replicate the last sample to fill the left half of the sample buffer */
131     kASRC_SampleBufferFillZeroOnStop = 1U, /*!< zero fill the left half of the sample buffer */
132 } asrc_sampleBuffer_stop_mode_t;
133 
134 /*! @brief ASRC prefilter stage1 result format */
135 typedef enum _asrc_prefilter_stage1_result
136 {
137     kASRC_PrefilterStage1ResultInt   = 0U, /*!< prefilter stage1 results are stored in 32 bit int format */
138     kASRC_PrefilterStage1ResultFloat = 1U, /*!< prefilter stage1 results are stored in 32 bit float format */
139 } asrc_prefilter_stage1_result_t;
140 
141 /*! @brief ASRC resampler taps */
142 typedef enum _asrc_resampler_taps
143 {
144     kASRC_ResamplerTaps_32  = 32U,  /*!< resampler taps 32 */
145     kASRC_ResamplerTaps_64  = 64U,  /*!< resampler taps 64 */
146     kASRC_ResamplerTaps_128 = 128U, /*!< resampler taps 128 */
147 } asrc_resampler_taps_t;
148 
149 /*! @brief ASRC support sample rate, _asrc_sample_rate */
150 enum
151 {
152     kASRC_SampleRate_8000   = 8000,   /*!< 8K sample rate */
153     kASRC_SampleRate_11025  = 11025,  /*!< 11025 sample rate */
154     kASRC_SampleRate_12000  = 12000,  /*!< 12K sample rate */
155     kASRC_SampleRate_16000  = 16000,  /*!< 16K sample rate */
156     kASRC_SampleRate_22050  = 22050,  /*!< 22.05K sample rate */
157     kASRC_SampleRate_24000  = 24000,  /*!< 24K sample rate */
158     kASRC_SampleRate_32000  = 32000,  /*!< 32K sample rate */
159     kASRC_SampleRate_44100  = 44100,  /*!< 44.1K sample rate */
160     kASRC_SampleRate_48000  = 48000,  /*!< 48K sample rate */
161     kASRC_SampleRate_64000  = 64000,  /*!< 64K sample rate */
162     kASRC_SampleRate_88200  = 88200,  /*!< 88.2K sample rate */
163     kASRC_SampleRate_96000  = 96000,  /*!< 96K sample rate */
164     kASRC_SampleRate_128000 = 128000, /*!< 128K sample rate */
165     kASRC_SampleRate_176400 = 176400, /*!< 176K sample rate */
166     kASRC_SampleRate_192000 = 192000, /*!< 256K sample rate */
167     kASRC_SampleRate_256000 = 256000, /*!< 256K sample rate */
168     kASRC_SampleRate_352800 = 352800, /*!< 352.8K sample rate */
169     kASRC_SampleRate_384000 = 384000, /*!< 384K sample rate */
170     kASRC_SampleRate_768000 = 768000, /*!< 768K sample rate */
171 };
172 
173 /*! @brief asrc context data format */
174 typedef struct _asrc_data_format
175 {
176     uint8_t dataPosition;                  /*!< context input data sample position */
177     asrc_data_endianness_t dataEndianness; /*!< context input data endianness */
178     asrc_data_width_t dataWidth;           /*!< context input data width */
179     asrc_data_type_t dataType;             /*!< context input data type */
180     asrc_data_sign_t dataSign;             /*!< context input data signed or unsigned */
181 } asrc_data_format_t;
182 
183 /*! @brief asrc context access control
184  * The ASRC provides interleaving support in hardware to ensure that a variety of sample source can be internally
185  * combined tp confir with this format. The interleave patter is controlled using 3 register fields: GROUP_LENGTH,
186  * ACCESS_LENGTH, ITERATIONIS. This is intended to support hardware configurations which distribute a single context
187  * across samples from multiple audio sources. Take a example as below: accessGroupLen = 6, the sample group length is 6
188  * samples accessIterations = 2, the 2 sequential ACCESS_LENGTH read from single source accessLen = 2, the 2 samples
189  * fetch from one source.
190  */
191 typedef struct _asrc_access_ctrl
192 {
193     uint8_t accessIterations; /*!< number of sequential fetches per source */
194     uint8_t accessGroupLen;   /*!< number of channels in a context */
195     uint8_t accessLen;        /*!< number of channels per source1 */
196 } asrc_access_ctrl_t;
197 
198 /*! @brief asrc context input configuration */
199 typedef struct _asrc_context_input_config
200 {
201     uint32_t sampleRate;           /*!< input audio data sample rate */
202     uint8_t watermark;             /*!< input water mark per samples */
203     asrc_access_ctrl_t accessCtrl; /*!< input access control */
204     asrc_data_format_t dataFormat; /*!< input data format */
205 } asrc_context_input_config_t;
206 
207 /*! @brief asrc context output configuration */
208 typedef struct _asrc_context_output_config
209 {
210     uint32_t sampleRate;           /*!< output audio data sample rate */
211     uint8_t watermark;             /*!< output water mark per samples */
212     asrc_access_ctrl_t accessCtrl; /*!< output access control */
213     asrc_data_format_t dataFormat; /*!< output data format */
214     bool enableDither;   /*!< output path contains a TPDF dither function. The dither function support all fixed output
215                             modes(16, 20, 24, 32bits)   dither is not supported in 32bit floating point output mode */
216     bool enableIEC60958; /*!< output IEC60958 bit field insertion enable */
217 } asrc_context_output_config_t;
218 
219 /*! @brief asrc context prefilter configuration */
220 typedef struct _asrc_context_prefilter_config
221 {
222     asrc_sampleBuffer_init_mode_t initMode;      /*!< prefilter initial mode */
223     asrc_sampleBuffer_stop_mode_t stopMode;      /*!< prefilter stop mode */
224     asrc_prefilter_stage1_result_t stage1Result; /*!< stage1 data store format */
225     /*
226      * applciation can untouch below configuration by set filterCoeffAddress to NULL , driver will load it from the
227      * driver firmware table, otherwise driver will use the value directly.
228      */
229     uint32_t filterSt1Taps;             /*!< prefilter stage1 taps */
230     uint32_t filterSt2Taps;             /*!< prefilter stage2 taps */
231     uint32_t filterSt1Exp;              /*!< prefilter stage1 expansion factor */
232     const uint32_t *filterCoeffAddress; /*!< prefilter coeff address */
233 } asrc_context_prefilter_config_t;
234 
235 /*! @brief asrc context resampler configuration */
236 typedef struct _asrc_context_resampler_config
237 {
238     asrc_sampleBuffer_init_mode_t initMode; /*!< initial mode */
239     asrc_sampleBuffer_stop_mode_t stopMode; /*!< resampler stop mode */
240     asrc_resampler_taps_t tap;              /*!< resampleer taps */
241     /*
242      * applciation can untouch below configuration by set filterCoeffAddress to NULL , driver will load it from the
243      * driver firmware table, otherwise driver will use the value directly.
244      */
245     uint32_t filterPhases;              /*!< interpolation phases */
246     uint64_t filterCenterTap;           /*!< interpolation center tap */
247     const uint32_t *filterCoeffAddress; /*!< interpolation coeff address */
248 } asrc_context_resampler_config_t;
249 
250 /*! @brief asrc context configuration */
251 typedef struct _asrc_context_config
252 {
253     uint8_t contextChannelNums;                       /*!< context channel numbers */
254     asrc_context_input_config_t contextInput;         /*!< context input configuration */
255     asrc_context_output_config_t contextOutput;       /*!< context output configuration */
256     asrc_context_prefilter_config_t contextPrefilter; /*!< context pre filter configuration */
257     asrc_context_resampler_config_t contextResampler; /*!< context resampler configuration */
258 } asrc_context_config_t;
259 
260 /*! @brief ASRC transfer */
261 typedef struct _asrc_transfer
262 {
263     uint32_t *inDataAddr;  /*!< address of audio data to be converted */
264     uint32_t inDataSize;   /*!< size of the audio data */
265     uint32_t *outDataAddr; /*!< address of audio data that is been converted */
266     uint32_t outDataSize;  /*!< size of the audio data */
267 } asrc_transfer_t;
268 /*******************************************************************************
269  * API
270  ******************************************************************************/
271 
272 #if defined(__cplusplus)
273 extern "C" {
274 #endif /*_cplusplus*/
275 
276 /*!
277  * @name Initialization and deinitialization
278  * @{
279  */
280 
281 /*!
282  * @brief Get instance number of the ASRC peripheral.
283  *
284  * @param base ASRC base pointer.
285  */
286 uint32_t ASRC_GetInstance(ASRC_Type *base);
287 
288 /*!
289  * brief Initializes the asrc peripheral.
290  *
291  * This API gates the asrc clock. The asrc module can't operate unless ASRC_Init is called to enable the clock.
292  *
293  * param base asrc base pointer.
294  */
295 void ASRC_Init(ASRC_Type *base);
296 
297 /*!
298  * @brief De-initializes the ASRC peripheral.
299  *
300  * This API gates the ASRC clock and disable ASRC module. The ASRC module can't operate unless ASRC_Init
301  *
302  * @param base ASRC base pointer.
303  */
304 void ASRC_Deinit(ASRC_Type *base);
305 
306 /*!
307  * @brief ASRC get context default configuration.
308  *
309  * @param config ASRC context configuration pointer.
310  * @param channels input audio data channel numbers.
311  * @param inSampleRate input sample rate.
312  * @param outSampleRate output sample rate.
313  */
314 void ASRC_GetContextDefaultConfig(asrc_context_config_t *config,
315                                   uint32_t channels,
316                                   uint32_t inSampleRate,
317                                   uint32_t outSampleRate);
318 
319 /*!
320  * @brief ASRC configure context.
321  *
322  * @param base ASRC base pointer.
323  * @param context index of asrc context, reference asrc_context_t.
324  * @param config ASRC context configuration pointer.
325  * @retval kStatus_InvalidArgument invalid parameters.
326  *        kStatus_ASRCConfigureFailed context configure failed.
327  *        kStatus_Success context configure success.
328  */
329 status_t ASRC_SetContextConfig(ASRC_Type *base, asrc_context_t context, asrc_context_config_t *config);
330 
331 /*!
332  * @brief ASRC configure context output.
333  *
334  * @param base ASRC base pointer.
335  * @param context index of asrc context, reference asrc_context_t.
336  * @param config ASRC context output configuration pointer.
337  */
338 status_t ASRC_SetContextOutputConfig(ASRC_Type *base, asrc_context_t context, asrc_context_output_config_t *config);
339 
340 /*!
341  * @brief ASRC configure context input.
342  *
343  * @param base ASRC base pointer.
344  * @param context index of asrc context, reference asrc_context_t.
345  * @param config ASRC context input configuration pointer.
346  */
347 status_t ASRC_SetContextInputConfig(ASRC_Type *base, asrc_context_t context, asrc_context_input_config_t *config);
348 
349 /*!
350  * @brief ASRC context enable run.
351  * All control fileds associated with a context must be stable prior to setting context run enable.
352  *
353  * @param base ASRC base pointer.
354  * @param context ASRC context index.
355  * @param enable true is enable, inform the datapath begin processing sample data for the context.
356  *               false is disable, data processing will halt immediately.
357  */
ASRC_EnableContextRun(ASRC_Type * base,asrc_context_t context,bool enable)358 static inline void ASRC_EnableContextRun(ASRC_Type *base, asrc_context_t context, bool enable)
359 {
360     if (enable)
361     {
362         base->CTX_CTRL[context] |= ASRC_CTX_CTRL_RUN_EN_MASK;
363     }
364     else
365     {
366         base->CTX_CTRL[context] &= ~ASRC_CTX_CTRL_RUN_EN_MASK;
367     }
368 }
369 
370 /*!
371  * @brief ASRC context enable run stop.
372  * This function used to flush the ASRC pipeline and completely end processing for a context.
373  *
374  * @param base ASRC base pointer.
375  * @param context ASRC context index.
376  * @param enable true is enable, false is disable.
377  */
ASRC_EnableContextRunStop(ASRC_Type * base,asrc_context_t context,bool enable)378 static inline void ASRC_EnableContextRunStop(ASRC_Type *base, asrc_context_t context, bool enable)
379 {
380     if (enable)
381     {
382         base->CTX_CTRL[context] |= ASRC_CTX_CTRL_RUN_STOP_MASK;
383     }
384     else
385     {
386         base->CTX_CTRL[context] &= ~ASRC_CTX_CTRL_RUN_STOP_MASK;
387     }
388 }
389 
390 /*!
391  * @brief ASRC context input DMA request enable.
392  *
393  * @param base ASRC base pointer.
394  * @param context ASRC context index.
395  * @param enable true is enable, false is disable.
396  */
ASRC_EnableContextInDMA(ASRC_Type * base,asrc_context_t context,bool enable)397 static inline void ASRC_EnableContextInDMA(ASRC_Type *base, asrc_context_t context, bool enable)
398 {
399     if (enable)
400     {
401         base->CTX_CTRL[context] |= ASRC_CTX_CTRL_FWMDE_MASK;
402     }
403     else
404     {
405         base->CTX_CTRL[context] &= ~ASRC_CTX_CTRL_FWMDE_MASK;
406     }
407 }
408 
409 /*!
410  * @brief ASRC context output DMA request enable.
411  *
412  * @param base ASRC base pointer.
413  * @param context ASRC context index.
414  * @param enable true is enable, false is disable.
415  */
ASRC_EnableContextOutDMA(ASRC_Type * base,asrc_context_t context,bool enable)416 static inline void ASRC_EnableContextOutDMA(ASRC_Type *base, asrc_context_t context, bool enable)
417 {
418     if (enable)
419     {
420         base->CTX_OUT_CTRL[context] |= ASRC_CTX_OUT_CTRL_FWMDE_MASK;
421     }
422     else
423     {
424         base->CTX_OUT_CTRL[context] &= ~ASRC_CTX_OUT_CTRL_FWMDE_MASK;
425     }
426 }
427 
428 /*!
429  * @brief ASRC prefilter bypass mode
430  * This function enable or disable the ASRC prefilter bypass mode.
431  *
432  * @param base ASRC peripheral base address.
433  * @param context context processor number.
434  * @param bypass true is bypass, false is normal mode.
435  */
ASRC_EnablePreFilterBypass(ASRC_Type * base,asrc_context_t context,bool bypass)436 static inline void ASRC_EnablePreFilterBypass(ASRC_Type *base, asrc_context_t context, bool bypass)
437 {
438     if (bypass)
439     {
440         base->CTX_CTRL_EXT1[context] |= ASRC_CTX_CTRL_EXT1_PF_BYPASS_MODE_MASK;
441         base->CTX_CTRL_EXT1[context] &= ~ASRC_CTX_CTRL_EXT1_PF_EXPANSION_FACTOR_MASK;
442         base->CTX_CTRL_EXT2[context] &= ~ASRC_CTX_CTRL_EXT2_ST1_NUM_TAPS_MASK;
443     }
444     else
445     {
446         base->CTX_CTRL_EXT1[context] &= ~ASRC_CTX_CTRL_EXT1_PF_BYPASS_MODE_MASK;
447     }
448 }
449 
450 /*!
451  * @brief ASRC resampler bypass mode
452  * This function enable or disable the ASRC resampler bypass mode.
453  *
454  * @param base ASRC peripheral base address.
455  * @param context context processor number.
456  * @param bypass true is bypass, false is normal mode.
457  */
ASRC_EnableResamplerBypass(ASRC_Type * base,asrc_context_t context,bool bypass)458 static inline void ASRC_EnableResamplerBypass(ASRC_Type *base, asrc_context_t context, bool bypass)
459 {
460     if (bypass)
461     {
462         base->CTX_CTRL_EXT1[context] |= ASRC_CTX_CTRL_EXT1_RS_BYPASS_MODE_MASK;
463     }
464     else
465     {
466         base->CTX_CTRL_EXT1[context] &= ~ASRC_CTX_CTRL_EXT1_RS_BYPASS_MODE_MASK;
467     }
468 }
469 
470 /*!
471  * @brief ASRC set context channel number.
472  * Note: The maximum channel number in one context can not exceed 32.
473  *
474  * @param base ASRC peripheral base address.
475  * @param context context  number.
476  * @param channels channel number, should <= 32.
477  */
ASRC_SetContextChannelNumber(ASRC_Type * base,asrc_context_t context,uint32_t channels)478 static inline void ASRC_SetContextChannelNumber(ASRC_Type *base, asrc_context_t context, uint32_t channels)
479 {
480     base->CTX_CTRL[context] &= ~ASRC_CTX_CTRL_NUM_CH_EN_MASK;
481     base->CTX_CTRL[context] |= ASRC_CTX_CTRL_NUM_CH_EN(channels - 1U);
482 }
483 
484 /*!
485  * @brief ASRC get output sample count.
486  *
487  * @param inSampleRate output sample rate.
488  * @param inSamplesSize input sample rate.
489  * @param inWidth input samples buffer size, the size of buffer should be converted to align with 4 byte .
490  * @param outSampleRate input sample width.
491  * @param outWidth Output width.
492  * @retval output samples size.
493  */
494 uint32_t ASRC_GetContextOutSampleSize(
495     uint32_t inSampleRate, uint32_t inSamplesSize, uint32_t inWidth, uint32_t outSampleRate, uint32_t outWidth);
496 
497 /*! @} */
498 
499 /*!
500  * @name Interrupts
501  * @{
502  */
503 
504 /*!
505  * @brief ASRC interrupt enable
506  * This function enable the ASRC interrupt with the provided mask.
507  *
508  * @param base ASRC peripheral base address.
509  * @param mask The interrupts to enable. Logical OR of _asrc_interrupt_mask.
510  */
ASRC_EnableInterrupt(ASRC_Type * base,uint32_t mask)511 static inline void ASRC_EnableInterrupt(ASRC_Type *base, uint32_t mask)
512 {
513     base->IRQ_CTRL &= ~mask;
514 }
515 
516 /*!
517  * @brief ASRC interrupt disable
518  * This function disable the ASRC interrupt with the provided mask.
519  *
520  * @param base ASRC peripheral base address.
521  * @param mask The interrupts to disable. Logical OR of _asrc_interrupt_mask.
522  */
ASRC_DisableInterrupt(ASRC_Type * base,uint32_t mask)523 static inline void ASRC_DisableInterrupt(ASRC_Type *base, uint32_t mask)
524 {
525     base->IRQ_CTRL |= mask;
526 }
527 /*! @} */
528 
529 /*!
530  * @name Status
531  * @{
532  */
533 
534 /*!
535  * @brief Gets the ASRC interrupt status flag state.
536  *
537  * @param base ASRC base pointer
538  * @return ASRC Tx status flag value. Use the Status Mask to get the status value needed.
539  */
ASRC_GetInterruptStatus(ASRC_Type * base)540 static inline uint32_t ASRC_GetInterruptStatus(ASRC_Type *base)
541 {
542     return base->IRQ_FLAGS;
543 }
544 
545 /*!
546  * @brief clear the ASRC interrupt status flag state.
547  *
548  * @param base ASRC base pointer
549  * @param status status flag to be cleared.
550  */
ASRC_ClearInterruptStatus(ASRC_Type * base,uint32_t status)551 static inline void ASRC_ClearInterruptStatus(ASRC_Type *base, uint32_t status)
552 {
553     base->IRQ_FLAGS |= status;
554 }
555 
556 /*!
557  * @brief Gets the ASRC fifo status flag.
558  *
559  * @param base ASRC base pointer
560  * @param context context id
561  */
ASRC_GetFifoStatus(ASRC_Type * base,asrc_context_t context)562 static inline uint32_t ASRC_GetFifoStatus(ASRC_Type *base, asrc_context_t context)
563 {
564     return (uint32_t)(base->SAMPLE_FIFO_STATUS[context] &
565                       (ASRC_SAMPLE_FIFO_STATUS_OUTFIFO_WTMK_MASK | ASRC_SAMPLE_FIFO_STATUS_INFIFO_WTMK_MASK));
566 }
567 
568 /*! @} */
569 
570 /*!
571  * @name fifo Operations
572  * @{
573  */
574 /*!
575  * @brief write the ASRC context fifo.
576  *
577  * @param base ASRC base pointer.
578  * @param context context id.
579  * @param data data to write.
580  */
ASRC_WriteContextFifo(ASRC_Type * base,asrc_context_t context,uint32_t data)581 static inline void ASRC_WriteContextFifo(ASRC_Type *base, asrc_context_t context, uint32_t data)
582 {
583     base->WRFIFO[context] = data;
584 }
585 
586 /*!
587  * @brief read the ASRC context fifo.
588  *
589  * @param base ASRC base pointer.
590  * @param context context id.
591  * @retval read data.
592  */
ASRC_ReadContextFifo(ASRC_Type * base,asrc_context_t context)593 static inline uint32_t ASRC_ReadContextFifo(ASRC_Type *base, asrc_context_t context)
594 {
595     return base->RDFIFO[context];
596 }
597 
598 /*!
599  * @brief Get ASRC write fifo address.
600  *
601  * @param base ASRC base pointer.
602  * @param context context id.
603  * @retval write fifo address.
604  */
ASRC_GetWriteContextFifoAddr(ASRC_Type * base,asrc_context_t context)605 static inline uint32_t ASRC_GetWriteContextFifoAddr(ASRC_Type *base, asrc_context_t context)
606 {
607     return (uint32_t)&base->WRFIFO[context];
608 }
609 
610 /*!
611  * @brief Get the ASRC read context fifo address.
612  *
613  * @param base ASRC base pointer.
614  * @param context context id.
615  * @retval read fifo address.
616  */
ASRC_GetReadContextFifoAddr(ASRC_Type * base,asrc_context_t context)617 static inline uint32_t ASRC_GetReadContextFifoAddr(ASRC_Type *base, asrc_context_t context)
618 {
619     return (uint32_t)&base->RDFIFO[context];
620 }
621 
622 /*!
623  * @brief Get the ASRC read fifo remained samples.
624  * Since the DMA request will be triggered only when the sample group in read fifo is bigger then the watermark, so when
625  * the data size cannot be divisible by the (watermark + 1), then part of sample will left in read fifo, application
626  * should call this api to get the left samples.
627  *
628  * @param base ASRC base pointer.
629  * @param context context id.
630  * @param outAddr address to receive remained sample in read fifo.
631  * @param outWidth output data width.
632  * @param sampleCount specify the read sample count.
633  * @retval sample counts actual read from output fifo.
634  */
635 uint32_t ASRC_ReadFIFORemainedSample(
636     ASRC_Type *base, asrc_context_t context, uint32_t *outAddr, uint32_t outWidth, uint32_t sampleCount);
637 
638 /*! @} */
639 
640 /*!
641  * @name Transactional
642  * @{
643  */
644 
645 /*!
646  * @brief ASRC blocking convert audio sample rate.
647  * This function depends on the configuration of input and output, so it should be called after the
648  * ASRC_SetContextConfig. The data format it supports:
649  * 1.16bit 16bit per sample in input buffer, input buffer size
650  * should be calculate as: samples 2U output buffer size can be calculated by call function
651  * ASRC_GetContextOutSampleSize, the parameter outWidth should be 2
652  * 2.20bit 24bit per sample in input buffer, input buffer size should be calculate as: samples 3U output buffer size can
653  * be calculated by call function ASRC_GetContextOutSampleSize, the outWidth should be 3. 3.24bit 24bit per sample in
654  * input buffer, input buffer size should be calculate as: samples * 3U output buffer size can be calculated by call
655  * function ASRC_GetContextOutSampleSize, the outWidth should be 3. 4.32bit 32bit per sample in input buffer, input
656  * buffer size should be calculate as: samples * 4U output buffer size can be calculated by call function
657  * ASRC_GetContextOutSampleSize, the outWidth should be 4.
658  *
659  * @param base ASRC base pointer.
660  * @param context context id.
661  * @param xfer .xfer configuration.
662  * @retval kStatus_Success.
663  */
664 status_t ASRC_TransferBlocking(ASRC_Type *base, asrc_context_t context, asrc_transfer_t *xfer);
665 
666 /*! @} */
667 
668 #if defined(__cplusplus)
669 }
670 #endif /*_cplusplus*/
671 
672 /*! @} */
673 
674 #endif /* _FSL_ASRC_H_ */
675