fsl_sai.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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_SAI_H_
  9. #define _FSL_SAI_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup sai_driver SAI Driver
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. #define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 3, 4)) /*!< Version 2.3.4 */
  21. /*@}*/
  22. /*! @brief _sai_status_t, SAI return status.*/
  23. enum
  24. {
  25. kStatus_SAI_TxBusy = MAKE_STATUS(kStatusGroup_SAI, 0), /*!< SAI Tx is busy. */
  26. kStatus_SAI_RxBusy = MAKE_STATUS(kStatusGroup_SAI, 1), /*!< SAI Rx is busy. */
  27. kStatus_SAI_TxError = MAKE_STATUS(kStatusGroup_SAI, 2), /*!< SAI Tx FIFO error. */
  28. kStatus_SAI_RxError = MAKE_STATUS(kStatusGroup_SAI, 3), /*!< SAI Rx FIFO error. */
  29. kStatus_SAI_QueueFull = MAKE_STATUS(kStatusGroup_SAI, 4), /*!< SAI transfer queue is full. */
  30. kStatus_SAI_TxIdle = MAKE_STATUS(kStatusGroup_SAI, 5), /*!< SAI Tx is idle */
  31. kStatus_SAI_RxIdle = MAKE_STATUS(kStatusGroup_SAI, 6) /*!< SAI Rx is idle */
  32. };
  33. /*! @brief _sai_channel_mask,.sai channel mask value, actual channel numbers is depend soc specific */
  34. enum
  35. {
  36. kSAI_Channel0Mask = 1 << 0U, /*!< channel 0 mask value */
  37. kSAI_Channel1Mask = 1 << 1U, /*!< channel 1 mask value */
  38. kSAI_Channel2Mask = 1 << 2U, /*!< channel 2 mask value */
  39. kSAI_Channel3Mask = 1 << 3U, /*!< channel 3 mask value */
  40. kSAI_Channel4Mask = 1 << 4U, /*!< channel 4 mask value */
  41. kSAI_Channel5Mask = 1 << 5U, /*!< channel 5 mask value */
  42. kSAI_Channel6Mask = 1 << 6U, /*!< channel 6 mask value */
  43. kSAI_Channel7Mask = 1 << 7U, /*!< channel 7 mask value */
  44. };
  45. /*! @brief Define the SAI bus type */
  46. typedef enum _sai_protocol
  47. {
  48. kSAI_BusLeftJustified = 0x0U, /*!< Uses left justified format.*/
  49. kSAI_BusRightJustified, /*!< Uses right justified format. */
  50. kSAI_BusI2S, /*!< Uses I2S format. */
  51. kSAI_BusPCMA, /*!< Uses I2S PCM A format.*/
  52. kSAI_BusPCMB /*!< Uses I2S PCM B format. */
  53. } sai_protocol_t;
  54. /*! @brief Master or slave mode */
  55. typedef enum _sai_master_slave
  56. {
  57. kSAI_Master = 0x0U, /*!< Master mode include bclk and frame sync */
  58. kSAI_Slave = 0x1U, /*!< Slave mode include bclk and frame sync */
  59. kSAI_Bclk_Master_FrameSync_Slave = 0x2U, /*!< bclk in master mode, frame sync in slave mode */
  60. kSAI_Bclk_Slave_FrameSync_Master = 0x3U, /*!< bclk in slave mode, frame sync in master mode */
  61. } sai_master_slave_t;
  62. /*! @brief Mono or stereo audio format */
  63. typedef enum _sai_mono_stereo
  64. {
  65. kSAI_Stereo = 0x0U, /*!< Stereo sound. */
  66. kSAI_MonoRight, /*!< Only Right channel have sound. */
  67. kSAI_MonoLeft /*!< Only left channel have sound. */
  68. } sai_mono_stereo_t;
  69. /*! @brief SAI data order, MSB or LSB */
  70. typedef enum _sai_data_order
  71. {
  72. kSAI_DataLSB = 0x0U, /*!< LSB bit transferred first */
  73. kSAI_DataMSB /*!< MSB bit transferred first */
  74. } sai_data_order_t;
  75. /*! @brief SAI clock polarity, active high or low */
  76. typedef enum _sai_clock_polarity
  77. {
  78. kSAI_PolarityActiveHigh = 0x0U, /*!< Drive outputs on rising edge */
  79. kSAI_PolarityActiveLow = 0x1U, /*!< Drive outputs on falling edge */
  80. kSAI_SampleOnFallingEdge = 0x0U, /*!< Sample inputs on falling edge */
  81. kSAI_SampleOnRisingEdge = 0x1U, /*!< Sample inputs on rising edge */
  82. } sai_clock_polarity_t;
  83. /*! @brief Synchronous or asynchronous mode */
  84. typedef enum _sai_sync_mode
  85. {
  86. kSAI_ModeAsync = 0x0U, /*!< Asynchronous mode */
  87. kSAI_ModeSync, /*!< Synchronous mode (with receiver or transmit) */
  88. #if defined(FSL_FEATURE_SAI_HAS_SYNC_WITH_ANOTHER_SAI) && (FSL_FEATURE_SAI_HAS_SYNC_WITH_ANOTHER_SAI)
  89. kSAI_ModeSyncWithOtherTx, /*!< Synchronous with another SAI transmit */
  90. kSAI_ModeSyncWithOtherRx /*!< Synchronous with another SAI receiver */
  91. #endif /* FSL_FEATURE_SAI_HAS_SYNC_WITH_ANOTHER_SAI */
  92. } sai_sync_mode_t;
  93. #if !(defined(FSL_FEATURE_SAI_HAS_NO_MCR_MICS) && (FSL_FEATURE_SAI_HAS_NO_MCR_MICS))
  94. /*! @brief Mater clock source */
  95. typedef enum _sai_mclk_source
  96. {
  97. kSAI_MclkSourceSysclk = 0x0U, /*!< Master clock from the system clock */
  98. kSAI_MclkSourceSelect1, /*!< Master clock from source 1 */
  99. kSAI_MclkSourceSelect2, /*!< Master clock from source 2 */
  100. kSAI_MclkSourceSelect3 /*!< Master clock from source 3 */
  101. } sai_mclk_source_t;
  102. #endif
  103. /*! @brief Bit clock source */
  104. typedef enum _sai_bclk_source
  105. {
  106. kSAI_BclkSourceBusclk = 0x0U, /*!< Bit clock using bus clock */
  107. /* General device bit source definition */
  108. kSAI_BclkSourceMclkOption1 = 0x1U, /*!< Bit clock MCLK option 1 */
  109. kSAI_BclkSourceMclkOption2 = 0x2U, /*!< Bit clock MCLK option2 */
  110. kSAI_BclkSourceMclkOption3 = 0x3U, /*!< Bit clock MCLK option3 */
  111. /* Kinetis device bit clock source definition */
  112. kSAI_BclkSourceMclkDiv = 0x1U, /*!< Bit clock using master clock divider */
  113. kSAI_BclkSourceOtherSai0 = 0x2U, /*!< Bit clock from other SAI device */
  114. kSAI_BclkSourceOtherSai1 = 0x3U /*!< Bit clock from other SAI device */
  115. } sai_bclk_source_t;
  116. /*! @brief _sai_interrupt_enable_t, The SAI interrupt enable flag */
  117. enum
  118. {
  119. kSAI_WordStartInterruptEnable =
  120. I2S_TCSR_WSIE_MASK, /*!< Word start flag, means the first word in a frame detected */
  121. kSAI_SyncErrorInterruptEnable = I2S_TCSR_SEIE_MASK, /*!< Sync error flag, means the sync error is detected */
  122. kSAI_FIFOWarningInterruptEnable = I2S_TCSR_FWIE_MASK, /*!< FIFO warning flag, means the FIFO is empty */
  123. kSAI_FIFOErrorInterruptEnable = I2S_TCSR_FEIE_MASK, /*!< FIFO error flag */
  124. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  125. kSAI_FIFORequestInterruptEnable = I2S_TCSR_FRIE_MASK, /*!< FIFO request, means reached watermark */
  126. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  127. };
  128. /*! @brief _sai_dma_enable_t, The DMA request sources */
  129. enum
  130. {
  131. kSAI_FIFOWarningDMAEnable = I2S_TCSR_FWDE_MASK, /*!< FIFO warning caused by the DMA request */
  132. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  133. kSAI_FIFORequestDMAEnable = I2S_TCSR_FRDE_MASK, /*!< FIFO request caused by the DMA request */
  134. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  135. };
  136. /*! @brief _sai_flags, The SAI status flag */
  137. enum
  138. {
  139. kSAI_WordStartFlag = I2S_TCSR_WSF_MASK, /*!< Word start flag, means the first word in a frame detected */
  140. kSAI_SyncErrorFlag = I2S_TCSR_SEF_MASK, /*!< Sync error flag, means the sync error is detected */
  141. kSAI_FIFOErrorFlag = I2S_TCSR_FEF_MASK, /*!< FIFO error flag */
  142. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  143. kSAI_FIFORequestFlag = I2S_TCSR_FRF_MASK, /*!< FIFO request flag. */
  144. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  145. kSAI_FIFOWarningFlag = I2S_TCSR_FWF_MASK, /*!< FIFO warning flag */
  146. };
  147. /*! @brief The reset type */
  148. typedef enum _sai_reset_type
  149. {
  150. kSAI_ResetTypeSoftware = I2S_TCSR_SR_MASK, /*!< Software reset, reset the logic state */
  151. kSAI_ResetTypeFIFO = I2S_TCSR_FR_MASK, /*!< FIFO reset, reset the FIFO read and write pointer */
  152. kSAI_ResetAll = I2S_TCSR_SR_MASK | I2S_TCSR_FR_MASK /*!< All reset. */
  153. } sai_reset_type_t;
  154. #if defined(FSL_FEATURE_SAI_HAS_FIFO_PACKING) && FSL_FEATURE_SAI_HAS_FIFO_PACKING
  155. /*!
  156. * @brief The SAI packing mode
  157. * The mode includes 8 bit and 16 bit packing.
  158. */
  159. typedef enum _sai_fifo_packing
  160. {
  161. kSAI_FifoPackingDisabled = 0x0U, /*!< Packing disabled */
  162. kSAI_FifoPacking8bit = 0x2U, /*!< 8 bit packing enabled */
  163. kSAI_FifoPacking16bit = 0x3U /*!< 16bit packing enabled */
  164. } sai_fifo_packing_t;
  165. #endif /* FSL_FEATURE_SAI_HAS_FIFO_PACKING */
  166. /*! @brief SAI user configuration structure */
  167. typedef struct _sai_config
  168. {
  169. sai_protocol_t protocol; /*!< Audio bus protocol in SAI */
  170. sai_sync_mode_t syncMode; /*!< SAI sync mode, control Tx/Rx clock sync */
  171. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  172. bool mclkOutputEnable; /*!< Master clock output enable, true means master clock divider enabled */
  173. #if !(defined(FSL_FEATURE_SAI_HAS_NO_MCR_MICS) && (FSL_FEATURE_SAI_HAS_NO_MCR_MICS))
  174. sai_mclk_source_t mclkSource; /*!< Master Clock source */
  175. #endif /* FSL_FEATURE_SAI_HAS_MCR */
  176. #endif
  177. sai_bclk_source_t bclkSource; /*!< Bit Clock source */
  178. sai_master_slave_t masterSlave; /*!< Master or slave */
  179. } sai_config_t;
  180. #ifndef SAI_XFER_QUEUE_SIZE
  181. /*!@brief SAI transfer queue size, user can refine it according to use case. */
  182. #define SAI_XFER_QUEUE_SIZE (4U)
  183. #endif
  184. /*! @brief Audio sample rate */
  185. typedef enum _sai_sample_rate
  186. {
  187. kSAI_SampleRate8KHz = 8000U, /*!< Sample rate 8000 Hz */
  188. kSAI_SampleRate11025Hz = 11025U, /*!< Sample rate 11025 Hz */
  189. kSAI_SampleRate12KHz = 12000U, /*!< Sample rate 12000 Hz */
  190. kSAI_SampleRate16KHz = 16000U, /*!< Sample rate 16000 Hz */
  191. kSAI_SampleRate22050Hz = 22050U, /*!< Sample rate 22050 Hz */
  192. kSAI_SampleRate24KHz = 24000U, /*!< Sample rate 24000 Hz */
  193. kSAI_SampleRate32KHz = 32000U, /*!< Sample rate 32000 Hz */
  194. kSAI_SampleRate44100Hz = 44100U, /*!< Sample rate 44100 Hz */
  195. kSAI_SampleRate48KHz = 48000U, /*!< Sample rate 48000 Hz */
  196. kSAI_SampleRate96KHz = 96000U, /*!< Sample rate 96000 Hz */
  197. kSAI_SampleRate192KHz = 192000U, /*!< Sample rate 192000 Hz */
  198. kSAI_SampleRate384KHz = 384000U, /*!< Sample rate 384000 Hz */
  199. } sai_sample_rate_t;
  200. /*! @brief Audio word width */
  201. typedef enum _sai_word_width
  202. {
  203. kSAI_WordWidth8bits = 8U, /*!< Audio data width 8 bits */
  204. kSAI_WordWidth16bits = 16U, /*!< Audio data width 16 bits */
  205. kSAI_WordWidth24bits = 24U, /*!< Audio data width 24 bits */
  206. kSAI_WordWidth32bits = 32U /*!< Audio data width 32 bits */
  207. } sai_word_width_t;
  208. #if defined(FSL_FEATURE_SAI_HAS_CHANNEL_MODE) && FSL_FEATURE_SAI_HAS_CHANNEL_MODE
  209. /*! @brief sai data pin state definition */
  210. typedef enum _sai_data_pin_state
  211. {
  212. kSAI_DataPinStateTriState =
  213. 0U, /*!< transmit data pins are tri-stated when slots are masked or channels are disabled */
  214. kSAI_DataPinStateOutputZero = 1U, /*!< transmit data pins are never tri-stated and will output zero when slots
  215. are masked or channel disabled */
  216. } sai_data_pin_state_t;
  217. #endif
  218. #if defined(FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE) && FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE
  219. /*! @brief sai fifo combine mode definition */
  220. typedef enum _sai_fifo_combine
  221. {
  222. kSAI_FifoCombineDisabled = 0U, /*!< sai fifo combine mode disabled */
  223. kSAI_FifoCombineModeEnabledOnRead, /*!< sai fifo combine mode enabled on FIFO reads */
  224. kSAI_FifoCombineModeEnabledOnWrite, /*!< sai fifo combine mode enabled on FIFO write */
  225. kSAI_FifoCombineModeEnabledOnReadWrite, /*!< sai fifo combined mode enabled on FIFO read/writes */
  226. } sai_fifo_combine_t;
  227. #endif
  228. /*! @brief sai transceiver type */
  229. typedef enum _sai_transceiver_type
  230. {
  231. kSAI_Transmitter = 0U, /*!< sai transmitter */
  232. kSAI_Receiver = 1U, /*!< sai receiver */
  233. } sai_transceiver_type_t;
  234. /*! @brief sai frame sync len */
  235. typedef enum _sai_frame_sync_len
  236. {
  237. kSAI_FrameSyncLenOneBitClk = 0U, /*!< 1 bit clock frame sync len for DSP mode */
  238. kSAI_FrameSyncLenPerWordWidth = 1U, /*!< Frame sync length decided by word width */
  239. } sai_frame_sync_len_t;
  240. /*! @brief sai transfer format */
  241. typedef struct _sai_transfer_format
  242. {
  243. uint32_t sampleRate_Hz; /*!< Sample rate of audio data */
  244. uint32_t bitWidth; /*!< Data length of audio data, usually 8/16/24/32 bits */
  245. sai_mono_stereo_t stereo; /*!< Mono or stereo */
  246. #if defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER)
  247. uint32_t masterClockHz; /*!< Master clock frequency in Hz */
  248. #endif /* FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER */
  249. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  250. uint8_t watermark; /*!< Watermark value */
  251. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  252. /* for the multi channel usage, user can provide channelMask Oonly, then sai driver will handle
  253. * other parameter carefully, such as
  254. * channelMask = kSAI_Channel0Mask | kSAI_Channel1Mask | kSAI_Channel4Mask
  255. * then in SAI_RxSetFormat/SAI_TxSetFormat function, channel/endChannel/channelNums will be calculated.
  256. * for the single channel usage, user can provide channel or channel mask only, such as,
  257. * channel = 0 or channelMask = kSAI_Channel0Mask.
  258. */
  259. uint8_t channel; /*!< Transfer start channel */
  260. uint8_t channelMask; /*!< enabled channel mask value, reference _sai_channel_mask */
  261. uint8_t endChannel; /*!< end channel number */
  262. uint8_t channelNums; /*!< Total enabled channel numbers */
  263. sai_protocol_t protocol; /*!< Which audio protocol used */
  264. bool isFrameSyncCompact; /*!< True means Frame sync length is configurable according to bitWidth, false means frame
  265. sync length is 64 times of bit clock. */
  266. } sai_transfer_format_t;
  267. #if (defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)) || \
  268. (defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER))
  269. /*! @brief master clock configurations */
  270. typedef struct _sai_master_clock
  271. {
  272. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  273. bool mclkOutputEnable; /*!< master clock output enable */
  274. #if !(defined(FSL_FEATURE_SAI_HAS_NO_MCR_MICS) && (FSL_FEATURE_SAI_HAS_NO_MCR_MICS))
  275. sai_mclk_source_t mclkSource; /*!< Master Clock source */
  276. #endif
  277. #endif
  278. #if (defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)) || \
  279. (defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER))
  280. uint32_t mclkHz; /*!< target mclk frequency */
  281. uint32_t mclkSourceClkHz; /*!< mclk source frequency*/
  282. #endif
  283. } sai_master_clock_t;
  284. #endif
  285. /*! @brief sai fifo feature*/
  286. #if (defined(FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR) && FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR) || \
  287. (defined(FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE) && FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE) || \
  288. (defined(FSL_FEATURE_SAI_HAS_FIFO_PACKING) && FSL_FEATURE_SAI_HAS_FIFO_PACKING) || \
  289. (defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1))
  290. #define FSL_SAI_HAS_FIFO_EXTEND_FEATURE 1
  291. #else
  292. #define FSL_SAI_HAS_FIFO_EXTEND_FEATURE 0
  293. #endif
  294. #if FSL_SAI_HAS_FIFO_EXTEND_FEATURE
  295. /*! @brief sai fifo configurations */
  296. typedef struct _sai_fifo
  297. {
  298. #if defined(FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR) && FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR
  299. bool fifoContinueOneError; /*!< fifo continues when error occur */
  300. #endif
  301. #if defined(FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE) && FSL_FEATURE_SAI_HAS_FIFO_COMBINE_MODE
  302. sai_fifo_combine_t fifoCombine; /*!< fifo combine mode */
  303. #endif
  304. #if defined(FSL_FEATURE_SAI_HAS_FIFO_PACKING) && FSL_FEATURE_SAI_HAS_FIFO_PACKING
  305. sai_fifo_packing_t fifoPacking; /*!< fifo packing mode */
  306. #endif
  307. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  308. uint8_t fifoWatermark; /*!< fifo watermark */
  309. #endif
  310. } sai_fifo_t;
  311. #endif
  312. /*! @brief sai bit clock configurations */
  313. typedef struct _sai_bit_clock
  314. {
  315. bool bclkSrcSwap; /*!< bit clock source swap */
  316. bool bclkInputDelay; /*!< bit clock actually used by the transmitter is delayed by the pad output delay,
  317. this has effect of decreasing the data input setup time, but increasing the data output valid
  318. time .*/
  319. sai_clock_polarity_t bclkPolarity; /*!< bit clock polarity */
  320. sai_bclk_source_t bclkSource; /*!< bit Clock source */
  321. } sai_bit_clock_t;
  322. /*! @brief sai frame sync configurations */
  323. typedef struct _sai_frame_sync
  324. {
  325. uint8_t frameSyncWidth; /*!< frame sync width in number of bit clocks */
  326. bool frameSyncEarly; /*!< TRUE is frame sync assert one bit before the first bit of frame
  327. FALSE is frame sync assert with the first bit of the frame */
  328. #if defined(FSL_FEATURE_SAI_HAS_FRAME_SYNC_ON_DEMAND) && FSL_FEATURE_SAI_HAS_FRAME_SYNC_ON_DEMAND
  329. bool frameSyncGenerateOnDemand; /*!< internal frame sync is generated when FIFO waring flag is clear */
  330. #endif
  331. sai_clock_polarity_t frameSyncPolarity; /*!< frame sync polarity */
  332. } sai_frame_sync_t;
  333. /*! @brief sai serial data configurations */
  334. typedef struct _sai_serial_data
  335. {
  336. #if defined(FSL_FEATURE_SAI_HAS_CHANNEL_MODE) && FSL_FEATURE_SAI_HAS_CHANNEL_MODE
  337. sai_data_pin_state_t dataMode; /*!< sai data pin state when slots masked or channel disabled */
  338. #endif
  339. sai_data_order_t dataOrder; /*!< configure whether the LSB or MSB is transmitted first */
  340. uint8_t dataWord0Length; /*!< configure the number of bits in the first word in each frame */
  341. uint8_t dataWordNLength; /*!< configure the number of bits in the each word in each frame, except the first word */
  342. uint8_t dataWordLength; /*!< used to record the data length for dma transfer */
  343. uint8_t
  344. dataFirstBitShifted; /*!< Configure the bit index for the first bit transmitted for each word in the frame */
  345. uint8_t dataWordNum; /*!< configure the number of words in each frame */
  346. uint32_t dataMaskedWord; /*!< configure whether the transmit word is masked */
  347. } sai_serial_data_t;
  348. /*! @brief sai transceiver configurations */
  349. typedef struct _sai_transceiver
  350. {
  351. sai_serial_data_t serialData; /*!< serial data configurations */
  352. sai_frame_sync_t frameSync; /*!< ws configurations */
  353. sai_bit_clock_t bitClock; /*!< bit clock configurations */
  354. #if FSL_SAI_HAS_FIFO_EXTEND_FEATURE
  355. sai_fifo_t fifo; /*!< fifo configurations */
  356. #endif
  357. sai_master_slave_t masterSlave; /*!< transceiver is master or slave */
  358. sai_sync_mode_t syncMode; /*!< transceiver sync mode */
  359. uint8_t startChannel; /*!< Transfer start channel */
  360. uint8_t channelMask; /*!< enabled channel mask value, reference _sai_channel_mask */
  361. uint8_t endChannel; /*!< end channel number */
  362. uint8_t channelNums; /*!< Total enabled channel numbers */
  363. } sai_transceiver_t;
  364. /*! @brief SAI transfer structure */
  365. typedef struct _sai_transfer
  366. {
  367. uint8_t *data; /*!< Data start address to transfer. */
  368. size_t dataSize; /*!< Transfer size. */
  369. } sai_transfer_t;
  370. typedef struct _sai_handle sai_handle_t;
  371. /*! @brief SAI transfer callback prototype */
  372. typedef void (*sai_transfer_callback_t)(I2S_Type *base, sai_handle_t *handle, status_t status, void *userData);
  373. /*! @brief SAI handle structure */
  374. struct _sai_handle
  375. {
  376. I2S_Type *base; /*!< base address */
  377. uint32_t state; /*!< Transfer status */
  378. sai_transfer_callback_t callback; /*!< Callback function called at transfer event*/
  379. void *userData; /*!< Callback parameter passed to callback function*/
  380. uint8_t bitWidth; /*!< Bit width for transfer, 8/16/24/32 bits */
  381. /* for the multi channel usage, user can provide channelMask Oonly, then sai driver will handle
  382. * other parameter carefully, such as
  383. * channelMask = kSAI_Channel0Mask | kSAI_Channel1Mask | kSAI_Channel4Mask
  384. * then in SAI_RxSetFormat/SAI_TxSetFormat function, channel/endChannel/channelNums will be calculated.
  385. * for the single channel usage, user can provide channel or channel mask only, such as,
  386. * channel = 0 or channelMask = kSAI_Channel0Mask.
  387. */
  388. uint8_t channel; /*!< Transfer start channel */
  389. uint8_t channelMask; /*!< enabled channel mask value, refernece _sai_channel_mask */
  390. uint8_t endChannel; /*!< end channel number */
  391. uint8_t channelNums; /*!< Total enabled channel numbers */
  392. sai_transfer_t saiQueue[SAI_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer */
  393. size_t transferSize[SAI_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */
  394. volatile uint8_t queueUser; /*!< Index for user to queue transfer */
  395. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  396. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  397. uint8_t watermark; /*!< Watermark value */
  398. #endif
  399. };
  400. /*******************************************************************************
  401. * API
  402. ******************************************************************************/
  403. #if defined(__cplusplus)
  404. extern "C" {
  405. #endif /*_cplusplus*/
  406. /*!
  407. * @name Initialization and deinitialization
  408. * @{
  409. */
  410. /*!
  411. * @brief Initializes the SAI Tx peripheral.
  412. * @deprecated Do not use this function. It has been superceded by @ref SAI_Init
  413. *
  414. * Ungates the SAI clock, resets the module, and configures SAI Tx with a configuration structure.
  415. * The configuration structure can be custom filled or set with default values by
  416. * SAI_TxGetDefaultConfig().
  417. *
  418. * @note This API should be called at the beginning of the application to use
  419. * the SAI driver. Otherwise, accessing the SAIM module can cause a hard fault
  420. * because the clock is not enabled.
  421. *
  422. * @param base SAI base pointer
  423. * @param config SAI configuration structure.
  424. */
  425. void SAI_TxInit(I2S_Type *base, const sai_config_t *config);
  426. /*!
  427. * @brief Initializes the SAI Rx peripheral.
  428. * @deprecated Do not use this function. It has been superceded by @ref SAI_Init
  429. *
  430. * Ungates the SAI clock, resets the module, and configures the SAI Rx with a configuration structure.
  431. * The configuration structure can be custom filled or set with default values by
  432. * SAI_RxGetDefaultConfig().
  433. *
  434. * @note This API should be called at the beginning of the application to use
  435. * the SAI driver. Otherwise, accessing the SAI module can cause a hard fault
  436. * because the clock is not enabled.
  437. *
  438. * @param base SAI base pointer
  439. * @param config SAI configuration structure.
  440. */
  441. void SAI_RxInit(I2S_Type *base, const sai_config_t *config);
  442. /*!
  443. * @brief Sets the SAI Tx configuration structure to default values.
  444. * @deprecated Do not use this function. It has been superceded by
  445. * @ref SAI_GetClassicI2SConfig, @ref SAI_GetLeftJustifiedConfig , @ref SAI_GetRightJustifiedConfig, @ref
  446. SAI_GetDSPConfig, @ref SAI_GetTDMConfig
  447. *
  448. * This API initializes the configuration structure for use in SAI_TxConfig().
  449. * The initialized structure can remain unchanged in SAI_TxConfig(), or it can be modified
  450. * before calling SAI_TxConfig().
  451. * This is an example.
  452. @code
  453. sai_config_t config;
  454. SAI_TxGetDefaultConfig(&config);
  455. @endcode
  456. *
  457. * @param config pointer to master configuration structure
  458. */
  459. void SAI_TxGetDefaultConfig(sai_config_t *config);
  460. /*!
  461. * @brief Sets the SAI Rx configuration structure to default values.
  462. * @deprecated Do not use this function. It has been superceded by
  463. * @ref SAI_GetClassicI2SConfig, @ref SAI_GetLeftJustifiedConfig , @ref SAI_GetRightJustifiedConfig, @ref
  464. SAI_GetDSPConfig, @ref SAI_GetTDMConfig
  465. *
  466. * This API initializes the configuration structure for use in SAI_RxConfig().
  467. * The initialized structure can remain unchanged in SAI_RxConfig() or it can be modified
  468. * before calling SAI_RxConfig().
  469. * This is an example.
  470. @code
  471. sai_config_t config;
  472. SAI_RxGetDefaultConfig(&config);
  473. @endcode
  474. *
  475. * @param config pointer to master configuration structure
  476. */
  477. void SAI_RxGetDefaultConfig(sai_config_t *config);
  478. /*!
  479. * @brief Initializes the SAI peripheral.
  480. *
  481. * This API gates the SAI clock. The SAI module can't operate unless SAI_Init is called to enable the clock.
  482. *
  483. * @param base SAI base pointer.
  484. */
  485. void SAI_Init(I2S_Type *base);
  486. /*!
  487. * @brief De-initializes the SAI peripheral.
  488. *
  489. * This API gates the SAI clock. The SAI module can't operate unless SAI_TxInit
  490. * or SAI_RxInit is called to enable the clock.
  491. *
  492. * @param base SAI base pointer.
  493. */
  494. void SAI_Deinit(I2S_Type *base);
  495. /*!
  496. * @brief Resets the SAI Tx.
  497. *
  498. * This function enables the software reset and FIFO reset of SAI Tx. After reset, clear the reset bit.
  499. *
  500. * @param base SAI base pointer
  501. */
  502. void SAI_TxReset(I2S_Type *base);
  503. /*!
  504. * @brief Resets the SAI Rx.
  505. *
  506. * This function enables the software reset and FIFO reset of SAI Rx. After reset, clear the reset bit.
  507. *
  508. * @param base SAI base pointer
  509. */
  510. void SAI_RxReset(I2S_Type *base);
  511. /*!
  512. * @brief Enables/disables the SAI Tx.
  513. *
  514. * @param base SAI base pointer.
  515. * @param enable True means enable SAI Tx, false means disable.
  516. */
  517. void SAI_TxEnable(I2S_Type *base, bool enable);
  518. /*!
  519. * @brief Enables/disables the SAI Rx.
  520. *
  521. * @param base SAI base pointer.
  522. * @param enable True means enable SAI Rx, false means disable.
  523. */
  524. void SAI_RxEnable(I2S_Type *base, bool enable);
  525. /*!
  526. * @brief Set Rx bit clock direction.
  527. *
  528. * Select bit clock direction, master or slave.
  529. *
  530. * @param base SAI base pointer.
  531. * @param masterSlave reference sai_master_slave_t.
  532. */
  533. static inline void SAI_TxSetBitClockDirection(I2S_Type *base, sai_master_slave_t masterSlave)
  534. {
  535. if (masterSlave == kSAI_Master)
  536. {
  537. base->TCR2 |= I2S_TCR2_BCD_MASK;
  538. }
  539. else
  540. {
  541. base->TCR2 &= ~I2S_TCR2_BCD_MASK;
  542. }
  543. }
  544. /*!
  545. * @brief Set Rx bit clock direction.
  546. *
  547. * Select bit clock direction, master or slave.
  548. *
  549. * @param base SAI base pointer.
  550. * @param masterSlave reference sai_master_slave_t.
  551. */
  552. static inline void SAI_RxSetBitClockDirection(I2S_Type *base, sai_master_slave_t masterSlave)
  553. {
  554. if (masterSlave == kSAI_Master)
  555. {
  556. base->RCR2 |= I2S_RCR2_BCD_MASK;
  557. }
  558. else
  559. {
  560. base->RCR2 &= ~I2S_RCR2_BCD_MASK;
  561. }
  562. }
  563. /*!
  564. * @brief Set Rx frame sync direction.
  565. *
  566. * Select frame sync direction, master or slave.
  567. *
  568. * @param base SAI base pointer.
  569. * @param masterSlave reference sai_master_slave_t.
  570. */
  571. static inline void SAI_RxSetFrameSyncDirection(I2S_Type *base, sai_master_slave_t masterSlave)
  572. {
  573. if (masterSlave == kSAI_Master)
  574. {
  575. base->RCR4 |= I2S_RCR4_FSD_MASK;
  576. }
  577. else
  578. {
  579. base->RCR4 &= ~I2S_RCR4_FSD_MASK;
  580. }
  581. }
  582. /*!
  583. * @brief Set Tx frame sync direction.
  584. *
  585. * Select frame sync direction, master or slave.
  586. *
  587. * @param base SAI base pointer.
  588. * @param masterSlave reference sai_master_slave_t.
  589. */
  590. static inline void SAI_TxSetFrameSyncDirection(I2S_Type *base, sai_master_slave_t masterSlave)
  591. {
  592. if (masterSlave == kSAI_Master)
  593. {
  594. base->TCR4 |= I2S_TCR4_FSD_MASK;
  595. }
  596. else
  597. {
  598. base->TCR4 &= ~I2S_TCR4_FSD_MASK;
  599. }
  600. }
  601. /*!
  602. * @brief Transmitter bit clock rate configurations.
  603. *
  604. * @param base SAI base pointer.
  605. * @param sourceClockHz Bit clock source frequency.
  606. * @param sampleRate Audio data sample rate.
  607. * @param bitWidth Audio data bitWidth.
  608. * @param channelNumbers Audio channel numbers.
  609. */
  610. void SAI_TxSetBitClockRate(
  611. I2S_Type *base, uint32_t sourceClockHz, uint32_t sampleRate, uint32_t bitWidth, uint32_t channelNumbers);
  612. /*!
  613. * @brief Receiver bit clock rate configurations.
  614. *
  615. * @param base SAI base pointer.
  616. * @param sourceClockHz Bit clock source frequency.
  617. * @param sampleRate Audio data sample rate.
  618. * @param bitWidth Audio data bitWidth.
  619. * @param channelNumbers Audio channel numbers.
  620. */
  621. void SAI_RxSetBitClockRate(
  622. I2S_Type *base, uint32_t sourceClockHz, uint32_t sampleRate, uint32_t bitWidth, uint32_t channelNumbers);
  623. /*!
  624. * @brief Transmitter Bit clock configurations.
  625. *
  626. * @param base SAI base pointer.
  627. * @param masterSlave master or slave.
  628. * @param config bit clock other configurations, can be NULL in slave mode.
  629. */
  630. void SAI_TxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai_bit_clock_t *config);
  631. /*!
  632. * @brief Receiver Bit clock configurations.
  633. *
  634. * @param base SAI base pointer.
  635. * @param masterSlave master or slave.
  636. * @param config bit clock other configurations, can be NULL in slave mode.
  637. */
  638. void SAI_RxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai_bit_clock_t *config);
  639. #if (defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)) || \
  640. (defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER))
  641. /*!
  642. * @brief Master clock configurations.
  643. *
  644. * @param base SAI base pointer.
  645. * @param config master clock configurations.
  646. */
  647. void SAI_SetMasterClockConfig(I2S_Type *base, sai_master_clock_t *config);
  648. #endif
  649. #if FSL_SAI_HAS_FIFO_EXTEND_FEATURE
  650. /*!
  651. * @brief SAI transmitter fifo configurations.
  652. *
  653. * @param base SAI base pointer.
  654. * @param config fifo configurations.
  655. */
  656. void SAI_TxSetFifoConfig(I2S_Type *base, sai_fifo_t *config);
  657. /*!
  658. * @brief SAI receiver fifo configurations.
  659. *
  660. * @param base SAI base pointer.
  661. * @param config fifo configurations.
  662. */
  663. void SAI_RxSetFifoConfig(I2S_Type *base, sai_fifo_t *config);
  664. #endif
  665. /*!
  666. * @brief SAI transmitter Frame sync configurations.
  667. *
  668. * @param base SAI base pointer.
  669. * @param masterSlave master or slave.
  670. * @param config frame sync configurations, can be NULL in slave mode.
  671. */
  672. void SAI_TxSetFrameSyncConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai_frame_sync_t *config);
  673. /*!
  674. * @brief SAI receiver Frame sync configurations.
  675. *
  676. * @param base SAI base pointer.
  677. * @param masterSlave master or slave.
  678. * @param config frame sync configurations, can be NULL in slave mode.
  679. */
  680. void SAI_RxSetFrameSyncConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai_frame_sync_t *config);
  681. /*!
  682. * @brief SAI transmitter Serial data configurations.
  683. *
  684. * @param base SAI base pointer.
  685. * @param config serial data configurations.
  686. */
  687. void SAI_TxSetSerialDataConfig(I2S_Type *base, sai_serial_data_t *config);
  688. /*!
  689. * @brief SAI receiver Serial data configurations.
  690. *
  691. * @param base SAI base pointer.
  692. * @param config serial data configurations.
  693. */
  694. void SAI_RxSetSerialDataConfig(I2S_Type *base, sai_serial_data_t *config);
  695. /*!
  696. * @brief SAI transmitter configurations.
  697. *
  698. * @param base SAI base pointer.
  699. * @param config transmitter configurations.
  700. */
  701. void SAI_TxSetConfig(I2S_Type *base, sai_transceiver_t *config);
  702. /*!
  703. * @brief SAI receiver configurations.
  704. *
  705. * @param base SAI base pointer.
  706. * @param config receiver configurations.
  707. */
  708. void SAI_RxSetConfig(I2S_Type *base, sai_transceiver_t *config);
  709. /*!
  710. * @brief Get classic I2S mode configurations.
  711. *
  712. * @param config transceiver configurations.
  713. * @param bitWidth audio data bitWidth.
  714. * @param mode audio data channel.
  715. * @param saiChannelMask mask value of the channel to be enable.
  716. */
  717. void SAI_GetClassicI2SConfig(sai_transceiver_t *config,
  718. sai_word_width_t bitWidth,
  719. sai_mono_stereo_t mode,
  720. uint32_t saiChannelMask);
  721. /*!
  722. * @brief Get left justified mode configurations.
  723. *
  724. * @param config transceiver configurations.
  725. * @param bitWidth audio data bitWidth.
  726. * @param mode audio data channel.
  727. * @param saiChannelMask mask value of the channel to be enable.
  728. */
  729. void SAI_GetLeftJustifiedConfig(sai_transceiver_t *config,
  730. sai_word_width_t bitWidth,
  731. sai_mono_stereo_t mode,
  732. uint32_t saiChannelMask);
  733. /*!
  734. * @brief Get right justified mode configurations.
  735. *
  736. * @param config transceiver configurations.
  737. * @param bitWidth audio data bitWidth.
  738. * @param mode audio data channel.
  739. * @param saiChannelMask mask value of the channel to be enable.
  740. */
  741. void SAI_GetRightJustifiedConfig(sai_transceiver_t *config,
  742. sai_word_width_t bitWidth,
  743. sai_mono_stereo_t mode,
  744. uint32_t saiChannelMask);
  745. /*!
  746. * @brief Get TDM mode configurations.
  747. *
  748. * @param config transceiver configurations.
  749. * @param frameSyncWidth length of frame sync.
  750. * @param bitWidth audio data word width.
  751. * @param dataWordNum word number in one frame.
  752. * @param saiChannelMask mask value of the channel to be enable.
  753. */
  754. void SAI_GetTDMConfig(sai_transceiver_t *config,
  755. sai_frame_sync_len_t frameSyncWidth,
  756. sai_word_width_t bitWidth,
  757. uint32_t dataWordNum,
  758. uint32_t saiChannelMask);
  759. /*!
  760. * @brief Get DSP mode configurations.
  761. *
  762. * @note DSP mode is also called PCM mode which support MODE A and MODE B,
  763. * DSP/PCM MODE A configuration flow. RX is similiar but uses SAI_RxSetConfig instead of SAI_TxSetConfig:
  764. * @code
  765. * SAI_GetDSPConfig(config, kSAI_FrameSyncLenOneBitClk, bitWidth, kSAI_Stereo, channelMask)
  766. * config->frameSync.frameSyncEarly = true;
  767. * SAI_TxSetConfig(base, config)
  768. * @endcode
  769. *
  770. * DSP/PCM MODE B configuration flow for TX. RX is similiar but uses SAI_RxSetConfig instead of SAI_TxSetConfig:
  771. * @code
  772. * SAI_GetDSPConfig(config, kSAI_FrameSyncLenOneBitClk, bitWidth, kSAI_Stereo, channelMask)
  773. * SAI_TxSetConfig(base, config)
  774. * @endcode
  775. *
  776. * @param config transceiver configurations.
  777. * @param frameSyncWidth length of frame sync.
  778. * @param bitWidth audio data bitWidth.
  779. * @param mode audio data channel.
  780. * @param saiChannelMask mask value of the channel to enable.
  781. */
  782. void SAI_GetDSPConfig(sai_transceiver_t *config,
  783. sai_frame_sync_len_t frameSyncWidth,
  784. sai_word_width_t bitWidth,
  785. sai_mono_stereo_t mode,
  786. uint32_t saiChannelMask);
  787. /*! @} */
  788. /*!
  789. * @name Status
  790. * @{
  791. */
  792. /*!
  793. * @brief Gets the SAI Tx status flag state.
  794. *
  795. * @param base SAI base pointer
  796. * @return SAI Tx status flag value. Use the Status Mask to get the status value needed.
  797. */
  798. static inline uint32_t SAI_TxGetStatusFlag(I2S_Type *base)
  799. {
  800. return base->TCSR;
  801. }
  802. /*!
  803. * @brief Clears the SAI Tx status flag state.
  804. *
  805. * @param base SAI base pointer
  806. * @param mask State mask. It can be a combination of the following source if defined:
  807. * @arg kSAI_WordStartFlag
  808. * @arg kSAI_SyncErrorFlag
  809. * @arg kSAI_FIFOErrorFlag
  810. */
  811. static inline void SAI_TxClearStatusFlags(I2S_Type *base, uint32_t mask)
  812. {
  813. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask);
  814. }
  815. /*!
  816. * @brief Gets the SAI Tx status flag state.
  817. *
  818. * @param base SAI base pointer
  819. * @return SAI Rx status flag value. Use the Status Mask to get the status value needed.
  820. */
  821. static inline uint32_t SAI_RxGetStatusFlag(I2S_Type *base)
  822. {
  823. return base->RCSR;
  824. }
  825. /*!
  826. * @brief Clears the SAI Rx status flag state.
  827. *
  828. * @param base SAI base pointer
  829. * @param mask State mask. It can be a combination of the following sources if defined.
  830. * @arg kSAI_WordStartFlag
  831. * @arg kSAI_SyncErrorFlag
  832. * @arg kSAI_FIFOErrorFlag
  833. */
  834. static inline void SAI_RxClearStatusFlags(I2S_Type *base, uint32_t mask)
  835. {
  836. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask);
  837. }
  838. /*!
  839. * @brief Do software reset or FIFO reset .
  840. *
  841. * FIFO reset means clear all the data in the FIFO, and make the FIFO pointer both to 0.
  842. * Software reset means clear the Tx internal logic, including the bit clock, frame count etc. But software
  843. * reset will not clear any configuration registers like TCR1~TCR5.
  844. * This function will also clear all the error flags such as FIFO error, sync error etc.
  845. *
  846. * @param base SAI base pointer
  847. * @param type Reset type, FIFO reset or software reset
  848. */
  849. void SAI_TxSoftwareReset(I2S_Type *base, sai_reset_type_t type);
  850. /*!
  851. * @brief Do software reset or FIFO reset .
  852. *
  853. * FIFO reset means clear all the data in the FIFO, and make the FIFO pointer both to 0.
  854. * Software reset means clear the Rx internal logic, including the bit clock, frame count etc. But software
  855. * reset will not clear any configuration registers like RCR1~RCR5.
  856. * This function will also clear all the error flags such as FIFO error, sync error etc.
  857. *
  858. * @param base SAI base pointer
  859. * @param type Reset type, FIFO reset or software reset
  860. */
  861. void SAI_RxSoftwareReset(I2S_Type *base, sai_reset_type_t type);
  862. /*!
  863. * @brief Set the Tx channel FIFO enable mask.
  864. *
  865. * @param base SAI base pointer
  866. * @param mask Channel enable mask, 0 means all channel FIFO disabled, 1 means channel 0 enabled,
  867. * 3 means both channel 0 and channel 1 enabled.
  868. */
  869. void SAI_TxSetChannelFIFOMask(I2S_Type *base, uint8_t mask);
  870. /*!
  871. * @brief Set the Rx channel FIFO enable mask.
  872. *
  873. * @param base SAI base pointer
  874. * @param mask Channel enable mask, 0 means all channel FIFO disabled, 1 means channel 0 enabled,
  875. * 3 means both channel 0 and channel 1 enabled.
  876. */
  877. void SAI_RxSetChannelFIFOMask(I2S_Type *base, uint8_t mask);
  878. /*!
  879. * @brief Set the Tx data order.
  880. *
  881. * @param base SAI base pointer
  882. * @param order Data order MSB or LSB
  883. */
  884. void SAI_TxSetDataOrder(I2S_Type *base, sai_data_order_t order);
  885. /*!
  886. * @brief Set the Rx data order.
  887. *
  888. * @param base SAI base pointer
  889. * @param order Data order MSB or LSB
  890. */
  891. void SAI_RxSetDataOrder(I2S_Type *base, sai_data_order_t order);
  892. /*!
  893. * @brief Set the Tx data order.
  894. *
  895. * @param base SAI base pointer
  896. * @param polarity
  897. */
  898. void SAI_TxSetBitClockPolarity(I2S_Type *base, sai_clock_polarity_t polarity);
  899. /*!
  900. * @brief Set the Rx data order.
  901. *
  902. * @param base SAI base pointer
  903. * @param polarity
  904. */
  905. void SAI_RxSetBitClockPolarity(I2S_Type *base, sai_clock_polarity_t polarity);
  906. /*!
  907. * @brief Set the Tx data order.
  908. *
  909. * @param base SAI base pointer
  910. * @param polarity
  911. */
  912. void SAI_TxSetFrameSyncPolarity(I2S_Type *base, sai_clock_polarity_t polarity);
  913. /*!
  914. * @brief Set the Rx data order.
  915. *
  916. * @param base SAI base pointer
  917. * @param polarity
  918. */
  919. void SAI_RxSetFrameSyncPolarity(I2S_Type *base, sai_clock_polarity_t polarity);
  920. #if defined(FSL_FEATURE_SAI_HAS_FIFO_PACKING) && FSL_FEATURE_SAI_HAS_FIFO_PACKING
  921. /*!
  922. * @brief Set Tx FIFO packing feature.
  923. *
  924. * @param base SAI base pointer.
  925. * @param pack FIFO pack type. It is element of sai_fifo_packing_t.
  926. */
  927. void SAI_TxSetFIFOPacking(I2S_Type *base, sai_fifo_packing_t pack);
  928. /*!
  929. * @brief Set Rx FIFO packing feature.
  930. *
  931. * @param base SAI base pointer.
  932. * @param pack FIFO pack type. It is element of sai_fifo_packing_t.
  933. */
  934. void SAI_RxSetFIFOPacking(I2S_Type *base, sai_fifo_packing_t pack);
  935. #endif /* FSL_FEATURE_SAI_HAS_FIFO_PACKING */
  936. #if defined(FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR) && FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR
  937. /*!
  938. * @brief Set Tx FIFO error continue.
  939. *
  940. * FIFO error continue mode means SAI will keep running while FIFO error occurred. If this feature
  941. * not enabled, SAI will hang and users need to clear FEF flag in TCSR register.
  942. *
  943. * @param base SAI base pointer.
  944. * @param isEnabled Is FIFO error continue enabled, true means enable, false means disable.
  945. */
  946. static inline void SAI_TxSetFIFOErrorContinue(I2S_Type *base, bool isEnabled)
  947. {
  948. if (isEnabled)
  949. {
  950. base->TCR4 |= I2S_TCR4_FCONT_MASK;
  951. }
  952. else
  953. {
  954. base->TCR4 &= ~I2S_TCR4_FCONT_MASK;
  955. }
  956. }
  957. /*!
  958. * @brief Set Rx FIFO error continue.
  959. *
  960. * FIFO error continue mode means SAI will keep running while FIFO error occurred. If this feature
  961. * not enabled, SAI will hang and users need to clear FEF flag in RCSR register.
  962. *
  963. * @param base SAI base pointer.
  964. * @param isEnabled Is FIFO error continue enabled, true means enable, false means disable.
  965. */
  966. static inline void SAI_RxSetFIFOErrorContinue(I2S_Type *base, bool isEnabled)
  967. {
  968. if (isEnabled)
  969. {
  970. base->RCR4 |= I2S_RCR4_FCONT_MASK;
  971. }
  972. else
  973. {
  974. base->RCR4 &= ~I2S_RCR4_FCONT_MASK;
  975. }
  976. }
  977. #endif
  978. /*! @} */
  979. /*!
  980. * @name Interrupts
  981. * @{
  982. */
  983. /*!
  984. * @brief Enables the SAI Tx interrupt requests.
  985. *
  986. * @param base SAI base pointer
  987. * @param mask interrupt source
  988. * The parameter can be a combination of the following sources if defined.
  989. * @arg kSAI_WordStartInterruptEnable
  990. * @arg kSAI_SyncErrorInterruptEnable
  991. * @arg kSAI_FIFOWarningInterruptEnable
  992. * @arg kSAI_FIFORequestInterruptEnable
  993. * @arg kSAI_FIFOErrorInterruptEnable
  994. */
  995. static inline void SAI_TxEnableInterrupts(I2S_Type *base, uint32_t mask)
  996. {
  997. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask);
  998. }
  999. /*!
  1000. * @brief Enables the SAI Rx interrupt requests.
  1001. *
  1002. * @param base SAI base pointer
  1003. * @param mask interrupt source
  1004. * The parameter can be a combination of the following sources if defined.
  1005. * @arg kSAI_WordStartInterruptEnable
  1006. * @arg kSAI_SyncErrorInterruptEnable
  1007. * @arg kSAI_FIFOWarningInterruptEnable
  1008. * @arg kSAI_FIFORequestInterruptEnable
  1009. * @arg kSAI_FIFOErrorInterruptEnable
  1010. */
  1011. static inline void SAI_RxEnableInterrupts(I2S_Type *base, uint32_t mask)
  1012. {
  1013. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask);
  1014. }
  1015. /*!
  1016. * @brief Disables the SAI Tx interrupt requests.
  1017. *
  1018. * @param base SAI base pointer
  1019. * @param mask interrupt source
  1020. * The parameter can be a combination of the following sources if defined.
  1021. * @arg kSAI_WordStartInterruptEnable
  1022. * @arg kSAI_SyncErrorInterruptEnable
  1023. * @arg kSAI_FIFOWarningInterruptEnable
  1024. * @arg kSAI_FIFORequestInterruptEnable
  1025. * @arg kSAI_FIFOErrorInterruptEnable
  1026. */
  1027. static inline void SAI_TxDisableInterrupts(I2S_Type *base, uint32_t mask)
  1028. {
  1029. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) & (~mask));
  1030. }
  1031. /*!
  1032. * @brief Disables the SAI Rx interrupt requests.
  1033. *
  1034. * @param base SAI base pointer
  1035. * @param mask interrupt source
  1036. * The parameter can be a combination of the following sources if defined.
  1037. * @arg kSAI_WordStartInterruptEnable
  1038. * @arg kSAI_SyncErrorInterruptEnable
  1039. * @arg kSAI_FIFOWarningInterruptEnable
  1040. * @arg kSAI_FIFORequestInterruptEnable
  1041. * @arg kSAI_FIFOErrorInterruptEnable
  1042. */
  1043. static inline void SAI_RxDisableInterrupts(I2S_Type *base, uint32_t mask)
  1044. {
  1045. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) & (~mask));
  1046. }
  1047. /*! @} */
  1048. /*!
  1049. * @name DMA Control
  1050. * @{
  1051. */
  1052. /*!
  1053. * @brief Enables/disables the SAI Tx DMA requests.
  1054. * @param base SAI base pointer
  1055. * @param mask DMA source
  1056. * The parameter can be combination of the following sources if defined.
  1057. * @arg kSAI_FIFOWarningDMAEnable
  1058. * @arg kSAI_FIFORequestDMAEnable
  1059. * @param enable True means enable DMA, false means disable DMA.
  1060. */
  1061. static inline void SAI_TxEnableDMA(I2S_Type *base, uint32_t mask, bool enable)
  1062. {
  1063. if (enable)
  1064. {
  1065. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask);
  1066. }
  1067. else
  1068. {
  1069. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) & (~mask));
  1070. }
  1071. }
  1072. /*!
  1073. * @brief Enables/disables the SAI Rx DMA requests.
  1074. * @param base SAI base pointer
  1075. * @param mask DMA source
  1076. * The parameter can be a combination of the following sources if defined.
  1077. * @arg kSAI_FIFOWarningDMAEnable
  1078. * @arg kSAI_FIFORequestDMAEnable
  1079. * @param enable True means enable DMA, false means disable DMA.
  1080. */
  1081. static inline void SAI_RxEnableDMA(I2S_Type *base, uint32_t mask, bool enable)
  1082. {
  1083. if (enable)
  1084. {
  1085. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask);
  1086. }
  1087. else
  1088. {
  1089. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) & (~mask));
  1090. }
  1091. }
  1092. /*!
  1093. * @brief Gets the SAI Tx data register address.
  1094. *
  1095. * This API is used to provide a transfer address for the SAI DMA transfer configuration.
  1096. *
  1097. * @param base SAI base pointer.
  1098. * @param channel Which data channel used.
  1099. * @return data register address.
  1100. */
  1101. static inline uint32_t SAI_TxGetDataRegisterAddress(I2S_Type *base, uint32_t channel)
  1102. {
  1103. return (uint32_t)(&(base->TDR)[channel]);
  1104. }
  1105. /*!
  1106. * @brief Gets the SAI Rx data register address.
  1107. *
  1108. * This API is used to provide a transfer address for the SAI DMA transfer configuration.
  1109. *
  1110. * @param base SAI base pointer.
  1111. * @param channel Which data channel used.
  1112. * @return data register address.
  1113. */
  1114. static inline uint32_t SAI_RxGetDataRegisterAddress(I2S_Type *base, uint32_t channel)
  1115. {
  1116. return (uint32_t)(&(base->RDR)[channel]);
  1117. }
  1118. /*! @} */
  1119. /*!
  1120. * @name Bus Operations
  1121. * @{
  1122. */
  1123. /*!
  1124. * @brief Configures the SAI Tx audio format.
  1125. * @deprecated Do not use this function. It has been superceded by @ref SAI_TxSetConfig
  1126. *
  1127. * The audio format can be changed at run-time. This function configures the sample rate and audio data
  1128. * format to be transferred.
  1129. *
  1130. * @param base SAI base pointer.
  1131. * @param format Pointer to the SAI audio data format structure.
  1132. * @param mclkSourceClockHz SAI master clock source frequency in Hz.
  1133. * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If the bit clock source is a master
  1134. * clock, this value should equal the masterClockHz.
  1135. */
  1136. void SAI_TxSetFormat(I2S_Type *base,
  1137. sai_transfer_format_t *format,
  1138. uint32_t mclkSourceClockHz,
  1139. uint32_t bclkSourceClockHz);
  1140. /*!
  1141. * @brief Configures the SAI Rx audio format.
  1142. * @deprecated Do not use this function. It has been superceded by @ref SAI_RxSetConfig
  1143. *
  1144. * The audio format can be changed at run-time. This function configures the sample rate and audio data
  1145. * format to be transferred.
  1146. *
  1147. * @param base SAI base pointer.
  1148. * @param format Pointer to the SAI audio data format structure.
  1149. * @param mclkSourceClockHz SAI master clock source frequency in Hz.
  1150. * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If the bit clock source is a master
  1151. * clock, this value should equal the masterClockHz.
  1152. */
  1153. void SAI_RxSetFormat(I2S_Type *base,
  1154. sai_transfer_format_t *format,
  1155. uint32_t mclkSourceClockHz,
  1156. uint32_t bclkSourceClockHz);
  1157. /*!
  1158. * @brief Sends data using a blocking method.
  1159. *
  1160. * @note This function blocks by polling until data is ready to be sent.
  1161. *
  1162. * @param base SAI base pointer.
  1163. * @param channel Data channel used.
  1164. * @param bitWidth How many bits in an audio word; usually 8/16/24/32 bits.
  1165. * @param buffer Pointer to the data to be written.
  1166. * @param size Bytes to be written.
  1167. */
  1168. void SAI_WriteBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  1169. /*!
  1170. * @brief Sends data to multi channel using a blocking method.
  1171. *
  1172. * @note This function blocks by polling until data is ready to be sent.
  1173. *
  1174. * @param base SAI base pointer.
  1175. * @param channel Data channel used.
  1176. * @param channelMask channel mask.
  1177. * @param bitWidth How many bits in an audio word; usually 8/16/24/32 bits.
  1178. * @param buffer Pointer to the data to be written.
  1179. * @param size Bytes to be written.
  1180. */
  1181. void SAI_WriteMultiChannelBlocking(
  1182. I2S_Type *base, uint32_t channel, uint32_t channelMask, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  1183. /*!
  1184. * @brief Writes data into SAI FIFO.
  1185. *
  1186. * @param base SAI base pointer.
  1187. * @param channel Data channel used.
  1188. * @param data Data needs to be written.
  1189. */
  1190. static inline void SAI_WriteData(I2S_Type *base, uint32_t channel, uint32_t data)
  1191. {
  1192. base->TDR[channel] = data;
  1193. }
  1194. /*!
  1195. * @brief Receives data using a blocking method.
  1196. *
  1197. * @note This function blocks by polling until data is ready to be sent.
  1198. *
  1199. * @param base SAI base pointer.
  1200. * @param channel Data channel used.
  1201. * @param bitWidth How many bits in an audio word; usually 8/16/24/32 bits.
  1202. * @param buffer Pointer to the data to be read.
  1203. * @param size Bytes to be read.
  1204. */
  1205. void SAI_ReadBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  1206. /*!
  1207. * @brief Receives multi channel data using a blocking method.
  1208. *
  1209. * @note This function blocks by polling until data is ready to be sent.
  1210. *
  1211. * @param base SAI base pointer.
  1212. * @param channel Data channel used.
  1213. * @param channelMask channel mask.
  1214. * @param bitWidth How many bits in an audio word; usually 8/16/24/32 bits.
  1215. * @param buffer Pointer to the data to be read.
  1216. * @param size Bytes to be read.
  1217. */
  1218. void SAI_ReadMultiChannelBlocking(
  1219. I2S_Type *base, uint32_t channel, uint32_t channelMask, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  1220. /*!
  1221. * @brief Reads data from the SAI FIFO.
  1222. *
  1223. * @param base SAI base pointer.
  1224. * @param channel Data channel used.
  1225. * @return Data in SAI FIFO.
  1226. */
  1227. static inline uint32_t SAI_ReadData(I2S_Type *base, uint32_t channel)
  1228. {
  1229. return base->RDR[channel];
  1230. }
  1231. /*! @} */
  1232. /*!
  1233. * @name Transactional
  1234. * @{
  1235. */
  1236. /*!
  1237. * @brief Initializes the SAI Tx handle.
  1238. *
  1239. * This function initializes the Tx handle for the SAI Tx transactional APIs. Call
  1240. * this function once to get the handle initialized.
  1241. *
  1242. * @param base SAI base pointer
  1243. * @param handle SAI handle pointer.
  1244. * @param callback Pointer to the user callback function.
  1245. * @param userData User parameter passed to the callback function
  1246. */
  1247. void SAI_TransferTxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData);
  1248. /*!
  1249. * @brief Initializes the SAI Rx handle.
  1250. *
  1251. * This function initializes the Rx handle for the SAI Rx transactional APIs. Call
  1252. * this function once to get the handle initialized.
  1253. *
  1254. * @param base SAI base pointer.
  1255. * @param handle SAI handle pointer.
  1256. * @param callback Pointer to the user callback function.
  1257. * @param userData User parameter passed to the callback function.
  1258. */
  1259. void SAI_TransferRxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData);
  1260. /*!
  1261. * @brief SAI transmitter transfer configurations.
  1262. *
  1263. * This function initializes the Tx, include bit clock, frame sync, master clock, serial data and fifo
  1264. * configurations.
  1265. *
  1266. * @param base SAI base pointer.
  1267. * @param handle SAI handle pointer.
  1268. * @param config tranmitter configurations.
  1269. */
  1270. void SAI_TransferTxSetConfig(I2S_Type *base, sai_handle_t *handle, sai_transceiver_t *config);
  1271. /*!
  1272. * @brief SAI receiver transfer configurations.
  1273. *
  1274. * This function initializes the Rx, include bit clock, frame sync, master clock, serial data and fifo
  1275. * configurations.
  1276. *
  1277. * @param base SAI base pointer.
  1278. * @param handle SAI handle pointer.
  1279. * @param config receiver configurations.
  1280. */
  1281. void SAI_TransferRxSetConfig(I2S_Type *base, sai_handle_t *handle, sai_transceiver_t *config);
  1282. /*!
  1283. * @brief Configures the SAI Tx audio format.
  1284. * @deprecated Do not use this function. It has been superceded by @ref SAI_TransferTxSetConfig
  1285. *
  1286. * The audio format can be changed at run-time. This function configures the sample rate and audio data
  1287. * format to be transferred.
  1288. *
  1289. * @param base SAI base pointer.
  1290. * @param handle SAI handle pointer.
  1291. * @param format Pointer to the SAI audio data format structure.
  1292. * @param mclkSourceClockHz SAI master clock source frequency in Hz.
  1293. * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If a bit clock source is a master
  1294. * clock, this value should equal the masterClockHz in format.
  1295. * @return Status of this function. Return value is the status_t.
  1296. */
  1297. status_t SAI_TransferTxSetFormat(I2S_Type *base,
  1298. sai_handle_t *handle,
  1299. sai_transfer_format_t *format,
  1300. uint32_t mclkSourceClockHz,
  1301. uint32_t bclkSourceClockHz);
  1302. /*!
  1303. * @brief Configures the SAI Rx audio format.
  1304. * @deprecated Do not use this function. It has been superceded by @ref SAI_TransferRxSetConfig
  1305. *
  1306. * The audio format can be changed at run-time. This function configures the sample rate and audio data
  1307. * format to be transferred.
  1308. *
  1309. * @param base SAI base pointer.
  1310. * @param handle SAI handle pointer.
  1311. * @param format Pointer to the SAI audio data format structure.
  1312. * @param mclkSourceClockHz SAI master clock source frequency in Hz.
  1313. * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If a bit clock source is a master
  1314. * clock, this value should equal the masterClockHz in format.
  1315. * @return Status of this function. Return value is one of status_t.
  1316. */
  1317. status_t SAI_TransferRxSetFormat(I2S_Type *base,
  1318. sai_handle_t *handle,
  1319. sai_transfer_format_t *format,
  1320. uint32_t mclkSourceClockHz,
  1321. uint32_t bclkSourceClockHz);
  1322. /*!
  1323. * @brief Performs an interrupt non-blocking send transfer on SAI.
  1324. *
  1325. * @note This API returns immediately after the transfer initiates.
  1326. * Call the SAI_TxGetTransferStatusIRQ to poll the transfer status and check whether
  1327. * the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer
  1328. * is finished.
  1329. *
  1330. * @param base SAI base pointer.
  1331. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1332. * @param xfer Pointer to the sai_transfer_t structure.
  1333. * @retval kStatus_Success Successfully started the data receive.
  1334. * @retval kStatus_SAI_TxBusy Previous receive still not finished.
  1335. * @retval kStatus_InvalidArgument The input parameter is invalid.
  1336. */
  1337. status_t SAI_TransferSendNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer);
  1338. /*!
  1339. * @brief Performs an interrupt non-blocking receive transfer on SAI.
  1340. *
  1341. * @note This API returns immediately after the transfer initiates.
  1342. * Call the SAI_RxGetTransferStatusIRQ to poll the transfer status and check whether
  1343. * the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer
  1344. * is finished.
  1345. *
  1346. * @param base SAI base pointer
  1347. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1348. * @param xfer Pointer to the sai_transfer_t structure.
  1349. * @retval kStatus_Success Successfully started the data receive.
  1350. * @retval kStatus_SAI_RxBusy Previous receive still not finished.
  1351. * @retval kStatus_InvalidArgument The input parameter is invalid.
  1352. */
  1353. status_t SAI_TransferReceiveNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer);
  1354. /*!
  1355. * @brief Gets a set byte count.
  1356. *
  1357. * @param base SAI base pointer.
  1358. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1359. * @param count Bytes count sent.
  1360. * @retval kStatus_Success Succeed get the transfer count.
  1361. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  1362. */
  1363. status_t SAI_TransferGetSendCount(I2S_Type *base, sai_handle_t *handle, size_t *count);
  1364. /*!
  1365. * @brief Gets a received byte count.
  1366. *
  1367. * @param base SAI base pointer.
  1368. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1369. * @param count Bytes count received.
  1370. * @retval kStatus_Success Succeed get the transfer count.
  1371. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  1372. */
  1373. status_t SAI_TransferGetReceiveCount(I2S_Type *base, sai_handle_t *handle, size_t *count);
  1374. /*!
  1375. * @brief Aborts the current send.
  1376. *
  1377. * @note This API can be called any time when an interrupt non-blocking transfer initiates
  1378. * to abort the transfer early.
  1379. *
  1380. * @param base SAI base pointer.
  1381. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1382. */
  1383. void SAI_TransferAbortSend(I2S_Type *base, sai_handle_t *handle);
  1384. /*!
  1385. * @brief Aborts the current IRQ receive.
  1386. *
  1387. * @note This API can be called when an interrupt non-blocking transfer initiates
  1388. * to abort the transfer early.
  1389. *
  1390. * @param base SAI base pointer
  1391. * @param handle Pointer to the sai_handle_t structure which stores the transfer state.
  1392. */
  1393. void SAI_TransferAbortReceive(I2S_Type *base, sai_handle_t *handle);
  1394. /*!
  1395. * @brief Terminate all SAI send.
  1396. *
  1397. * This function will clear all transfer slots buffered in the sai queue. If users only want to abort the
  1398. * current transfer slot, please call SAI_TransferAbortSend.
  1399. *
  1400. * @param base SAI base pointer.
  1401. * @param handle SAI eDMA handle pointer.
  1402. */
  1403. void SAI_TransferTerminateSend(I2S_Type *base, sai_handle_t *handle);
  1404. /*!
  1405. * @brief Terminate all SAI receive.
  1406. *
  1407. * This function will clear all transfer slots buffered in the sai queue. If users only want to abort the
  1408. * current transfer slot, please call SAI_TransferAbortReceive.
  1409. *
  1410. * @param base SAI base pointer.
  1411. * @param handle SAI eDMA handle pointer.
  1412. */
  1413. void SAI_TransferTerminateReceive(I2S_Type *base, sai_handle_t *handle);
  1414. /*!
  1415. * @brief Tx interrupt handler.
  1416. *
  1417. * @param base SAI base pointer.
  1418. * @param handle Pointer to the sai_handle_t structure.
  1419. */
  1420. void SAI_TransferTxHandleIRQ(I2S_Type *base, sai_handle_t *handle);
  1421. /*!
  1422. * @brief Tx interrupt handler.
  1423. *
  1424. * @param base SAI base pointer.
  1425. * @param handle Pointer to the sai_handle_t structure.
  1426. */
  1427. void SAI_TransferRxHandleIRQ(I2S_Type *base, sai_handle_t *handle);
  1428. /*! @} */
  1429. #if defined(__cplusplus)
  1430. }
  1431. #endif /*_cplusplus*/
  1432. /*! @} */
  1433. #endif /* _FSL_SAI_H_ */