fsl_asrc.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * Copyright 2019-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_ASRC_H_
  8. #define _FSL_ASRC_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup asrc_driver
  12. * @{
  13. */
  14. /*******************************************************************************
  15. * Definitions
  16. ******************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. #define FSL_ASRC_DRIVER_VERSION (MAKE_VERSION(2, 1, 2)) /*!< Version 2.1.2 */
  20. /*@}*/
  21. #ifndef ASRC_XFER_QUEUE_SIZE
  22. /*!@brief ASRC transfer queue size, user can refine it according to use case. */
  23. #define ASRC_XFER_QUEUE_SIZE (4U)
  24. #endif
  25. /*!@brief ASRC channel pair count */
  26. #define FSL_ASRC_CHANNEL_PAIR_COUNT (4U)
  27. /*! @brief ASRC FIFO depth */
  28. #define FSL_ASRC_CHANNEL_PAIR_FIFO_DEPTH (64U)
  29. /*! @brief ASRC register access macro */
  30. #define ASRC_ASRCTR_AT_MASK(index) ((uint32_t)1U << (ASRC_ASRCTR_ATSA_SHIFT + (uint32_t)(index)))
  31. #define ASRC_ASRCTR_RATIO_MASK(index) ((uint32_t)3U << (ASRC_ASRCTR_IDRA_SHIFT + (uint32_t)(index)*2U))
  32. #define ASRC_ASRCTR_RATIO(ratio, index) \
  33. (((uint32_t)((uint32_t)(ratio) << (ASRC_ASRCTR_IDRA_SHIFT + (uint32_t)(index)*2U))) & ASRC_ASRCTR_RATIO_MASK(index))
  34. #define ASRC_ASRIER_INPUT_INTERRUPT_MASK(index) ((uint32_t)1U << (ASRC_ASRIER_ADIEA_SHIFT + (uint32_t)(index)))
  35. #define ASRC_ASRIER_OUTPUTPUT_INTERRUPT_MASK(index) ((uint32_t)1U << (ASRC_ASRIER_ADOEA_SHIFT + (uint32_t)(index)))
  36. #define ASRC_ASRCNCR_CHANNEL_COUNTER_MASK(index) ((uint32_t)0xFU << (ASRC_ASRCNCR_ANCA_SHIFT + (uint32_t)(index)*4U))
  37. #define ASRC_ASRCNCR_CHANNEL_COUNTER(counter, index) \
  38. ((uint32_t)((uint32_t)(counter) << (ASRC_ASRCNCR_ANCA_SHIFT + (uint32_t)(index)*4U)) & \
  39. ASRC_ASRCNCR_CHANNEL_COUNTER_MASK(index))
  40. #define ASRC_ASRCFG_PRE_MODE_MASK(index) ((uint32_t)3U << (ASRC_ASRCFG_PREMODA_SHIFT + (uint32_t)(index)*4U))
  41. #define ASRC_ASRCFG_PRE_MODE(mode, index) \
  42. ((uint32_t)((uint32_t)(mode) << (ASRC_ASRCFG_PREMODA_SHIFT + (uint32_t)(index)*4U)) & \
  43. ASRC_ASRCFG_PRE_MODE_MASK(index))
  44. #define ASRC_ASRCFG_POST_MODE_MASK(index) ((uint32_t)3U << (ASRC_ASRCFG_POSTMODA_SHIFT + (uint32_t)(index)*4U))
  45. #define ASRC_ASRCFG_POST_MODE(mode, index) \
  46. ((uint32_t)((uint32_t)(mode) << (ASRC_ASRCFG_POSTMODA_SHIFT + (uint32_t)(index)*4U)) & \
  47. ASRC_ASRCFG_POST_MODE_MASK(index))
  48. #define ASRC_ASRCFG_INIT_DONE_MASK(index) ((uint32_t)1U << (ASRC_ASRCFG_INIRQA_SHIFT + (uint32_t)(index)))
  49. #define ASRC_ASRCSR_INPUT_CLOCK_SOURCE_MASK(index) ((uint32_t)0xFU << (ASRC_ASRCSR_AICSA_SHIFT + (uint32_t)(index)*4U))
  50. #define ASRC_ASRCSR_INPUT_CLOCK_SOURCE(source, index) \
  51. ((uint32_t)((uint32_t)(source) << (ASRC_ASRCSR_AICSA_SHIFT + (uint32_t)(index)*4U)) & \
  52. ASRC_ASRCSR_INPUT_CLOCK_SOURCE_MASK(index))
  53. #define ASRC_ASRCSR_OUTPUT_CLOCK_SOURCE_MASK(index) ((uint32_t)0xFU << (ASRC_ASRCSR_AOCSA_SHIFT + (uint32_t)(index)*4U))
  54. #define ASRC_ASRCSR_OUTPUT_CLOCK_SOURCE(source, index) \
  55. ((uint32_t)((uint32_t)(source) << (ASRC_ASRCSR_AOCSA_SHIFT + (uint32_t)(index)*4U)) & \
  56. ASRC_ASRCSR_OUTPUT_CLOCK_SOURCE_MASK(index))
  57. #define ASRC_ASRCDR_INPUT_PRESCALER_MASK(index) \
  58. ((uint32_t)(index) < 2U ? ((uint32_t)7U << (ASRC_ASRCDR1_AICPA_SHIFT + (uint32_t)(index)*6U)) : 7U)
  59. #define ASRC_ASRCDR_INPUT_PRESCALER(prescaler, index) \
  60. (((index) < 2U ? ((uint32_t)(prescaler) << (ASRC_ASRCDR1_AICPA_SHIFT + (uint32_t)(index)*6U)) : (prescaler)) & \
  61. ASRC_ASRCDR1_INPUT_PRESCALER_MASK(index))
  62. #define ASRC_ASRCDR_INPUT_DIVIDER_MASK(index) \
  63. ((uint32_t)(index) < 2U ? ((uint32_t)7U << (ASRC_ASRCDR1_AICDA_SHIFT + (uint32_t)(index)*6U)) : \
  64. (7U << ASRC_ASRCDR1_AICDA_SHIFT))
  65. #define ASRC_ASRCDR_INPUT_DIVIDER(divider, index) \
  66. (((uint32_t)(index) < 2U ? ((uint32_t)(divider) << (ASRC_ASRCDR1_AICDA_SHIFT + (uint32_t)(index)*6U)) : \
  67. ((uint32_t)(divider) << ASRC_ASRCDR1_AICDA_SHIFT)) & \
  68. ASRC_ASRCDR_INPUT_DIVIDER_MASK(index))
  69. #define ASRC_ASRCDR_OUTPUT_PRESCALER_MASK(index) \
  70. ((uint32_t)(index) < 2U ? ((uint32_t)7U << (ASRC_ASRCDR1_AOCPA_SHIFT + (uint32_t)(index)*6U)) : (7U << 6U))
  71. #define ASRC_ASRCDR_OUTPUT_PRESCALER(prescaler, index) \
  72. (((uint32_t)(index) < 2U ? ((uint32_t)(prescaler) << (ASRC_ASRCDR1_AOCPA_SHIFT + (uint32_t)(index)*6U)) : \
  73. ((uint32_t)(prescaler) << 6U)) & \
  74. ASRC_ASRCDR_OUTPUT_PRESCALER_MASK(index))
  75. #define ASRC_ASRCDR_OUTPUT_DIVIDER_MASK(index) \
  76. ((uint32_t)(index) < 2U ? ((uint32_t)7U << (ASRC_ASRCDR1_AOCDA_SHIFT + (uint32_t)(index)*6U)) : (7UL << 9U))
  77. #define ASRC_ASRCDR_OUTPUT_DIVIDER(divider, index) \
  78. (((uint32_t)(index) < 2U ? ((uint32_t)(divider) << (ASRC_ASRCDR1_AOCDA_SHIFT + (uint32_t)(index)*6U)) : \
  79. ((uint32_t)(divider) << 9U)) & \
  80. ASRC_ASRCDR_OUTPUT_DIVIDER_MASK(index))
  81. #define ASCR_ASRCDR_OUTPUT_CLOCK_DIVIDER_PRESCALER(value, index) \
  82. (((uint32_t)(index) < 2U ? ((uint32_t)(value) << (ASRC_ASRCDR1_AOCPA_SHIFT + (uint32_t)(index)*6U)) : \
  83. ((uint32_t)(value) << 6U)))
  84. #define ASCR_ASRCDR_INPUT_CLOCK_DIVIDER_PRESCALER(value, index) \
  85. (((uint32_t)(index) < 2U ? ((uint32_t)(value) << ((uint32_t)(index)*6U)) : ((uint32_t)(value))))
  86. #define ASRC_IDEAL_RATIO_HIGH(base, index) *(volatile uint32_t *)((uint32_t)(&(base)->ASRIDRHA) + (uint32_t)(index)*8U)
  87. #define ASRC_IDEAL_RATIO_LOW(base, index) *(volatile uint32_t *)((uint32_t)(&(base)->ASRIDRLA) + (uint32_t)(index)*8U)
  88. #define ASRC_ASRMCR(base, index) *(volatile uint32_t *)((uint32_t)(&(base)->ASRMCRA) + (uint32_t)(index)*8U)
  89. #define ASRC_ASRMCR1(base, index) *(volatile uint32_t *)((uint32_t)(&((base)->ASRMCR1[(index)])))
  90. #define ASRC_ASRDI(base, index) *(volatile uint32_t *)((uint32_t)(&(base)->ASRDIA) + (uint32_t)(index)*8U)
  91. #define ASRC_ASRDO(base, index) *(volatile uint32_t *)((uint32_t)(&(base)->ASRDOA) + (uint32_t)(index)*8U)
  92. #define ASRC_ASRDI_ADDR(base, index) (volatile uint32_t *)((uint32_t)(&(base)->ASRDIA) + (uint32_t)(index)*8U)
  93. #define ASRC_ASRDO_ADDR(base, index) (volatile uint32_t *)((uint32_t)(&(base)->ASRDOA) + (uint32_t)(index)*8U)
  94. #define ASRC_ASRFST_ADDR(base, index) (*(volatile uint32_t *)((uint32_t)(&(base)->ASRFSTA) + (uint32_t)(index)*8U))
  95. #define ASRC_GET_CHANNEL_COUNTER(base, index) (((base)->ASRCNCR >> ((uint32_t)(index)*4U)) & 0xFU)
  96. /*! @brief ASRC return status
  97. * @anchor _asrc_status_t
  98. */
  99. enum
  100. {
  101. kStatus_ASRCIdle = MAKE_STATUS(kStatusGroup_ASRC, 0), /*!< ASRC is idle. */
  102. kStatus_ASRCInIdle = MAKE_STATUS(kStatusGroup_ASRC, 1), /*!< ASRC in is idle. */
  103. kStatus_ASRCOutIdle = MAKE_STATUS(kStatusGroup_ASRC, 2), /*!< ASRC out is idle. */
  104. kStatus_ASRCBusy = MAKE_STATUS(kStatusGroup_ASRC, 3), /*!< ASRC is busy. */
  105. kStatus_ASRCInvalidArgument = MAKE_STATUS(kStatusGroup_ASRC, 4), /*!< ASRC invalid argument. */
  106. kStatus_ASRCClockConfigureFailed = MAKE_STATUS(kStatusGroup_ASRC, 5), /*!< ASRC clock configure failed */
  107. kStatus_ASRCChannelPairConfigureFailed = MAKE_STATUS(kStatusGroup_ASRC, 6), /*!< ASRC clock configure failed */
  108. kStatus_ASRCConvertError = MAKE_STATUS(kStatusGroup_ASRC, 7), /*!< ASRC clock configure failed */
  109. kStatus_ASRCNotSupport = MAKE_STATUS(kStatusGroup_ASRC, 8), /*!< ASRC not support */
  110. kStatus_ASRCQueueFull = MAKE_STATUS(kStatusGroup_ASRC, 9), /*!< ASRC queue is full */
  111. kStatus_ASRCOutQueueIdle = MAKE_STATUS(kStatusGroup_ASRC, 10), /*!< ASRC out queue is idle */
  112. kStatus_ASRCInQueueIdle = MAKE_STATUS(kStatusGroup_ASRC, 11), /*!< ASRC in queue is idle */
  113. };
  114. /*! @brief ASRC channel pair mask */
  115. typedef enum _asrc_channel_pair
  116. {
  117. kASRC_ChannelPairA = 0, /*!< channel pair A value */
  118. kASRC_ChannelPairB = 1, /*!< channel pair B value */
  119. kASRC_ChannelPairC = 2, /*!< channel pair C value */
  120. } asrc_channel_pair_t;
  121. /*! @brief ASRC support sample rate
  122. * @anchor _asrc_sample_rate
  123. */
  124. enum
  125. {
  126. kASRC_SampleRate_8000HZ = 8000U, /*!< asrc sample rate 8KHZ */
  127. kASRC_SampleRate_11025HZ = 11025U, /*!< asrc sample rate 11.025KHZ */
  128. kASRC_SampleRate_12000HZ = 12000U, /*!< asrc sample rate 12KHZ */
  129. kASRC_SampleRate_16000HZ = 16000U, /*!< asrc sample rate 16KHZ */
  130. kASRC_SampleRate_22050HZ = 22050U, /*!< asrc sample rate 22.05KHZ */
  131. kASRC_SampleRate_24000HZ = 24000U, /*!< asrc sample rate 24KHZ */
  132. kASRC_SampleRate_30000HZ = 30000U, /*!< asrc sample rate 30KHZ */
  133. kASRC_SampleRate_32000HZ = 32000U, /*!< asrc sample rate 32KHZ */
  134. kASRC_SampleRate_44100HZ = 44100U, /*!< asrc sample rate 44.1KHZ */
  135. kASRC_SampleRate_48000HZ = 48000U, /*!< asrc sample rate 48KHZ */
  136. kASRC_SampleRate_64000HZ = 64000U, /*!< asrc sample rate 64KHZ */
  137. kASRC_SampleRate_88200HZ = 88200U, /*!< asrc sample rate 88.2KHZ */
  138. kASRC_SampleRate_96000HZ = 96000U, /*!< asrc sample rate 96KHZ */
  139. kASRC_SampleRate_128000HZ = 128000U, /*!< asrc sample rate 128KHZ */
  140. kASRC_SampleRate_176400HZ = 176400U, /*!< asrc sample rate 176.4KHZ */
  141. kASRC_SampleRate_192000HZ = 192000U, /*!< asrc sample rate 192KHZ */
  142. };
  143. /*! @brief The ASRC interrupt enable flag
  144. * @anchor _asrc_interrupt_mask
  145. */
  146. enum
  147. {
  148. kASRC_FPInWaitStateInterruptEnable = ASRC_ASRIER_AFPWE_MASK, /*!< FP in wait state mask */
  149. kASRC_OverLoadInterruptMask = ASRC_ASRIER_AOLIE_MASK, /*!< overload interrupt mask */
  150. kASRC_DataOutputCInterruptMask = ASRC_ASRIER_ADOEC_MASK, /*!< data output c interrupt mask */
  151. kASRC_DataOutputBInterruptMask = ASRC_ASRIER_ADOEB_MASK, /*!< data output b interrupt mask */
  152. kASRC_DataOutputAInterruptMask = ASRC_ASRIER_ADOEA_MASK, /*!< data output a interrupt mask */
  153. kASRC_DataInputCInterruptMask = ASRC_ASRIER_ADIEC_MASK, /*!< data input c interrupt mask */
  154. kASRC_DataInputBInterruptMask = ASRC_ASRIER_ADIEB_MASK, /*!< data input b interrupt mask */
  155. kASRC_DataInputAInterruptMask = ASRC_ASRIER_ADIEA_MASK, /*!< data input a interrupt mask */
  156. };
  157. /*! @brief The ASRC interrupt status
  158. * @anchor _asrc_interrupt_status
  159. */
  160. enum
  161. {
  162. kASRC_StatusDSLCounterReady = ASRC_ASRSTR_DSLCNT_MASK, /*!< DSL counter */
  163. kASRC_StatusTaskQueueOverLoad = ASRC_ASRSTR_ATQOL_MASK, /*!< task queue overload */
  164. kASRC_StatusPairCOutputOverLoad = ASRC_ASRSTR_AOOLC_MASK, /*!< pair c output overload */
  165. kASRC_StatusPairBOutputOverLoad = ASRC_ASRSTR_AOOLB_MASK, /*!< pair b output overload */
  166. kASRC_StatusPairAOutputOverLoad = ASRC_ASRSTR_AOOLA_MASK, /*!< pair a output overload */
  167. kASRC_StatusPairCInputOverLoad = ASRC_ASRSTR_AIOLC_MASK, /*!< pair c input overload */
  168. kASRC_StatusPairBInputOverLoad = ASRC_ASRSTR_AIOLB_MASK, /*!<pair b input overload */
  169. kASRC_StatusPairAInputOverLoad = ASRC_ASRSTR_AIOLA_MASK, /*!< pair a input overload */
  170. kASRC_StatusPairCOutputOverflow = ASRC_ASRSTR_AODOC_MASK, /*!< pair c output overflow */
  171. kASRC_StatusPairBOutputOverflow = ASRC_ASRSTR_AODOB_MASK, /*!< pair b output overflow */
  172. kASRC_StatusPairAOutputOverflow = ASRC_ASRSTR_AODOA_MASK, /*!< pair a output overflow */
  173. kASRC_StatusPairCInputUnderflow = ASRC_ASRSTR_AIDUC_MASK, /*!< pair c input underflow*/
  174. kASRC_StatusPairBInputUnderflow = ASRC_ASRSTR_AIDUB_MASK, /*!< pair b input under flow */
  175. kASRC_StatusPairAInputUnderflow = ASRC_ASRSTR_AIDUA_MASK, /*!< pair a input underflow*/
  176. kASRC_StatusFPInWaitState = ASRC_ASRSTR_FPWT_MASK, /*!< FP in wait state */
  177. kASRC_StatusOverloadError = ASRC_ASRSTR_AOLE_MASK, /*!< overload error */
  178. kASRC_StatusInputError = kASRC_StatusPairCInputOverLoad | kASRC_StatusPairBInputOverLoad |
  179. kASRC_StatusPairAInputOverLoad | kASRC_StatusPairCInputUnderflow |
  180. kASRC_StatusPairBInputUnderflow |
  181. kASRC_StatusPairAInputUnderflow, /*!< input error status */
  182. kASRC_StatusOutputError = kASRC_StatusPairCOutputOverLoad | kASRC_StatusPairBOutputOverLoad |
  183. kASRC_StatusPairAOutputOverLoad | kASRC_StatusPairCOutputOverflow |
  184. kASRC_StatusPairBOutputOverflow |
  185. kASRC_StatusPairAOutputOverflow, /*!< output error status */
  186. kASRC_StatusPairCOutputReady = ASRC_ASRSTR_AODFC_MASK, /*!< pair c output ready */
  187. kASRC_StatusPairBOutputReady = ASRC_ASRSTR_AODFB_MASK, /*!< pair b output ready */
  188. kASRC_StatusPairAOutputReady = ASRC_ASRSTR_AODFA_MASK, /*!< pair a output ready */
  189. kASRC_StatusPairCInputReady = ASRC_ASRSTR_AIDEC_MASK, /*!< pair c input ready */
  190. kASRC_StatusPairBInputReady = ASRC_ASRSTR_AIDEB_MASK, /*!< pair b input ready */
  191. kASRC_StatusPairAInputReady = ASRC_ASRSTR_AIDEA_MASK, /*!< pair a input ready */
  192. kASRC_StatusPairAInterrupt = kASRC_StatusPairAInputReady | kASRC_StatusPairAOutputReady, /*!< pair A interrupt */
  193. kASRC_StatusPairBInterrupt = kASRC_StatusPairBInputReady | kASRC_StatusPairBOutputReady, /*!< pair B interrupt */
  194. kASRC_StatusPairCInterrupt = kASRC_StatusPairCInputReady | kASRC_StatusPairCOutputReady, /*!< pair C interrupt */
  195. };
  196. /*! @brief ASRC channel pair status
  197. * @anchor _asrc_channel_pair_status
  198. */
  199. enum
  200. {
  201. kASRC_OutputFifoNearFull = ASRC_ASRFSTA_OAFA_MASK, /*!< channel pair output fifo near full */
  202. kASRC_InputFifoNearEmpty = ASRC_ASRFSTA_IAEA_MASK, /*!< channel pair input fifo near empty */
  203. };
  204. /*! @brief ASRC ideal ratio */
  205. typedef enum _asrc_ratio
  206. {
  207. kASRC_RatioNotUsed = 0U, /*!< ideal ratio not used */
  208. kASRC_RatioUseInternalMeasured =
  209. 2U, /*!< ideal ratio use internal measure ratio, can be used for real time streaming audio */
  210. kASRC_RatioUseIdealRatio =
  211. 3U, /*!< ideal ratio use manual configure ratio, can be used for the non-real time streaming audio */
  212. } asrc_ratio_t;
  213. /*! @brief Number of channels in audio data */
  214. typedef enum _asrc_audio_channel
  215. {
  216. kASRC_ChannelsNumber1 = 1U, /*!< channel number is 1 */
  217. kASRC_ChannelsNumber2 = 2U, /*!< channel number is 2 */
  218. kASRC_ChannelsNumber3 = 3U, /*!< channel number is 3 */
  219. kASRC_ChannelsNumber4 = 4U, /*!< channel number is 4 */
  220. kASRC_ChannelsNumber5 = 5U, /*!< channel number is 5 */
  221. kASRC_ChannelsNumber6 = 6U, /*!< channel number is 6 */
  222. kASRC_ChannelsNumber7 = 7U, /*!< channel number is 7 */
  223. kASRC_ChannelsNumber8 = 8U, /*!< channel number is 8 */
  224. kASRC_ChannelsNumber9 = 9U, /*!< channel number is 9 */
  225. kASRC_ChannelsNumber10 = 10U, /*!< channel number is 10 */
  226. } asrc_audio_channel_t;
  227. /*! @brief data width */
  228. typedef enum _asrc_data_width
  229. {
  230. kASRC_DataWidth24Bit = 0U, /*!< data width 24bit */
  231. kASRC_DataWidth16Bit = 1U, /*!< data width 16bit */
  232. kASRC_DataWidth8Bit = 2U, /*!< data width 8bit */
  233. } asrc_data_width_t;
  234. /*! @brief data alignment */
  235. typedef enum _asrc_data_align
  236. {
  237. kASRC_DataAlignMSB = 1U, /*!< data alignment MSB */
  238. kASRC_DataAlignLSB = 0U, /*!< data alignment LSB */
  239. } asrc_data_align_t;
  240. /*! @brief sign extension */
  241. typedef enum _asrc_sign_extension
  242. {
  243. kASRC_NoSignExtension = 0U, /*!< no sign extension */
  244. kASRC_SignExtension = 1U, /*!< sign extension */
  245. } asrc_sign_extension_t;
  246. /*! @brief asrc channel pair configuation */
  247. typedef struct _asrc_channel_pair_config
  248. {
  249. asrc_audio_channel_t audioDataChannels; /*!< audio data channel numbers */
  250. asrc_clock_source_t
  251. inClockSource; /*!< input clock source, reference the clock source definition in SOC header file */
  252. uint32_t inSourceClock_Hz; /*!< input source clock frequency */
  253. asrc_clock_source_t
  254. outClockSource; /*!< output clock source, reference the clock source definition in SOC header file */
  255. uint32_t outSourceClock_Hz; /*!< output source clock frequency */
  256. asrc_ratio_t sampleRateRatio; /*!< sample rate ratio type */
  257. asrc_data_width_t inDataWidth; /*!< input data width */
  258. asrc_data_align_t inDataAlign; /*!< input data alignment */
  259. asrc_data_width_t outDataWidth; /*!< output data width */
  260. asrc_data_align_t outDataAlign; /*!< output data alignment */
  261. asrc_sign_extension_t outSignExtension; /*!< output extension */
  262. uint8_t outFifoThreshold; /*!< output fifo threshold */
  263. uint8_t inFifoThreshold; /*!< input fifo threshold */
  264. bool bufStallWhenFifoEmptyFull; /*!< stall Pair A conversion in case of Buffer near empty full condition */
  265. } asrc_channel_pair_config_t;
  266. /*! @brief SAI transfer structure */
  267. typedef struct _asrc_transfer
  268. {
  269. void *inData; /*!< Data address to convert.*/
  270. size_t inDataSize; /*!< input data size. */
  271. void *outData; /*!< Data address to store converted data */
  272. size_t outDataSize; /*!< output data size. */
  273. } asrc_transfer_t;
  274. /*! @brief asrc handler */
  275. typedef struct _asrc_handle asrc_handle_t;
  276. /*! @brief ASRC transfer callback prototype */
  277. typedef void (*asrc_transfer_callback_t)(ASRC_Type *base, asrc_handle_t *handle, status_t status, void *userData);
  278. /*! @brief asrc in handler */
  279. typedef struct _asrc_in_handle
  280. {
  281. asrc_transfer_callback_t callback; /*!< Callback function called at convert complete */
  282. uint32_t sampleWidth; /*!< data width */
  283. uint32_t sampleMask; /*!< data mask */
  284. uint32_t fifoThreshold; /*!< fifo threshold */
  285. uint8_t *asrcQueue[ASRC_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer */
  286. size_t transferSamples[ASRC_XFER_QUEUE_SIZE]; /*!< Data bytes need to convert */
  287. volatile uint8_t queueUser; /*!< Index for user to queue transfer */
  288. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  289. } asrc_in_handle_t;
  290. /*! @brief output handler */
  291. typedef struct _asrc_out_handle
  292. {
  293. asrc_transfer_callback_t callback; /*!< Callback function called at convert complete */
  294. uint32_t sampleWidth; /*!< data width */
  295. uint32_t fifoThreshold; /*!< fifo threshold */
  296. uint8_t *asrcQueue[ASRC_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer */
  297. size_t transferSamples[ASRC_XFER_QUEUE_SIZE]; /*!< Data bytes need to convert */
  298. volatile uint8_t queueUser; /*!< Index for user to queue transfer */
  299. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  300. } asrc_out_handle_t;
  301. /*! @brief ASRC handle structure */
  302. struct _asrc_handle
  303. {
  304. ASRC_Type *base; /*!< base address */
  305. uint32_t state; /*!< Transfer status */
  306. void *userData; /*!< Callback parameter passed to callback function*/
  307. asrc_audio_channel_t audioDataChannels; /*!< audio channel number */
  308. asrc_channel_pair_t channelPair; /*!< channel pair mask */
  309. asrc_in_handle_t in; /*!< asrc input handler */
  310. asrc_out_handle_t out; /*!< asrc output handler */
  311. };
  312. /*******************************************************************************
  313. * API
  314. ******************************************************************************/
  315. #if defined(__cplusplus)
  316. extern "C" {
  317. #endif /*_cplusplus*/
  318. /*!
  319. * @name Initialization and deinitialization
  320. * @{
  321. */
  322. /*!
  323. * @brief Get instance number of the ASRC peripheral.
  324. *
  325. * @param base ASRC base pointer.
  326. */
  327. uint32_t ASRC_GetInstance(ASRC_Type *base);
  328. /*!
  329. * brief Initializes the asrc peripheral.
  330. *
  331. * This API gates the asrc clock. The asrc module can't operate unless ASRC_Init is called to enable the clock.
  332. *
  333. * param base asrc base pointer.
  334. * param asrcPeripheralClock_Hz peripheral clock of ASRC.
  335. */
  336. void ASRC_Init(ASRC_Type *base, uint32_t asrcPeripheralClock_Hz);
  337. /*!
  338. * @brief De-initializes the ASRC peripheral.
  339. *
  340. * This API gates the ASRC clock and disable ASRC module. The ASRC module can't operate unless ASRC_Init
  341. *
  342. * @param base ASRC base pointer.
  343. */
  344. void ASRC_Deinit(ASRC_Type *base);
  345. /*!
  346. * @brief Do software reset .
  347. *
  348. * This software reset bit is self-clear bit, it will generate a software reset signal inside ASRC.
  349. * After 9 cycles of the ASRC processing clock, this reset process will stop and this bit will cleared
  350. * automatically.
  351. *
  352. * @param base ASRC base pointer
  353. */
  354. void ASRC_SoftwareReset(ASRC_Type *base);
  355. /*!
  356. * @brief ASRC configure channel pair.
  357. *
  358. * @param base ASRC base pointer.
  359. * @param channelPair index of channel pair, reference _asrc_channel_pair.
  360. * @param config ASRC channel pair configuration pointer.
  361. * @param inputSampleRate input audio data sample rate.
  362. * @param outputSampleRate output audio data sample rate.
  363. */
  364. status_t ASRC_SetChannelPairConfig(ASRC_Type *base,
  365. asrc_channel_pair_t channelPair,
  366. asrc_channel_pair_config_t *config,
  367. uint32_t inputSampleRate,
  368. uint32_t outputSampleRate);
  369. /*!
  370. * @brief Get output sample buffer size.
  371. *
  372. * @note This API is depends on the ASRC output configuration, should be called after the ASRC_SetChannelPairConfig.
  373. *
  374. * @param base asrc base pointer.
  375. * @param channelPair ASRC channel pair number.
  376. * @param inSampleRate input sample rate.
  377. * @param outSampleRate output sample rate.
  378. * @param inSamplesize input sampleS size.
  379. * @retval output buffer size in byte.
  380. */
  381. uint32_t ASRC_GetOutSamplesSize(ASRC_Type *base,
  382. asrc_channel_pair_t channelPair,
  383. uint32_t inSampleRate,
  384. uint32_t outSampleRate,
  385. uint32_t inSamplesize);
  386. /*!
  387. * @brief Map register sample width to real sample width.
  388. *
  389. * @note This API is depends on the ASRC configuration, should be called after the ASRC_SetChannelPairConfig.
  390. * @param base asrc base pointer.
  391. * @param channelPair asrc channel pair index.
  392. * @param inWidth ASRC channel pair number.
  393. * @param outWidth input sample rate.
  394. * @retval input sample mask value.
  395. */
  396. uint32_t ASRC_MapSamplesWidth(ASRC_Type *base, asrc_channel_pair_t channelPair, uint32_t *inWidth, uint32_t *outWidth);
  397. /*!
  398. * @brief Get left samples in fifo.
  399. *
  400. * @param base asrc base pointer.
  401. * @param channelPair ASRC channel pair number.
  402. * @param buffer input sample numbers.
  403. * @param outSampleWidth output sample width.
  404. * @param remainSamples output sample rate.
  405. * @retval remain samples number.
  406. */
  407. uint32_t ASRC_GetRemainFifoSamples(ASRC_Type *base,
  408. asrc_channel_pair_t channelPair,
  409. uint32_t *buffer,
  410. uint32_t outSampleWidth,
  411. uint32_t remainSamples);
  412. /*!
  413. * @brief ASRC module enable.
  414. *
  415. * @param base ASRC base pointer.
  416. * @param enable true is enable, false is disable
  417. */
  418. static inline void ASRC_ModuleEnable(ASRC_Type *base, bool enable)
  419. {
  420. if (enable)
  421. {
  422. base->ASRCTR |= ASRC_ASRCTR_ASRCEN_MASK;
  423. }
  424. else
  425. {
  426. base->ASRCTR &= ~ASRC_ASRCTR_ASRCEN_MASK;
  427. }
  428. }
  429. /*!
  430. * @brief ASRC enable channel pair.
  431. *
  432. * @param base ASRC base pointer.
  433. * @param channelPair channel pair mask value, reference _asrc_channel_pair_mask.
  434. * @param enable true is enable, false is disable.
  435. */
  436. static inline void ASRC_ChannelPairEnable(ASRC_Type *base, asrc_channel_pair_t channelPair, bool enable)
  437. {
  438. if (enable)
  439. {
  440. base->ASRCTR |= 1UL << ((uint32_t)channelPair + 1U);
  441. }
  442. else
  443. {
  444. base->ASRCTR &= ~(1UL << ((uint32_t)channelPair + 1U));
  445. }
  446. }
  447. /*! @} */
  448. /*!
  449. * @name Interrupts
  450. * @{
  451. */
  452. /*!
  453. * @brief ASRC interrupt enable
  454. * This function enable the ASRC interrupt with the provided mask.
  455. *
  456. * @param base ASRC peripheral base address.
  457. * @param mask The interrupts to enable. Logical OR of @ref _asrc_interrupt_mask.
  458. */
  459. static inline void ASRC_EnableInterrupt(ASRC_Type *base, uint32_t mask)
  460. {
  461. base->ASRIER |= mask;
  462. }
  463. /*!
  464. * @brief ASRC interrupt disable
  465. * This function disable the ASRC interrupt with the provided mask.
  466. *
  467. * @param base ASRC peripheral base address.
  468. * @param mask The interrupts to disable. Logical OR of @ref _asrc_interrupt_mask.
  469. */
  470. static inline void ASRC_DisableInterrupt(ASRC_Type *base, uint32_t mask)
  471. {
  472. base->ASRIER &= ~mask;
  473. }
  474. /*! @} */
  475. /*!
  476. * @name Status
  477. * @{
  478. */
  479. /*!
  480. * @brief Gets the ASRC status flag state.
  481. *
  482. * @param base ASRC base pointer
  483. * @return ASRC Tx status flag value. Use the Status Mask to get the status value needed.
  484. */
  485. static inline uint32_t ASRC_GetStatus(ASRC_Type *base)
  486. {
  487. return base->ASRSTR;
  488. }
  489. /*!
  490. * @brief Gets the ASRC channel pair initialization state.
  491. *
  492. * @param base ASRC base pointer
  493. * @param channel ASRC channel pair.
  494. * @return ASRC Tx status flag value. Use the Status Mask to get the status value needed.
  495. */
  496. static inline bool ASRC_GetChannelPairInitialStatus(ASRC_Type *base, asrc_channel_pair_t channel)
  497. {
  498. return ((base->ASRCFG >> ASRC_ASRCFG_INIRQA_SHIFT) & (1U << (uint32_t)channel)) == 0U ? false : true;
  499. }
  500. /*!
  501. * @brief Gets the ASRC channel A fifo a status flag state.
  502. *
  503. * @param base ASRC base pointer
  504. * @param channelPair ASRC channel pair.
  505. * @return ASRC channel pair a fifo status flag value. Use the Status Mask to get the status value needed.
  506. */
  507. static inline uint32_t ASRC_GetChannelPairFifoStatus(ASRC_Type *base, asrc_channel_pair_t channelPair)
  508. {
  509. return ASRC_ASRMCR(base, channelPair) & ((uint32_t)kASRC_OutputFifoNearFull | (uint32_t)kASRC_InputFifoNearEmpty);
  510. }
  511. /*! @} */
  512. /*!
  513. * @name Bus Operations
  514. * @{
  515. */
  516. /*!
  517. * @brief Writes data into ASRC channel pair FIFO.
  518. * Note: ASRC fifo width is 24bit.
  519. * @param base ASRC base pointer.
  520. * @param channelPair ASRC channel pair.
  521. * @param data Data needs to be written.
  522. */
  523. static inline void ASRC_ChannelPairWriteData(ASRC_Type *base, asrc_channel_pair_t channelPair, uint32_t data)
  524. {
  525. ASRC_ASRDI(base, channelPair) = data;
  526. }
  527. /*!
  528. * @brief Read data from ASRC channel pair FIFO.
  529. * Note: ASRC fifo width is 24bit.
  530. *
  531. * @param base ASRC base pointer.
  532. * @param channelPair ASRC channel pair.
  533. * @retval value read from fifo.
  534. */
  535. static inline uint32_t ASRC_ChannelPairReadData(ASRC_Type *base, asrc_channel_pair_t channelPair)
  536. {
  537. return ASRC_ASRDO(base, channelPair);
  538. }
  539. /*!
  540. * @brief Get input data fifo address.
  541. * Note: ASRC fifo width is 24bit.
  542. *
  543. * @param base ASRC base pointer.
  544. * @param channelPair ASRC channel pair.
  545. */
  546. static inline uint32_t ASRC_GetInputDataRegisterAddress(ASRC_Type *base, asrc_channel_pair_t channelPair)
  547. {
  548. return (uint32_t)ASRC_ASRDI_ADDR(base, channelPair);
  549. }
  550. /*!
  551. * @brief Get output data fifo address.
  552. * Note: ASRC fifo width is 24bit.
  553. *
  554. * @param base ASRC base pointer.
  555. * @param channelPair ASRC channel pair.
  556. */
  557. static inline uint32_t ASRC_GetOutputDataRegisterAddress(ASRC_Type *base, asrc_channel_pair_t channelPair)
  558. {
  559. return (uint32_t)ASRC_ASRDO_ADDR(base, channelPair);
  560. }
  561. /*!
  562. * @brief ASRC configure ideal ratio.
  563. * The ideal ratio should be used when input clock source is not avalible.
  564. *
  565. * @param base ASRC base pointer.
  566. * @param channelPair ASRC channel pair.
  567. * @param inputSampleRate input audio data sample rate.
  568. * @param outputSampleRate output audio data sample rate.
  569. */
  570. status_t ASRC_SetIdealRatioConfig(ASRC_Type *base,
  571. asrc_channel_pair_t channelPair,
  572. uint32_t inputSampleRate,
  573. uint32_t outputSampleRate);
  574. /*! @} */
  575. /*!
  576. * @name Transactional
  577. * @{
  578. */
  579. /*!
  580. * @brief ASRC configure channel pair.
  581. *
  582. * @param base ASRC base pointer.
  583. * @param handle ASRC transactional handle pointer.
  584. * @param config ASRC channel pair configuration pointer.
  585. * @param inputSampleRate input audio data sample rate.
  586. * @param outputSampleRate output audio data sample rate.
  587. */
  588. status_t ASRC_TransferSetChannelPairConfig(ASRC_Type *base,
  589. asrc_handle_t *handle,
  590. asrc_channel_pair_config_t *config,
  591. uint32_t inputSampleRate,
  592. uint32_t outputSampleRate);
  593. /*!
  594. * @brief Initializes the ASRC handle.
  595. *
  596. * This function initializes the handle for the ASRC transactional APIs. Call
  597. * this function once to get the handle initialized.
  598. *
  599. * @param base ASRC base pointer
  600. * @param handle ASRC handle pointer.
  601. * @param channelPair ASRC channel pair.
  602. * @param inCallback Pointer to the user callback function.
  603. * @param outCallback Pointer to the user callback function.
  604. * @param userData User parameter passed to the callback function
  605. */
  606. void ASRC_TransferCreateHandle(ASRC_Type *base,
  607. asrc_handle_t *handle,
  608. asrc_channel_pair_t channelPair,
  609. asrc_transfer_callback_t inCallback,
  610. asrc_transfer_callback_t outCallback,
  611. void *userData);
  612. /*!
  613. * @brief Performs an interrupt non-blocking convert on asrc.
  614. *
  615. * @note This API returns immediately after the transfer initiates, application should check the wait and check the
  616. * callback status.
  617. *
  618. * @param base asrc base pointer.
  619. * @param handle Pointer to the asrc_handle_t structure which stores the transfer state.
  620. * @param xfer Pointer to the ASRC_transfer_t structure.
  621. * @retval kStatus_Success Successfully started the data receive.
  622. * @retval kStatus_ASRCBusy Previous receive still not finished.
  623. */
  624. status_t ASRC_TransferNonBlocking(ASRC_Type *base, asrc_handle_t *handle, asrc_transfer_t *xfer);
  625. /*!
  626. * @brief Performs an blocking convert on asrc.
  627. *
  628. * @note This API returns immediately after the convert finished.
  629. *
  630. * @param base asrc base pointer.
  631. * @param channelPair channel pair index.
  632. * @param xfer Pointer to the ASRC_transfer_t structure.
  633. * @retval kStatus_Success Successfully started the data receive.
  634. */
  635. status_t ASRC_TransferBlocking(ASRC_Type *base, asrc_channel_pair_t channelPair, asrc_transfer_t *xfer);
  636. /*!
  637. * @brief Get converted byte count.
  638. *
  639. * @param base ASRC base pointer.
  640. * @param handle Pointer to the asrc_handle_t structure which stores the transfer state.
  641. * @param count Bytes count sent.
  642. * @retval kStatus_Success Succeed get the transfer count.
  643. * @retval kStatus_ASRCIdle There is not a non-blocking transaction currently in progress.
  644. */
  645. status_t ASRC_TransferGetConvertedCount(ASRC_Type *base, asrc_handle_t *handle, size_t *count);
  646. /*!
  647. * @brief Aborts the current convert.
  648. *
  649. * @note This API can be called any time when an interrupt non-blocking transfer initiates
  650. * to abort the transfer early.
  651. *
  652. * @param base ASRC base pointer.
  653. * @param handle Pointer to the asrc_handle_t structure which stores the transfer state.
  654. */
  655. void ASRC_TransferAbortConvert(ASRC_Type *base, asrc_handle_t *handle);
  656. /*!
  657. * @brief Terminate all ASRC convert.
  658. *
  659. * This function will clear all transfer slots buffered in the asrc queue. If users only want to abort the
  660. * current transfer slot, please call ASRC_TransferAbortConvert.
  661. *
  662. * @param base ASRC base pointer.
  663. * @param handle ASRC eDMA handle pointer.
  664. */
  665. void ASRC_TransferTerminateConvert(ASRC_Type *base, asrc_handle_t *handle);
  666. /*!
  667. * @brief ASRC convert interrupt handler.
  668. *
  669. * @param base ASRC base pointer.
  670. * @param handle Pointer to the asrc_handle_t structure.
  671. */
  672. void ASRC_TransferHandleIRQ(ASRC_Type *base, asrc_handle_t *handle);
  673. /*! @} */
  674. #if defined(__cplusplus)
  675. }
  676. #endif /*_cplusplus*/
  677. /*! @} */
  678. #endif /* _FSL_ASRC_H_ */