fsl_sai.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_sai.h"
  35. /*******************************************************************************
  36. * Definitations
  37. ******************************************************************************/
  38. enum _sai_transfer_state
  39. {
  40. kSAI_Busy = 0x0U, /*!< SAI is busy */
  41. kSAI_Idle, /*!< Transfer is done. */
  42. kSAI_Error /*!< Transfer error occured. */
  43. };
  44. /*! @brief Typedef for sai tx interrupt handler. */
  45. typedef void (*sai_tx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
  46. /*! @brief Typedef for sai rx interrupt handler. */
  47. typedef void (*sai_rx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
  48. /*******************************************************************************
  49. * Prototypes
  50. ******************************************************************************/
  51. #if defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER)
  52. /*!
  53. * @brief Set the master clock divider.
  54. *
  55. * This API will compute the master clock divider according to master clock frequency and master
  56. * clock source clock source frequency.
  57. *
  58. * @param base SAI base pointer.
  59. * @param mclk_Hz Mater clock frequency in Hz.
  60. * @param mclkSrcClock_Hz Master clock source frequency in Hz.
  61. */
  62. static void SAI_SetMasterClockDivider(I2S_Type *base, uint32_t mclk_Hz, uint32_t mclkSrcClock_Hz);
  63. #endif /* FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER */
  64. /*!
  65. * @brief Get the instance number for SAI.
  66. *
  67. * @param base SAI base pointer.
  68. */
  69. uint32_t SAI_GetInstance(I2S_Type *base);
  70. /*!
  71. * @brief sends a piece of data in non-blocking way.
  72. *
  73. * @param base SAI base pointer
  74. * @param channel Data channel used.
  75. * @param bitWidth How many bits in a audio word, usually 8/16/24/32 bits.
  76. * @param buffer Pointer to the data to be written.
  77. * @param size Bytes to be written.
  78. */
  79. static void SAI_WriteNonBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  80. /*!
  81. * @brief Receive a piece of data in non-blocking way.
  82. *
  83. * @param base SAI base pointer
  84. * @param channel Data channel used.
  85. * @param bitWidth How many bits in a audio word, usually 8/16/24/32 bits.
  86. * @param buffer Pointer to the data to be read.
  87. * @param size Bytes to be read.
  88. */
  89. static void SAI_ReadNonBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size);
  90. /*******************************************************************************
  91. * Variables
  92. ******************************************************************************/
  93. /* Base pointer array */
  94. static I2S_Type *const s_saiBases[] = I2S_BASE_PTRS;
  95. /*!@brief SAI handle pointer */
  96. sai_handle_t *s_saiHandle[ARRAY_SIZE(s_saiBases)][2];
  97. /* IRQ number array */
  98. static const IRQn_Type s_saiTxIRQ[] = I2S_TX_IRQS;
  99. static const IRQn_Type s_saiRxIRQ[] = I2S_RX_IRQS;
  100. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  101. /* Clock name array */
  102. static const clock_ip_name_t s_saiClock[] = SAI_CLOCKS;
  103. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  104. /*! @brief Pointer to tx IRQ handler for each instance. */
  105. static sai_tx_isr_t s_saiTxIsr;
  106. /*! @brief Pointer to tx IRQ handler for each instance. */
  107. static sai_rx_isr_t s_saiRxIsr;
  108. /*******************************************************************************
  109. * Code
  110. ******************************************************************************/
  111. #if defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER)
  112. static void SAI_SetMasterClockDivider(I2S_Type *base, uint32_t mclk_Hz, uint32_t mclkSrcClock_Hz)
  113. {
  114. uint32_t freq = mclkSrcClock_Hz;
  115. uint16_t fract, divide;
  116. uint32_t remaind = 0;
  117. uint32_t current_remainder = 0xFFFFFFFFU;
  118. uint16_t current_fract = 0;
  119. uint16_t current_divide = 0;
  120. uint32_t mul_freq = 0;
  121. uint32_t max_fract = 256;
  122. /*In order to prevent overflow */
  123. freq /= 100;
  124. mclk_Hz /= 100;
  125. /* Compute the max fract number */
  126. max_fract = mclk_Hz * 4096 / freq + 1;
  127. if (max_fract > 256)
  128. {
  129. max_fract = 256;
  130. }
  131. /* Looking for the closet frequency */
  132. for (fract = 1; fract < max_fract; fract++)
  133. {
  134. mul_freq = freq * fract;
  135. remaind = mul_freq % mclk_Hz;
  136. divide = mul_freq / mclk_Hz;
  137. /* Find the exactly frequency */
  138. if (remaind == 0)
  139. {
  140. current_fract = fract;
  141. current_divide = mul_freq / mclk_Hz;
  142. break;
  143. }
  144. /* Closer to next one, set the closest to next data */
  145. if (remaind > mclk_Hz / 2)
  146. {
  147. remaind = mclk_Hz - remaind;
  148. divide += 1;
  149. }
  150. /* Update the closest div and fract */
  151. if (remaind < current_remainder)
  152. {
  153. current_fract = fract;
  154. current_divide = divide;
  155. current_remainder = remaind;
  156. }
  157. }
  158. /* Fill the computed fract and divider to registers */
  159. base->MDR = I2S_MDR_DIVIDE(current_divide - 1) | I2S_MDR_FRACT(current_fract - 1);
  160. /* Waiting for the divider updated */
  161. while (base->MCR & I2S_MCR_DUF_MASK)
  162. {
  163. }
  164. }
  165. #endif /* FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER */
  166. uint32_t SAI_GetInstance(I2S_Type *base)
  167. {
  168. uint32_t instance;
  169. /* Find the instance index from base address mappings. */
  170. for (instance = 0; instance < ARRAY_SIZE(s_saiBases); instance++)
  171. {
  172. if (s_saiBases[instance] == base)
  173. {
  174. break;
  175. }
  176. }
  177. assert(instance < ARRAY_SIZE(s_saiBases));
  178. return instance;
  179. }
  180. static void SAI_WriteNonBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
  181. {
  182. uint32_t i = 0;
  183. uint8_t j = 0;
  184. uint8_t bytesPerWord = bitWidth / 8U;
  185. uint32_t data = 0;
  186. uint32_t temp = 0;
  187. for (i = 0; i < size / bytesPerWord; i++)
  188. {
  189. for (j = 0; j < bytesPerWord; j++)
  190. {
  191. temp = (uint32_t)(*buffer);
  192. data |= (temp << (8U * j));
  193. buffer++;
  194. }
  195. base->TDR[channel] = data;
  196. data = 0;
  197. }
  198. }
  199. static void SAI_ReadNonBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
  200. {
  201. uint32_t i = 0;
  202. uint8_t j = 0;
  203. uint8_t bytesPerWord = bitWidth / 8U;
  204. uint32_t data = 0;
  205. for (i = 0; i < size / bytesPerWord; i++)
  206. {
  207. data = base->RDR[channel];
  208. for (j = 0; j < bytesPerWord; j++)
  209. {
  210. *buffer = (data >> (8U * j)) & 0xFF;
  211. buffer++;
  212. }
  213. }
  214. }
  215. void SAI_TxInit(I2S_Type *base, const sai_config_t *config)
  216. {
  217. uint32_t val = 0;
  218. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  219. /* Enable the SAI clock */
  220. CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
  221. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  222. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  223. /* Master clock source setting */
  224. val = (base->MCR & ~I2S_MCR_MICS_MASK);
  225. base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
  226. /* Configure Master clock output enable */
  227. val = (base->MCR & ~I2S_MCR_MOE_MASK);
  228. base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
  229. #endif /* FSL_FEATURE_SAI_HAS_MCR */
  230. /* Configure audio protocol */
  231. switch (config->protocol)
  232. {
  233. case kSAI_BusLeftJustified:
  234. base->TCR2 |= I2S_TCR2_BCP_MASK;
  235. base->TCR3 &= ~I2S_TCR3_WDFL_MASK;
  236. base->TCR4 = I2S_TCR4_MF(1U) | I2S_TCR4_SYWD(31U) | I2S_TCR4_FSE(0U) | I2S_TCR4_FSP(0U) | I2S_TCR4_FRSZ(1U);
  237. break;
  238. case kSAI_BusRightJustified:
  239. base->TCR2 |= I2S_TCR2_BCP_MASK;
  240. base->TCR3 &= ~I2S_TCR3_WDFL_MASK;
  241. base->TCR4 = I2S_TCR4_MF(1U) | I2S_TCR4_SYWD(31U) | I2S_TCR4_FSE(0U) | I2S_TCR4_FSP(0U) | I2S_TCR4_FRSZ(1U);
  242. break;
  243. case kSAI_BusI2S:
  244. base->TCR2 |= I2S_TCR2_BCP_MASK;
  245. base->TCR3 &= ~I2S_TCR3_WDFL_MASK;
  246. base->TCR4 = I2S_TCR4_MF(1U) | I2S_TCR4_SYWD(31U) | I2S_TCR4_FSE(1U) | I2S_TCR4_FSP(1U) | I2S_TCR4_FRSZ(1U);
  247. break;
  248. case kSAI_BusPCMA:
  249. base->TCR2 &= ~I2S_TCR2_BCP_MASK;
  250. base->TCR3 &= ~I2S_TCR3_WDFL_MASK;
  251. base->TCR4 = I2S_TCR4_MF(1U) | I2S_TCR4_SYWD(0U) | I2S_TCR4_FSE(1U) | I2S_TCR4_FSP(0U) | I2S_TCR4_FRSZ(1U);
  252. break;
  253. case kSAI_BusPCMB:
  254. base->TCR2 &= ~I2S_TCR2_BCP_MASK;
  255. base->TCR3 &= ~I2S_TCR3_WDFL_MASK;
  256. base->TCR4 = I2S_TCR4_MF(1U) | I2S_TCR4_SYWD(0U) | I2S_TCR4_FSE(0U) | I2S_TCR4_FSP(0U) | I2S_TCR4_FRSZ(1U);
  257. break;
  258. default:
  259. break;
  260. }
  261. /* Set master or slave */
  262. if (config->masterSlave == kSAI_Master)
  263. {
  264. base->TCR2 |= I2S_TCR2_BCD_MASK;
  265. base->TCR4 |= I2S_TCR4_FSD_MASK;
  266. /* Bit clock source setting */
  267. val = base->TCR2 & (~I2S_TCR2_MSEL_MASK);
  268. base->TCR2 = (val | I2S_TCR2_MSEL(config->bclkSource));
  269. }
  270. else
  271. {
  272. base->TCR2 &= ~I2S_TCR2_BCD_MASK;
  273. base->TCR4 &= ~I2S_TCR4_FSD_MASK;
  274. }
  275. /* Set Sync mode */
  276. switch (config->syncMode)
  277. {
  278. case kSAI_ModeAsync:
  279. val = base->TCR2;
  280. val &= ~I2S_TCR2_SYNC_MASK;
  281. base->TCR2 = (val | I2S_TCR2_SYNC(0U));
  282. break;
  283. case kSAI_ModeSync:
  284. val = base->TCR2;
  285. val &= ~I2S_TCR2_SYNC_MASK;
  286. base->TCR2 = (val | I2S_TCR2_SYNC(1U));
  287. /* If sync with Rx, should set Rx to async mode */
  288. val = base->RCR2;
  289. val &= ~I2S_RCR2_SYNC_MASK;
  290. base->RCR2 = (val | I2S_RCR2_SYNC(0U));
  291. break;
  292. case kSAI_ModeSyncWithOtherTx:
  293. val = base->TCR2;
  294. val &= ~I2S_TCR2_SYNC_MASK;
  295. base->TCR2 = (val | I2S_TCR2_SYNC(2U));
  296. break;
  297. case kSAI_ModeSyncWithOtherRx:
  298. val = base->TCR2;
  299. val &= ~I2S_TCR2_SYNC_MASK;
  300. base->TCR2 = (val | I2S_TCR2_SYNC(3U));
  301. break;
  302. default:
  303. break;
  304. }
  305. }
  306. void SAI_RxInit(I2S_Type *base, const sai_config_t *config)
  307. {
  308. uint32_t val = 0;
  309. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  310. /* Enable SAI clock first. */
  311. CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
  312. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  313. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  314. /* Master clock source setting */
  315. val = (base->MCR & ~I2S_MCR_MICS_MASK);
  316. base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
  317. /* Configure Master clock output enable */
  318. val = (base->MCR & ~I2S_MCR_MOE_MASK);
  319. base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
  320. #endif /* FSL_FEATURE_SAI_HAS_MCR */
  321. /* Configure audio protocol */
  322. switch (config->protocol)
  323. {
  324. case kSAI_BusLeftJustified:
  325. base->RCR2 |= I2S_RCR2_BCP_MASK;
  326. base->RCR3 &= ~I2S_RCR3_WDFL_MASK;
  327. base->RCR4 = I2S_RCR4_MF(1U) | I2S_RCR4_SYWD(31U) | I2S_RCR4_FSE(0U) | I2S_RCR4_FSP(0U) | I2S_RCR4_FRSZ(1U);
  328. break;
  329. case kSAI_BusRightJustified:
  330. base->RCR2 |= I2S_RCR2_BCP_MASK;
  331. base->RCR3 &= ~I2S_RCR3_WDFL_MASK;
  332. base->RCR4 = I2S_RCR4_MF(1U) | I2S_RCR4_SYWD(31U) | I2S_RCR4_FSE(0U) | I2S_RCR4_FSP(0U) | I2S_RCR4_FRSZ(1U);
  333. break;
  334. case kSAI_BusI2S:
  335. base->RCR2 |= I2S_RCR2_BCP_MASK;
  336. base->RCR3 &= ~I2S_RCR3_WDFL_MASK;
  337. base->RCR4 = I2S_RCR4_MF(1U) | I2S_RCR4_SYWD(31U) | I2S_RCR4_FSE(1U) | I2S_RCR4_FSP(1U) | I2S_RCR4_FRSZ(1U);
  338. break;
  339. case kSAI_BusPCMA:
  340. base->RCR2 &= ~I2S_RCR2_BCP_MASK;
  341. base->RCR3 &= ~I2S_RCR3_WDFL_MASK;
  342. base->RCR4 = I2S_RCR4_MF(1U) | I2S_RCR4_SYWD(0U) | I2S_RCR4_FSE(1U) | I2S_RCR4_FSP(0U) | I2S_RCR4_FRSZ(1U);
  343. break;
  344. case kSAI_BusPCMB:
  345. base->RCR2 &= ~I2S_RCR2_BCP_MASK;
  346. base->RCR3 &= ~I2S_RCR3_WDFL_MASK;
  347. base->RCR4 = I2S_RCR4_MF(1U) | I2S_RCR4_SYWD(0U) | I2S_RCR4_FSE(0U) | I2S_RCR4_FSP(0U) | I2S_RCR4_FRSZ(1U);
  348. break;
  349. default:
  350. break;
  351. }
  352. /* Set master or slave */
  353. if (config->masterSlave == kSAI_Master)
  354. {
  355. base->RCR2 |= I2S_RCR2_BCD_MASK;
  356. base->RCR4 |= I2S_RCR4_FSD_MASK;
  357. /* Bit clock source setting */
  358. val = base->RCR2 & (~I2S_RCR2_MSEL_MASK);
  359. base->RCR2 = (val | I2S_RCR2_MSEL(config->bclkSource));
  360. }
  361. else
  362. {
  363. base->RCR2 &= ~I2S_RCR2_BCD_MASK;
  364. base->RCR4 &= ~I2S_RCR4_FSD_MASK;
  365. }
  366. /* Set Sync mode */
  367. switch (config->syncMode)
  368. {
  369. case kSAI_ModeAsync:
  370. val = base->RCR2;
  371. val &= ~I2S_RCR2_SYNC_MASK;
  372. base->RCR2 = (val | I2S_RCR2_SYNC(0U));
  373. break;
  374. case kSAI_ModeSync:
  375. val = base->RCR2;
  376. val &= ~I2S_RCR2_SYNC_MASK;
  377. base->RCR2 = (val | I2S_RCR2_SYNC(1U));
  378. /* If sync with Tx, should set Tx to async mode */
  379. val = base->TCR2;
  380. val &= ~I2S_TCR2_SYNC_MASK;
  381. base->TCR2 = (val | I2S_TCR2_SYNC(0U));
  382. break;
  383. case kSAI_ModeSyncWithOtherTx:
  384. val = base->RCR2;
  385. val &= ~I2S_RCR2_SYNC_MASK;
  386. base->RCR2 = (val | I2S_RCR2_SYNC(2U));
  387. break;
  388. case kSAI_ModeSyncWithOtherRx:
  389. val = base->RCR2;
  390. val &= ~I2S_RCR2_SYNC_MASK;
  391. base->RCR2 = (val | I2S_RCR2_SYNC(3U));
  392. break;
  393. default:
  394. break;
  395. }
  396. }
  397. void SAI_Deinit(I2S_Type *base)
  398. {
  399. SAI_TxEnable(base, false);
  400. SAI_RxEnable(base, false);
  401. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  402. CLOCK_DisableClock(s_saiClock[SAI_GetInstance(base)]);
  403. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  404. }
  405. void SAI_TxGetDefaultConfig(sai_config_t *config)
  406. {
  407. config->bclkSource = kSAI_BclkSourceMclkDiv;
  408. config->masterSlave = kSAI_Master;
  409. config->mclkSource = kSAI_MclkSourceSysclk;
  410. config->protocol = kSAI_BusLeftJustified;
  411. config->syncMode = kSAI_ModeAsync;
  412. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  413. config->mclkOutputEnable = true;
  414. #endif /* FSL_FEATURE_SAI_HAS_MCR */
  415. }
  416. void SAI_RxGetDefaultConfig(sai_config_t *config)
  417. {
  418. config->bclkSource = kSAI_BclkSourceMclkDiv;
  419. config->masterSlave = kSAI_Master;
  420. config->mclkSource = kSAI_MclkSourceSysclk;
  421. config->protocol = kSAI_BusLeftJustified;
  422. config->syncMode = kSAI_ModeSync;
  423. #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
  424. config->mclkOutputEnable = true;
  425. #endif /* FSL_FEATURE_SAI_HAS_MCR */
  426. }
  427. void SAI_TxReset(I2S_Type *base)
  428. {
  429. /* Set the software reset and FIFO reset to clear internal state */
  430. base->TCSR = I2S_TCSR_SR_MASK | I2S_TCSR_FR_MASK;
  431. /* Clear software reset bit, this should be done by software */
  432. base->TCSR &= ~I2S_TCSR_SR_MASK;
  433. /* Reset all Tx register values */
  434. base->TCR2 = 0;
  435. base->TCR3 = 0;
  436. base->TCR4 = 0;
  437. base->TCR5 = 0;
  438. base->TMR = 0;
  439. }
  440. void SAI_RxReset(I2S_Type *base)
  441. {
  442. /* Set the software reset and FIFO reset to clear internal state */
  443. base->RCSR = I2S_RCSR_SR_MASK | I2S_RCSR_FR_MASK;
  444. /* Clear software reset bit, this should be done by software */
  445. base->RCSR &= ~I2S_RCSR_SR_MASK;
  446. /* Reset all Rx register values */
  447. base->RCR2 = 0;
  448. base->RCR3 = 0;
  449. base->RCR4 = 0;
  450. base->RCR5 = 0;
  451. base->RMR = 0;
  452. }
  453. void SAI_TxEnable(I2S_Type *base, bool enable)
  454. {
  455. if (enable)
  456. {
  457. /* If clock is sync with Rx, should enable RE bit. */
  458. if (((base->TCR2 & I2S_TCR2_SYNC_MASK) >> I2S_TCR2_SYNC_SHIFT) == 0x1U)
  459. {
  460. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
  461. }
  462. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
  463. /* Also need to clear the FIFO error flag before start */
  464. SAI_TxClearStatusFlags(base, kSAI_FIFOErrorFlag);
  465. }
  466. else
  467. {
  468. /* If RE not sync with TE, than disable TE, otherwise, shall not disable TE */
  469. if (((base->RCR2 & I2S_RCR2_SYNC_MASK) >> I2S_RCR2_SYNC_SHIFT) != 0x1U)
  470. {
  471. /* Should not close RE even sync with Rx */
  472. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) & (~I2S_TCSR_TE_MASK));
  473. }
  474. }
  475. }
  476. void SAI_RxEnable(I2S_Type *base, bool enable)
  477. {
  478. if (enable)
  479. {
  480. /* If clock is sync with Tx, should enable TE bit. */
  481. if (((base->RCR2 & I2S_RCR2_SYNC_MASK) >> I2S_RCR2_SYNC_SHIFT) == 0x1U)
  482. {
  483. base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
  484. }
  485. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
  486. /* Also need to clear the FIFO error flag before start */
  487. SAI_RxClearStatusFlags(base, kSAI_FIFOErrorFlag);
  488. }
  489. else
  490. {
  491. /* While TX is not sync with RX, close RX */
  492. if (((base->TCR2 & I2S_TCR2_SYNC_MASK) >> I2S_TCR2_SYNC_SHIFT) != 0x1U)
  493. {
  494. base->RCSR = ((base->RCSR & 0xFFE3FFFFU) & (~I2S_RCSR_RE_MASK));
  495. }
  496. }
  497. }
  498. void SAI_TxSoftwareReset(I2S_Type *base, sai_reset_type_t type)
  499. {
  500. base->TCSR |= (uint32_t)type;
  501. /* Clear the software reset */
  502. base->TCSR &= ~I2S_TCSR_SR_MASK;
  503. }
  504. void SAI_RxSoftwareReset(I2S_Type *base, sai_reset_type_t type)
  505. {
  506. base->RCSR |= (uint32_t)type;
  507. /* Clear the software reset */
  508. base->RCSR &= ~I2S_RCSR_SR_MASK;
  509. }
  510. void SAI_TxSetChannelFIFOMask(I2S_Type *base, uint8_t mask)
  511. {
  512. base->TCR3 &= ~I2S_TCR3_TCE_MASK;
  513. base->TCR3 |= I2S_TCR3_TCE(mask);
  514. }
  515. void SAI_RxSetChannelFIFOMask(I2S_Type *base, uint8_t mask)
  516. {
  517. base->RCR3 &= ~I2S_RCR3_RCE_MASK;
  518. base->RCR3 |= I2S_RCR3_RCE(mask);
  519. }
  520. void SAI_TxSetFormat(I2S_Type *base,
  521. sai_transfer_format_t *format,
  522. uint32_t mclkSourceClockHz,
  523. uint32_t bclkSourceClockHz)
  524. {
  525. uint32_t bclk = 0;
  526. uint32_t val = 0;
  527. uint32_t channels = 2U;
  528. if (format->stereo != kSAI_Stereo)
  529. {
  530. channels = 1U;
  531. }
  532. if (format->isFrameSyncCompact)
  533. {
  534. bclk = format->sampleRate_Hz * format->bitWidth * channels;
  535. val = (base->TCR4 & (~I2S_TCR4_SYWD_MASK));
  536. val |= I2S_TCR4_SYWD(format->bitWidth - 1U);
  537. base->TCR4 = val;
  538. }
  539. else
  540. {
  541. bclk = format->sampleRate_Hz * 32U * 2U;
  542. }
  543. /* Compute the mclk */
  544. #if defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER)
  545. /* Check if master clock divider enabled, then set master clock divider */
  546. if (base->MCR & I2S_MCR_MOE_MASK)
  547. {
  548. SAI_SetMasterClockDivider(base, format->masterClockHz, mclkSourceClockHz);
  549. }
  550. #endif /* FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER */
  551. /* Set bclk if needed */
  552. if (base->TCR2 & I2S_TCR2_BCD_MASK)
  553. {
  554. base->TCR2 &= ~I2S_TCR2_DIV_MASK;
  555. base->TCR2 |= I2S_TCR2_DIV((bclkSourceClockHz / bclk) / 2U - 1U);
  556. }
  557. /* Set bitWidth */
  558. val = (format->isFrameSyncCompact) ? (format->bitWidth - 1) : 31U;
  559. if (format->protocol == kSAI_BusRightJustified)
  560. {
  561. base->TCR5 = I2S_TCR5_WNW(val) | I2S_TCR5_W0W(val) | I2S_TCR5_FBT(val);
  562. }
  563. else
  564. {
  565. base->TCR5 = I2S_TCR5_WNW(val) | I2S_TCR5_W0W(val) | I2S_TCR5_FBT(format->bitWidth - 1);
  566. }
  567. /* Set mono or stereo */
  568. base->TMR = (uint32_t)format->stereo;
  569. /* Set data channel */
  570. base->TCR3 &= ~I2S_TCR3_TCE_MASK;
  571. base->TCR3 |= I2S_TCR3_TCE(1U << format->channel);
  572. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  573. /* Set watermark */
  574. base->TCR1 = format->watermark;
  575. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  576. }
  577. void SAI_RxSetFormat(I2S_Type *base,
  578. sai_transfer_format_t *format,
  579. uint32_t mclkSourceClockHz,
  580. uint32_t bclkSourceClockHz)
  581. {
  582. uint32_t bclk = 0;
  583. uint32_t val = 0;
  584. uint32_t channels = 2U;
  585. if (format->stereo != kSAI_Stereo)
  586. {
  587. channels = 1U;
  588. }
  589. if (format->isFrameSyncCompact)
  590. {
  591. bclk = format->sampleRate_Hz * format->bitWidth * channels;
  592. val = (base->RCR4 & (~I2S_RCR4_SYWD_MASK));
  593. val |= I2S_RCR4_SYWD(format->bitWidth - 1U);
  594. base->RCR4 = val;
  595. }
  596. else
  597. {
  598. bclk = format->sampleRate_Hz * 32U * 2U;
  599. }
  600. /* Compute the mclk */
  601. #if defined(FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER) && (FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER)
  602. /* Check if master clock divider enabled */
  603. if (base->MCR & I2S_MCR_MOE_MASK)
  604. {
  605. SAI_SetMasterClockDivider(base, format->masterClockHz, mclkSourceClockHz);
  606. }
  607. #endif /* FSL_FEATURE_SAI_HAS_MCLKDIV_REGISTER */
  608. /* Set bclk if needed */
  609. if (base->RCR2 & I2S_RCR2_BCD_MASK)
  610. {
  611. base->RCR2 &= ~I2S_RCR2_DIV_MASK;
  612. base->RCR2 |= I2S_RCR2_DIV((bclkSourceClockHz / bclk) / 2U - 1U);
  613. }
  614. /* Set bitWidth */
  615. val = (format->isFrameSyncCompact) ? (format->bitWidth - 1) : 31U;
  616. if (format->protocol == kSAI_BusRightJustified)
  617. {
  618. base->RCR5 = I2S_RCR5_WNW(val) | I2S_RCR5_W0W(val) | I2S_RCR5_FBT(val);
  619. }
  620. else
  621. {
  622. base->RCR5 = I2S_RCR5_WNW(val) | I2S_RCR5_W0W(val) | I2S_RCR5_FBT(format->bitWidth - 1);
  623. }
  624. /* Set mono or stereo */
  625. base->RMR = (uint32_t)format->stereo;
  626. /* Set data channel */
  627. base->RCR3 &= ~I2S_RCR3_RCE_MASK;
  628. base->RCR3 |= I2S_RCR3_RCE(1U << format->channel);
  629. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  630. /* Set watermark */
  631. base->RCR1 = format->watermark;
  632. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  633. }
  634. void SAI_WriteBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
  635. {
  636. uint32_t i = 0;
  637. uint8_t bytesPerWord = bitWidth / 8U;
  638. while (i < size)
  639. {
  640. /* Wait until it can write data */
  641. while (!(base->TCSR & I2S_TCSR_FWF_MASK))
  642. {
  643. }
  644. SAI_WriteNonBlocking(base, channel, bitWidth, buffer, bytesPerWord);
  645. buffer += bytesPerWord;
  646. i += bytesPerWord;
  647. }
  648. /* Wait until the last data is sent */
  649. while (!(base->TCSR & I2S_TCSR_FWF_MASK))
  650. {
  651. }
  652. }
  653. void SAI_ReadBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
  654. {
  655. uint32_t i = 0;
  656. uint8_t bytesPerWord = bitWidth / 8U;
  657. while (i < size)
  658. {
  659. /* Wait until data is received */
  660. while (!(base->RCSR & I2S_RCSR_FWF_MASK))
  661. {
  662. }
  663. SAI_ReadNonBlocking(base, channel, bitWidth, buffer, bytesPerWord);
  664. buffer += bytesPerWord;
  665. i += bytesPerWord;
  666. }
  667. }
  668. void SAI_TransferTxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData)
  669. {
  670. assert(handle);
  671. /* Zero the handle */
  672. memset(handle, 0, sizeof(*handle));
  673. s_saiHandle[SAI_GetInstance(base)][0] = handle;
  674. handle->callback = callback;
  675. handle->userData = userData;
  676. /* Set the isr pointer */
  677. s_saiTxIsr = SAI_TransferTxHandleIRQ;
  678. /* Enable Tx irq */
  679. EnableIRQ(s_saiTxIRQ[SAI_GetInstance(base)]);
  680. }
  681. void SAI_TransferRxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData)
  682. {
  683. assert(handle);
  684. /* Zero the handle */
  685. memset(handle, 0, sizeof(*handle));
  686. s_saiHandle[SAI_GetInstance(base)][1] = handle;
  687. handle->callback = callback;
  688. handle->userData = userData;
  689. /* Set the isr pointer */
  690. s_saiRxIsr = SAI_TransferRxHandleIRQ;
  691. /* Enable Rx irq */
  692. EnableIRQ(s_saiRxIRQ[SAI_GetInstance(base)]);
  693. }
  694. status_t SAI_TransferTxSetFormat(I2S_Type *base,
  695. sai_handle_t *handle,
  696. sai_transfer_format_t *format,
  697. uint32_t mclkSourceClockHz,
  698. uint32_t bclkSourceClockHz)
  699. {
  700. assert(handle);
  701. if ((mclkSourceClockHz < format->sampleRate_Hz) || (bclkSourceClockHz < format->sampleRate_Hz))
  702. {
  703. return kStatus_InvalidArgument;
  704. }
  705. /* Copy format to handle */
  706. handle->bitWidth = format->bitWidth;
  707. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  708. handle->watermark = format->watermark;
  709. #endif
  710. handle->channel = format->channel;
  711. SAI_TxSetFormat(base, format, mclkSourceClockHz, bclkSourceClockHz);
  712. return kStatus_Success;
  713. }
  714. status_t SAI_TransferRxSetFormat(I2S_Type *base,
  715. sai_handle_t *handle,
  716. sai_transfer_format_t *format,
  717. uint32_t mclkSourceClockHz,
  718. uint32_t bclkSourceClockHz)
  719. {
  720. assert(handle);
  721. if ((mclkSourceClockHz < format->sampleRate_Hz) || (bclkSourceClockHz < format->sampleRate_Hz))
  722. {
  723. return kStatus_InvalidArgument;
  724. }
  725. /* Copy format to handle */
  726. handle->bitWidth = format->bitWidth;
  727. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  728. handle->watermark = format->watermark;
  729. #endif
  730. handle->channel = format->channel;
  731. SAI_RxSetFormat(base, format, mclkSourceClockHz, bclkSourceClockHz);
  732. return kStatus_Success;
  733. }
  734. status_t SAI_TransferSendNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer)
  735. {
  736. assert(handle);
  737. /* Check if the queue is full */
  738. if (handle->saiQueue[handle->queueUser].data)
  739. {
  740. return kStatus_SAI_QueueFull;
  741. }
  742. /* Add into queue */
  743. handle->transferSize[handle->queueUser] = xfer->dataSize;
  744. handle->saiQueue[handle->queueUser].data = xfer->data;
  745. handle->saiQueue[handle->queueUser].dataSize = xfer->dataSize;
  746. handle->queueUser = (handle->queueUser + 1) % SAI_XFER_QUEUE_SIZE;
  747. /* Set the state to busy */
  748. handle->state = kSAI_Busy;
  749. /* Enable interrupt */
  750. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  751. /* Use FIFO request interrupt and fifo error*/
  752. SAI_TxEnableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFORequestInterruptEnable);
  753. #else
  754. SAI_TxEnableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFOWarningInterruptEnable);
  755. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  756. /* Enable Tx transfer */
  757. SAI_TxEnable(base, true);
  758. return kStatus_Success;
  759. }
  760. status_t SAI_TransferReceiveNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer)
  761. {
  762. assert(handle);
  763. /* Check if the queue is full */
  764. if (handle->saiQueue[handle->queueUser].data)
  765. {
  766. return kStatus_SAI_QueueFull;
  767. }
  768. /* Add into queue */
  769. handle->transferSize[handle->queueUser] = xfer->dataSize;
  770. handle->saiQueue[handle->queueUser].data = xfer->data;
  771. handle->saiQueue[handle->queueUser].dataSize = xfer->dataSize;
  772. handle->queueUser = (handle->queueUser + 1) % SAI_XFER_QUEUE_SIZE;
  773. /* Set state to busy */
  774. handle->state = kSAI_Busy;
  775. /* Enable interrupt */
  776. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  777. /* Use FIFO request interrupt and fifo error*/
  778. SAI_RxEnableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFORequestInterruptEnable);
  779. #else
  780. SAI_RxEnableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFOWarningInterruptEnable);
  781. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  782. /* Enable Rx transfer */
  783. SAI_RxEnable(base, true);
  784. return kStatus_Success;
  785. }
  786. status_t SAI_TransferGetSendCount(I2S_Type *base, sai_handle_t *handle, size_t *count)
  787. {
  788. assert(handle);
  789. status_t status = kStatus_Success;
  790. if (handle->state != kSAI_Busy)
  791. {
  792. status = kStatus_NoTransferInProgress;
  793. }
  794. else
  795. {
  796. *count = (handle->transferSize[handle->queueDriver] - handle->saiQueue[handle->queueDriver].dataSize);
  797. }
  798. return status;
  799. }
  800. status_t SAI_TransferGetReceiveCount(I2S_Type *base, sai_handle_t *handle, size_t *count)
  801. {
  802. assert(handle);
  803. status_t status = kStatus_Success;
  804. if (handle->state != kSAI_Busy)
  805. {
  806. status = kStatus_NoTransferInProgress;
  807. }
  808. else
  809. {
  810. *count = (handle->transferSize[handle->queueDriver] - handle->saiQueue[handle->queueDriver].dataSize);
  811. }
  812. return status;
  813. }
  814. void SAI_TransferAbortSend(I2S_Type *base, sai_handle_t *handle)
  815. {
  816. assert(handle);
  817. /* Stop Tx transfer and disable interrupt */
  818. SAI_TxEnable(base, false);
  819. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  820. /* Use FIFO request interrupt and fifo error */
  821. SAI_TxDisableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFORequestInterruptEnable);
  822. #else
  823. SAI_TxDisableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFOWarningInterruptEnable);
  824. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  825. handle->state = kSAI_Idle;
  826. /* Clear the queue */
  827. memset(handle->saiQueue, 0, sizeof(sai_transfer_t) * SAI_XFER_QUEUE_SIZE);
  828. handle->queueDriver = 0;
  829. handle->queueUser = 0;
  830. }
  831. void SAI_TransferAbortReceive(I2S_Type *base, sai_handle_t *handle)
  832. {
  833. assert(handle);
  834. /* Stop Tx transfer and disable interrupt */
  835. SAI_RxEnable(base, false);
  836. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  837. /* Use FIFO request interrupt and fifo error */
  838. SAI_RxDisableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFORequestInterruptEnable);
  839. #else
  840. SAI_RxDisableInterrupts(base, kSAI_FIFOErrorInterruptEnable | kSAI_FIFOWarningInterruptEnable);
  841. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  842. handle->state = kSAI_Idle;
  843. /* Clear the queue */
  844. memset(handle->saiQueue, 0, sizeof(sai_transfer_t) * SAI_XFER_QUEUE_SIZE);
  845. handle->queueDriver = 0;
  846. handle->queueUser = 0;
  847. }
  848. void SAI_TransferTerminateSend(I2S_Type *base, sai_handle_t *handle)
  849. {
  850. assert(handle);
  851. /* Abort the current transfer */
  852. SAI_TransferAbortSend(base, handle);
  853. /* Clear all the internal information */
  854. memset(handle->saiQueue, 0U, sizeof(handle->saiQueue));
  855. memset(handle->transferSize, 0U, sizeof(handle->transferSize));
  856. handle->queueUser = 0U;
  857. handle->queueDriver = 0U;
  858. }
  859. void SAI_TransferTerminateReceive(I2S_Type *base, sai_handle_t *handle)
  860. {
  861. assert(handle);
  862. /* Abort the current transfer */
  863. SAI_TransferAbortReceive(base, handle);
  864. /* Clear all the internal information */
  865. memset(handle->saiQueue, 0U, sizeof(handle->saiQueue));
  866. memset(handle->transferSize, 0U, sizeof(handle->transferSize));
  867. handle->queueUser = 0U;
  868. handle->queueDriver = 0U;
  869. }
  870. void SAI_TransferTxHandleIRQ(I2S_Type *base, sai_handle_t *handle)
  871. {
  872. assert(handle);
  873. uint8_t *buffer = handle->saiQueue[handle->queueDriver].data;
  874. uint8_t dataSize = handle->bitWidth / 8U;
  875. /* Handle Error */
  876. if (base->TCSR & I2S_TCSR_FEF_MASK)
  877. {
  878. /* Clear FIFO error flag to continue transfer */
  879. SAI_TxClearStatusFlags(base, kSAI_FIFOErrorFlag);
  880. /* Reset FIFO for safety */
  881. SAI_TxSoftwareReset(base, kSAI_ResetTypeFIFO);
  882. /* Call the callback */
  883. if (handle->callback)
  884. {
  885. (handle->callback)(base, handle, kStatus_SAI_TxError, handle->userData);
  886. }
  887. }
  888. /* Handle transfer */
  889. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  890. if (base->TCSR & I2S_TCSR_FRF_MASK)
  891. {
  892. /* Judge if the data need to transmit is less than space */
  893. uint8_t size = MIN((handle->saiQueue[handle->queueDriver].dataSize),
  894. (size_t)((FSL_FEATURE_SAI_FIFO_COUNT - handle->watermark) * dataSize));
  895. /* Copy the data from sai buffer to FIFO */
  896. SAI_WriteNonBlocking(base, handle->channel, handle->bitWidth, buffer, size);
  897. /* Update the internal counter */
  898. handle->saiQueue[handle->queueDriver].dataSize -= size;
  899. handle->saiQueue[handle->queueDriver].data += size;
  900. }
  901. #else
  902. if (base->TCSR & I2S_TCSR_FWF_MASK)
  903. {
  904. uint8_t size = MIN((handle->saiQueue[handle->queueDriver].dataSize), dataSize);
  905. SAI_WriteNonBlocking(base, handle->channel, handle->bitWidth, buffer, size);
  906. /* Update internal counter */
  907. handle->saiQueue[handle->queueDriver].dataSize -= size;
  908. handle->saiQueue[handle->queueDriver].data += size;
  909. }
  910. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  911. /* If finished a blcok, call the callback function */
  912. if (handle->saiQueue[handle->queueDriver].dataSize == 0U)
  913. {
  914. memset(&handle->saiQueue[handle->queueDriver], 0, sizeof(sai_transfer_t));
  915. handle->queueDriver = (handle->queueDriver + 1) % SAI_XFER_QUEUE_SIZE;
  916. if (handle->callback)
  917. {
  918. (handle->callback)(base, handle, kStatus_SAI_TxIdle, handle->userData);
  919. }
  920. }
  921. /* If all data finished, just stop the transfer */
  922. if (handle->saiQueue[handle->queueDriver].data == NULL)
  923. {
  924. SAI_TransferAbortSend(base, handle);
  925. }
  926. }
  927. void SAI_TransferRxHandleIRQ(I2S_Type *base, sai_handle_t *handle)
  928. {
  929. assert(handle);
  930. uint8_t *buffer = handle->saiQueue[handle->queueDriver].data;
  931. uint8_t dataSize = handle->bitWidth / 8U;
  932. /* Handle Error */
  933. if (base->RCSR & I2S_RCSR_FEF_MASK)
  934. {
  935. /* Clear FIFO error flag to continue transfer */
  936. SAI_RxClearStatusFlags(base, kSAI_FIFOErrorFlag);
  937. /* Reset FIFO for safety */
  938. SAI_RxSoftwareReset(base, kSAI_ResetTypeFIFO);
  939. /* Call the callback */
  940. if (handle->callback)
  941. {
  942. (handle->callback)(base, handle, kStatus_SAI_RxError, handle->userData);
  943. }
  944. }
  945. /* Handle transfer */
  946. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  947. if (base->RCSR & I2S_RCSR_FRF_MASK)
  948. {
  949. /* Judge if the data need to transmit is less than space */
  950. uint8_t size = MIN((handle->saiQueue[handle->queueDriver].dataSize), (handle->watermark * dataSize));
  951. /* Copy the data from sai buffer to FIFO */
  952. SAI_ReadNonBlocking(base, handle->channel, handle->bitWidth, buffer, size);
  953. /* Update the internal counter */
  954. handle->saiQueue[handle->queueDriver].dataSize -= size;
  955. handle->saiQueue[handle->queueDriver].data += size;
  956. }
  957. #else
  958. if (base->RCSR & I2S_RCSR_FWF_MASK)
  959. {
  960. uint8_t size = MIN((handle->saiQueue[handle->queueDriver].dataSize), dataSize);
  961. SAI_ReadNonBlocking(base, handle->channel, handle->bitWidth, buffer, size);
  962. /* Update internal state */
  963. handle->saiQueue[handle->queueDriver].dataSize -= size;
  964. handle->saiQueue[handle->queueDriver].data += size;
  965. }
  966. #endif /* FSL_FEATURE_SAI_FIFO_COUNT */
  967. /* If finished a blcok, call the callback function */
  968. if (handle->saiQueue[handle->queueDriver].dataSize == 0U)
  969. {
  970. memset(&handle->saiQueue[handle->queueDriver], 0, sizeof(sai_transfer_t));
  971. handle->queueDriver = (handle->queueDriver + 1) % SAI_XFER_QUEUE_SIZE;
  972. if (handle->callback)
  973. {
  974. (handle->callback)(base, handle, kStatus_SAI_RxIdle, handle->userData);
  975. }
  976. }
  977. /* If all data finished, just stop the transfer */
  978. if (handle->saiQueue[handle->queueDriver].data == NULL)
  979. {
  980. SAI_TransferAbortReceive(base, handle);
  981. }
  982. }
  983. #if defined(I2S0)
  984. void I2S0_DriverIRQHandler(void)
  985. {
  986. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  987. if ((s_saiHandle[0][1]) && ((I2S0->RCSR & kSAI_FIFORequestFlag) || (I2S0->RCSR & kSAI_FIFOErrorFlag)) &&
  988. ((I2S0->RCSR & kSAI_FIFORequestInterruptEnable) || (I2S0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  989. #else
  990. if ((s_saiHandle[0][1]) && ((I2S0->RCSR & kSAI_FIFOWarningFlag) || (I2S0->RCSR & kSAI_FIFOErrorFlag)) &&
  991. ((I2S0->RCSR & kSAI_FIFOWarningInterruptEnable) || (I2S0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  992. #endif
  993. {
  994. s_saiRxIsr(I2S0, s_saiHandle[0][1]);
  995. }
  996. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  997. if ((s_saiHandle[0][0]) && ((I2S0->TCSR & kSAI_FIFORequestFlag) || (I2S0->TCSR & kSAI_FIFOErrorFlag)) &&
  998. ((I2S0->TCSR & kSAI_FIFORequestInterruptEnable) || (I2S0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  999. #else
  1000. if ((s_saiHandle[0][0]) && ((I2S0->TCSR & kSAI_FIFOWarningFlag) || (I2S0->TCSR & kSAI_FIFOErrorFlag)) &&
  1001. ((I2S0->TCSR & kSAI_FIFOWarningInterruptEnable) || (I2S0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1002. #endif
  1003. {
  1004. s_saiTxIsr(I2S0, s_saiHandle[0][0]);
  1005. }
  1006. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1007. exception return operation might vector to incorrect interrupt */
  1008. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1009. __DSB();
  1010. #endif
  1011. }
  1012. void I2S0_Tx_DriverIRQHandler(void)
  1013. {
  1014. assert(s_saiHandle[0][0]);
  1015. s_saiTxIsr(I2S0, s_saiHandle[0][0]);
  1016. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1017. exception return operation might vector to incorrect interrupt */
  1018. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1019. __DSB();
  1020. #endif
  1021. }
  1022. void I2S0_Rx_DriverIRQHandler(void)
  1023. {
  1024. assert(s_saiHandle[0][1]);
  1025. s_saiRxIsr(I2S0, s_saiHandle[0][1]);
  1026. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1027. exception return operation might vector to incorrect interrupt */
  1028. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1029. __DSB();
  1030. #endif
  1031. }
  1032. #endif /* I2S0*/
  1033. #if defined(I2S1)
  1034. void I2S1_DriverIRQHandler(void)
  1035. {
  1036. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1037. if ((s_saiHandle[1][1]) && ((I2S1->RCSR & kSAI_FIFORequestFlag) || (I2S1->RCSR & kSAI_FIFOErrorFlag)) &&
  1038. ((I2S1->RCSR & kSAI_FIFORequestInterruptEnable) || (I2S1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1039. #else
  1040. if ((s_saiHandle[1][1]) && ((I2S1->RCSR & kSAI_FIFOWarningFlag) || (I2S1->RCSR & kSAI_FIFOErrorFlag)) &&
  1041. ((I2S1->RCSR & kSAI_FIFOWarningInterruptEnable) || (I2S1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1042. #endif
  1043. {
  1044. s_saiRxIsr(I2S1, s_saiHandle[1][1]);
  1045. }
  1046. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1047. if ((s_saiHandle[1][0]) && ((I2S1->TCSR & kSAI_FIFORequestFlag) || (I2S1->TCSR & kSAI_FIFOErrorFlag)) &&
  1048. ((I2S1->TCSR & kSAI_FIFORequestInterruptEnable) || (I2S1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1049. #else
  1050. if ((s_saiHandle[1][0]) && ((I2S1->TCSR & kSAI_FIFOWarningFlag) || (I2S1->TCSR & kSAI_FIFOErrorFlag)) &&
  1051. ((I2S1->TCSR & kSAI_FIFOWarningInterruptEnable) || (I2S1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1052. #endif
  1053. {
  1054. s_saiTxIsr(I2S1, s_saiHandle[1][0]);
  1055. }
  1056. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1057. exception return operation might vector to incorrect interrupt */
  1058. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1059. __DSB();
  1060. #endif
  1061. }
  1062. void I2S1_Tx_DriverIRQHandler(void)
  1063. {
  1064. assert(s_saiHandle[1][0]);
  1065. s_saiTxIsr(I2S1, s_saiHandle[1][0]);
  1066. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1067. exception return operation might vector to incorrect interrupt */
  1068. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1069. __DSB();
  1070. #endif
  1071. }
  1072. void I2S1_Rx_DriverIRQHandler(void)
  1073. {
  1074. assert(s_saiHandle[1][1]);
  1075. s_saiRxIsr(I2S1, s_saiHandle[1][1]);
  1076. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1077. exception return operation might vector to incorrect interrupt */
  1078. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1079. __DSB();
  1080. #endif
  1081. }
  1082. #endif /* I2S1*/
  1083. #if defined(I2S2)
  1084. void I2S2_DriverIRQHandler(void)
  1085. {
  1086. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1087. if ((s_saiHandle[2][1]) && ((I2S2->RCSR & kSAI_FIFORequestFlag) || (I2S2->RCSR & kSAI_FIFOErrorFlag)) &&
  1088. ((I2S2->RCSR & kSAI_FIFORequestInterruptEnable) || (I2S2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1089. #else
  1090. if ((s_saiHandle[2][1]) && ((I2S2->RCSR & kSAI_FIFOWarningFlag) || (I2S2->RCSR & kSAI_FIFOErrorFlag)) &&
  1091. ((I2S2->RCSR & kSAI_FIFOWarningInterruptEnable) || (I2S2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1092. #endif
  1093. {
  1094. s_saiRxIsr(I2S2, s_saiHandle[2][1]);
  1095. }
  1096. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1097. if ((s_saiHandle[2][0]) && ((I2S2->TCSR & kSAI_FIFORequestFlag) || (I2S2->TCSR & kSAI_FIFOErrorFlag)) &&
  1098. ((I2S2->TCSR & kSAI_FIFORequestInterruptEnable) || (I2S2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1099. #else
  1100. if ((s_saiHandle[2][0]) && ((I2S2->TCSR & kSAI_FIFOWarningFlag) || (I2S2->TCSR & kSAI_FIFOErrorFlag)) &&
  1101. ((I2S2->TCSR & kSAI_FIFOWarningInterruptEnable) || (I2S2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1102. #endif
  1103. {
  1104. s_saiTxIsr(I2S2, s_saiHandle[2][0]);
  1105. }
  1106. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1107. exception return operation might vector to incorrect interrupt */
  1108. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1109. __DSB();
  1110. #endif
  1111. }
  1112. void I2S2_Tx_DriverIRQHandler(void)
  1113. {
  1114. assert(s_saiHandle[2][0]);
  1115. s_saiTxIsr(I2S2, s_saiHandle[2][0]);
  1116. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1117. exception return operation might vector to incorrect interrupt */
  1118. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1119. __DSB();
  1120. #endif
  1121. }
  1122. void I2S2_Rx_DriverIRQHandler(void)
  1123. {
  1124. assert(s_saiHandle[2][1]);
  1125. s_saiRxIsr(I2S2, s_saiHandle[2][1]);
  1126. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1127. exception return operation might vector to incorrect interrupt */
  1128. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1129. __DSB();
  1130. #endif
  1131. }
  1132. #endif /* I2S2*/
  1133. #if defined(I2S3)
  1134. void I2S3_DriverIRQHandler(void)
  1135. {
  1136. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1137. if ((s_saiHandle[3][1]) && ((I2S3->RCSR & kSAI_FIFORequestFlag) || (I2S3->RCSR & kSAI_FIFOErrorFlag)) &&
  1138. ((I2S3->RCSR & kSAI_FIFORequestInterruptEnable) || (I2S3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1139. #else
  1140. if ((s_saiHandle[3][1]) && ((I2S3->RCSR & kSAI_FIFOWarningFlag) || (I2S3->RCSR & kSAI_FIFOErrorFlag)) &&
  1141. ((I2S3->RCSR & kSAI_FIFOWarningInterruptEnable) || (I2S3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1142. #endif
  1143. {
  1144. s_saiRxIsr(I2S3, s_saiHandle[3][1]);
  1145. }
  1146. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1147. if ((s_saiHandle[3][0]) && ((I2S3->TCSR & kSAI_FIFORequestFlag) || (I2S3->TCSR & kSAI_FIFOErrorFlag)) &&
  1148. ((I2S3->TCSR & kSAI_FIFORequestInterruptEnable) || (I2S3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1149. #else
  1150. if ((s_saiHandle[3][0]) && ((I2S3->TCSR & kSAI_FIFOWarningFlag) || (I2S3->TCSR & kSAI_FIFOErrorFlag)) &&
  1151. ((I2S3->TCSR & kSAI_FIFOWarningInterruptEnable) || (I2S3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1152. #endif
  1153. {
  1154. s_saiTxIsr(I2S3, s_saiHandle[3][0]);
  1155. }
  1156. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1157. exception return operation might vector to incorrect interrupt */
  1158. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1159. __DSB();
  1160. #endif
  1161. }
  1162. void I2S3_Tx_DriverIRQHandler(void)
  1163. {
  1164. assert(s_saiHandle[3][0]);
  1165. s_saiTxIsr(I2S3, s_saiHandle[3][0]);
  1166. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1167. exception return operation might vector to incorrect interrupt */
  1168. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1169. __DSB();
  1170. #endif
  1171. }
  1172. void I2S3_Rx_DriverIRQHandler(void)
  1173. {
  1174. assert(s_saiHandle[3][1]);
  1175. s_saiRxIsr(I2S3, s_saiHandle[3][1]);
  1176. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1177. exception return operation might vector to incorrect interrupt */
  1178. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1179. __DSB();
  1180. #endif
  1181. }
  1182. #endif /* I2S3*/
  1183. #if defined(AUDIO__SAI0)
  1184. void AUDIO_SAI0_INT_DriverIRQHandler(void)
  1185. {
  1186. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1187. if ((s_saiHandle[0][1]) &&
  1188. ((AUDIO__SAI0->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI0->RCSR & kSAI_FIFOErrorFlag)) &&
  1189. ((AUDIO__SAI0->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1190. #else
  1191. if ((s_saiHandle[0][1]) &&
  1192. ((AUDIO__SAI0->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI0->RCSR & kSAI_FIFOErrorFlag)) &&
  1193. ((AUDIO__SAI0->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1194. #endif
  1195. {
  1196. s_saiRxIsr(AUDIO__SAI0, s_saiHandle[0][1]);
  1197. }
  1198. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1199. if ((s_saiHandle[0][0]) &&
  1200. ((AUDIO__SAI0->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI0->TCSR & kSAI_FIFOErrorFlag)) &&
  1201. ((AUDIO__SAI0->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1202. #else
  1203. if ((s_saiHandle[0][0]) &&
  1204. ((AUDIO__SAI0->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI0->TCSR & kSAI_FIFOErrorFlag)) &&
  1205. ((AUDIO__SAI0->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1206. #endif
  1207. {
  1208. s_saiTxIsr(AUDIO__SAI0, s_saiHandle[0][0]);
  1209. }
  1210. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1211. exception return operation might vector to incorrect interrupt */
  1212. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1213. __DSB();
  1214. #endif
  1215. }
  1216. #endif /* AUDIO__SAI0 */
  1217. #if defined(AUDIO__SAI1)
  1218. void AUDIO_SAI1_INT_DriverIRQHandler(void)
  1219. {
  1220. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1221. if ((s_saiHandle[1][1]) &&
  1222. ((AUDIO__SAI1->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI1->RCSR & kSAI_FIFOErrorFlag)) &&
  1223. ((AUDIO__SAI1->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1224. #else
  1225. if ((s_saiHandle[1][1]) &&
  1226. ((AUDIO__SAI1->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI1->RCSR & kSAI_FIFOErrorFlag)) &&
  1227. ((AUDIO__SAI1->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1228. #endif
  1229. {
  1230. s_saiRxIsr(AUDIO__SAI1, s_saiHandle[1][1]);
  1231. }
  1232. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1233. if ((s_saiHandle[1][0]) &&
  1234. ((AUDIO__SAI1->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI1->TCSR & kSAI_FIFOErrorFlag)) &&
  1235. ((AUDIO__SAI1->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1236. #else
  1237. if ((s_saiHandle[1][0]) &&
  1238. ((AUDIO__SAI1->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI1->TCSR & kSAI_FIFOErrorFlag)) &&
  1239. ((AUDIO__SAI1->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1240. #endif
  1241. {
  1242. s_saiTxIsr(AUDIO__SAI1, s_saiHandle[1][0]);
  1243. }
  1244. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1245. exception return operation might vector to incorrect interrupt */
  1246. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1247. __DSB();
  1248. #endif
  1249. }
  1250. #endif /* AUDIO__SAI1 */
  1251. #if defined(AUDIO__SAI2)
  1252. void AUDIO_SAI2_INT_DriverIRQHandler(void)
  1253. {
  1254. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1255. if ((s_saiHandle[2][1]) &&
  1256. ((AUDIO__SAI2->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI2->RCSR & kSAI_FIFOErrorFlag)) &&
  1257. ((AUDIO__SAI2->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1258. #else
  1259. if ((s_saiHandle[2][1]) &&
  1260. ((AUDIO__SAI2->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI2->RCSR & kSAI_FIFOErrorFlag)) &&
  1261. ((AUDIO__SAI2->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1262. #endif
  1263. {
  1264. s_saiRxIsr(AUDIO__SAI2, s_saiHandle[2][1]);
  1265. }
  1266. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1267. if ((s_saiHandle[2][0]) &&
  1268. ((AUDIO__SAI2->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI2->TCSR & kSAI_FIFOErrorFlag)) &&
  1269. ((AUDIO__SAI2->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1270. #else
  1271. if ((s_saiHandle[2][0]) &&
  1272. ((AUDIO__SAI2->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI2->TCSR & kSAI_FIFOErrorFlag)) &&
  1273. ((AUDIO__SAI2->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1274. #endif
  1275. {
  1276. s_saiTxIsr(AUDIO__SAI2, s_saiHandle[2][0]);
  1277. }
  1278. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1279. exception return operation might vector to incorrect interrupt */
  1280. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1281. __DSB();
  1282. #endif
  1283. }
  1284. #endif /* AUDIO__SAI2 */
  1285. #if defined(AUDIO__SAI3)
  1286. void AUDIO_SAI3_INT_DriverIRQHandler(void)
  1287. {
  1288. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1289. if ((s_saiHandle[3][1]) &&
  1290. ((AUDIO__SAI3->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI3->RCSR & kSAI_FIFOErrorFlag)) &&
  1291. ((AUDIO__SAI3->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1292. #else
  1293. if ((s_saiHandle[3][1]) &&
  1294. ((AUDIO__SAI3->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI3->RCSR & kSAI_FIFOErrorFlag)) &&
  1295. ((AUDIO__SAI3->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1296. #endif
  1297. {
  1298. s_saiRxIsr(AUDIO__SAI3, s_saiHandle[3][1]);
  1299. }
  1300. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1301. if ((s_saiHandle[3][0]) &&
  1302. ((AUDIO__SAI3->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI3->TCSR & kSAI_FIFOErrorFlag)) &&
  1303. ((AUDIO__SAI3->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1304. #else
  1305. if ((s_saiHandle[3][0]) &&
  1306. ((AUDIO__SAI3->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI3->TCSR & kSAI_FIFOErrorFlag)) &&
  1307. ((AUDIO__SAI3->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1308. #endif
  1309. {
  1310. s_saiTxIsr(AUDIO__SAI3, s_saiHandle[3][0]);
  1311. }
  1312. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1313. exception return operation might vector to incorrect interrupt */
  1314. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1315. __DSB();
  1316. #endif
  1317. }
  1318. #endif
  1319. #if defined(AUDIO__SAI6)
  1320. void AUDIO_SAI6_INT_DriverIRQHandler(void)
  1321. {
  1322. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1323. if ((s_saiHandle[6][1]) &&
  1324. ((AUDIO__SAI6->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI6->RCSR & kSAI_FIFOErrorFlag)) &&
  1325. ((AUDIO__SAI6->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI6->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1326. #else
  1327. if ((s_saiHandle[6][1]) &&
  1328. ((AUDIO__SAI6->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI6->RCSR & kSAI_FIFOErrorFlag)) &&
  1329. ((AUDIO__SAI6->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI6->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1330. #endif
  1331. {
  1332. s_saiRxIsr(AUDIO__SAI6, s_saiHandle[6][1]);
  1333. }
  1334. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1335. if ((s_saiHandle[6][0]) &&
  1336. ((AUDIO__SAI6->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI6->TCSR & kSAI_FIFOErrorFlag)) &&
  1337. ((AUDIO__SAI6->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI6->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1338. #else
  1339. if ((s_saiHandle[6][0]) &&
  1340. ((AUDIO__SAI6->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI6->TCSR & kSAI_FIFOErrorFlag)) &&
  1341. ((AUDIO__SAI6->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI6->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1342. #endif
  1343. {
  1344. s_saiTxIsr(AUDIO__SAI6, s_saiHandle[6][0]);
  1345. }
  1346. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1347. exception return operation might vector to incorrect interrupt */
  1348. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1349. __DSB();
  1350. #endif
  1351. }
  1352. #endif /* AUDIO__SAI6 */
  1353. #if defined(AUDIO__SAI7)
  1354. void AUDIO_SAI7_INT_DriverIRQHandler(void)
  1355. {
  1356. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1357. if ((s_saiHandle[7][1]) &&
  1358. ((AUDIO__SAI7->RCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI7->RCSR & kSAI_FIFOErrorFlag)) &&
  1359. ((AUDIO__SAI7->RCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI7->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1360. #else
  1361. if ((s_saiHandle[7][1]) &&
  1362. ((AUDIO__SAI7->RCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI7->RCSR & kSAI_FIFOErrorFlag)) &&
  1363. ((AUDIO__SAI7->RCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI7->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1364. #endif
  1365. {
  1366. s_saiRxIsr(AUDIO__SAI7, s_saiHandle[7][1]);
  1367. }
  1368. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1369. if ((s_saiHandle[7][0]) &&
  1370. ((AUDIO__SAI7->TCSR & kSAI_FIFORequestFlag) || (AUDIO__SAI7->TCSR & kSAI_FIFOErrorFlag)) &&
  1371. ((AUDIO__SAI7->TCSR & kSAI_FIFORequestInterruptEnable) || (AUDIO__SAI7->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1372. #else
  1373. if ((s_saiHandle[7][0]) &&
  1374. ((AUDIO__SAI7->TCSR & kSAI_FIFOWarningFlag) || (AUDIO__SAI7->TCSR & kSAI_FIFOErrorFlag)) &&
  1375. ((AUDIO__SAI7->TCSR & kSAI_FIFOWarningInterruptEnable) || (AUDIO__SAI7->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1376. #endif
  1377. {
  1378. s_saiTxIsr(AUDIO__SAI7, s_saiHandle[7][0]);
  1379. }
  1380. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1381. exception return operation might vector to incorrect interrupt */
  1382. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1383. __DSB();
  1384. #endif
  1385. }
  1386. #endif /* AUDIO__SAI7 */
  1387. #if defined(SAI0)
  1388. void SAI0_DriverIRQHandler(void)
  1389. {
  1390. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1391. if ((s_saiHandle[0][1]) && ((SAI0->RCSR & kSAI_FIFORequestFlag) || (SAI0->RCSR & kSAI_FIFOErrorFlag)) &&
  1392. ((SAI0->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1393. #else
  1394. if ((s_saiHandle[0][1]) && ((SAI0->RCSR & kSAI_FIFOWarningFlag) || (SAI0->RCSR & kSAI_FIFOErrorFlag)) &&
  1395. ((SAI0->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI0->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1396. #endif
  1397. {
  1398. s_saiRxIsr(SAI0, s_saiHandle[0][1]);
  1399. }
  1400. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1401. if ((s_saiHandle[0][0]) && ((SAI0->TCSR & kSAI_FIFORequestFlag) || (SAI0->TCSR & kSAI_FIFOErrorFlag)) &&
  1402. ((SAI0->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1403. #else
  1404. if ((s_saiHandle[0][0]) && ((SAI0->TCSR & kSAI_FIFOWarningFlag) || (SAI0->TCSR & kSAI_FIFOErrorFlag)) &&
  1405. ((SAI0->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI0->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1406. #endif
  1407. {
  1408. s_saiTxIsr(AUDIO__SAI0, s_saiHandle[0][0]);
  1409. }
  1410. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1411. exception return operation might vector to incorrect interrupt */
  1412. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1413. __DSB();
  1414. #endif
  1415. }
  1416. #endif /* SAI0 */
  1417. #if defined(SAI1)
  1418. void SAI1_DriverIRQHandler(void)
  1419. {
  1420. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1421. if ((s_saiHandle[1][1]) && ((SAI1->RCSR & kSAI_FIFORequestFlag) || (SAI1->RCSR & kSAI_FIFOErrorFlag)) &&
  1422. ((SAI1->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1423. #else
  1424. if ((s_saiHandle[1][1]) && ((SAI1->RCSR & kSAI_FIFOWarningFlag) || (SAI1->RCSR & kSAI_FIFOErrorFlag)) &&
  1425. ((SAI1->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI1->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1426. #endif
  1427. {
  1428. s_saiRxIsr(SAI1, s_saiHandle[1][1]);
  1429. }
  1430. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1431. if ((s_saiHandle[1][0]) && ((SAI1->TCSR & kSAI_FIFORequestFlag) || (SAI1->TCSR & kSAI_FIFOErrorFlag)) &&
  1432. ((SAI1->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1433. #else
  1434. if ((s_saiHandle[1][0]) && ((SAI1->TCSR & kSAI_FIFOWarningFlag) || (SAI1->TCSR & kSAI_FIFOErrorFlag)) &&
  1435. ((SAI1->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI1->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1436. #endif
  1437. {
  1438. s_saiTxIsr(SAI1, s_saiHandle[1][0]);
  1439. }
  1440. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1441. exception return operation might vector to incorrect interrupt */
  1442. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1443. __DSB();
  1444. #endif
  1445. }
  1446. #endif /* SAI1 */
  1447. #if defined(SAI2)
  1448. void SAI2_DriverIRQHandler(void)
  1449. {
  1450. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1451. if ((s_saiHandle[2][1]) && ((SAI2->RCSR & kSAI_FIFORequestFlag) || (SAI2->RCSR & kSAI_FIFOErrorFlag)) &&
  1452. ((SAI2->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1453. #else
  1454. if ((s_saiHandle[2][1]) && ((SAI2->RCSR & kSAI_FIFOWarningFlag) || (SAI2->RCSR & kSAI_FIFOErrorFlag)) &&
  1455. ((SAI2->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI2->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1456. #endif
  1457. {
  1458. s_saiRxIsr(SAI2, s_saiHandle[2][1]);
  1459. }
  1460. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1461. if ((s_saiHandle[2][0]) && ((SAI2->TCSR & kSAI_FIFORequestFlag) || (SAI2->TCSR & kSAI_FIFOErrorFlag)) &&
  1462. ((SAI2->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1463. #else
  1464. if ((s_saiHandle[2][0]) && ((SAI2->TCSR & kSAI_FIFOWarningFlag) || (SAI2->TCSR & kSAI_FIFOErrorFlag)) &&
  1465. ((SAI2->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI2->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1466. #endif
  1467. {
  1468. s_saiTxIsr(SAI2, s_saiHandle[2][0]);
  1469. }
  1470. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1471. exception return operation might vector to incorrect interrupt */
  1472. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1473. __DSB();
  1474. #endif
  1475. }
  1476. #endif /* SAI2 */
  1477. #if defined(SAI3)
  1478. void SAI3_DriverIRQHandler(void)
  1479. {
  1480. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1481. if ((s_saiHandle[3][1]) && ((SAI3->RCSR & kSAI_FIFORequestFlag) || (SAI3->RCSR & kSAI_FIFOErrorFlag)) &&
  1482. ((SAI3->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1483. #else
  1484. if ((s_saiHandle[3][1]) && ((SAI3->RCSR & kSAI_FIFOWarningFlag) || (SAI3->RCSR & kSAI_FIFOErrorFlag)) &&
  1485. ((SAI3->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI3->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1486. #endif
  1487. {
  1488. s_saiRxIsr(SAI3, s_saiHandle[3][1]);
  1489. }
  1490. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1491. if ((s_saiHandle[3][0]) && ((SAI3->TCSR & kSAI_FIFORequestFlag) || (SAI3->TCSR & kSAI_FIFOErrorFlag)) &&
  1492. ((SAI3->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1493. #else
  1494. if ((s_saiHandle[3][0]) && ((SAI3->TCSR & kSAI_FIFOWarningFlag) || (SAI3->TCSR & kSAI_FIFOErrorFlag)) &&
  1495. ((SAI3->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI3->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1496. #endif
  1497. {
  1498. s_saiTxIsr(SAI3, s_saiHandle[3][0]);
  1499. }
  1500. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1501. exception return operation might vector to incorrect interrupt */
  1502. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1503. __DSB();
  1504. #endif
  1505. }
  1506. #endif /* SAI3 */
  1507. #if defined(SAI4)
  1508. void SAI4_DriverIRQHandler(void)
  1509. {
  1510. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1511. if ((s_saiHandle[4][1]) && ((SAI4->RCSR & kSAI_FIFORequestFlag) || (SAI4->RCSR & kSAI_FIFOErrorFlag)) &&
  1512. ((SAI4->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI4->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1513. #else
  1514. if ((s_saiHandle[4][1]) && ((SAI4->RCSR & kSAI_FIFOWarningFlag) || (SAI4->RCSR & kSAI_FIFOErrorFlag)) &&
  1515. ((SAI4->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI4->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1516. #endif
  1517. {
  1518. s_saiRxIsr(SAI4, s_saiHandle[4][1]);
  1519. }
  1520. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1521. if ((s_saiHandle[4][0]) && ((SAI4->TCSR & kSAI_FIFORequestFlag) || (SAI4->TCSR & kSAI_FIFOErrorFlag)) &&
  1522. ((SAI4->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI4->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1523. #else
  1524. if ((s_saiHandle[4][0]) && ((SAI4->TCSR & kSAI_FIFOWarningFlag) || (SAI4->TCSR & kSAI_FIFOErrorFlag)) &&
  1525. ((SAI4->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI4->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1526. #endif
  1527. {
  1528. s_saiTxIsr(SAI4, s_saiHandle[4][0]);
  1529. }
  1530. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1531. exception return operation might vector to incorrect interrupt */
  1532. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1533. __DSB();
  1534. #endif
  1535. }
  1536. #endif /* SAI4 */
  1537. #if defined(SAI5)
  1538. void SAI5_DriverIRQHandler(void)
  1539. {
  1540. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1541. if ((s_saiHandle[5][1]) && ((SAI5->RCSR & kSAI_FIFORequestFlag) || (SAI5->RCSR & kSAI_FIFOErrorFlag)) &&
  1542. ((SAI5->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI5->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1543. #else
  1544. if ((s_saiHandle[5][1]) && ((SAI5->RCSR & kSAI_FIFOWarningFlag) || (SAI5->RCSR & kSAI_FIFOErrorFlag)) &&
  1545. ((SAI5->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI5->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1546. #endif
  1547. {
  1548. s_saiRxIsr(SAI5, s_saiHandle[5][1]);
  1549. }
  1550. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1551. if ((s_saiHandle[5][0]) && ((SAI5->TCSR & kSAI_FIFORequestFlag) || (SAI5->TCSR & kSAI_FIFOErrorFlag)) &&
  1552. ((SAI5->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI5->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1553. #else
  1554. if ((s_saiHandle[5][0]) && ((SAI5->TCSR & kSAI_FIFOWarningFlag) || (SAI5->TCSR & kSAI_FIFOErrorFlag)) &&
  1555. ((SAI5->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI5->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1556. #endif
  1557. {
  1558. s_saiTxIsr(SAI5, s_saiHandle[5][0]);
  1559. }
  1560. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1561. exception return operation might vector to incorrect interrupt */
  1562. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1563. __DSB();
  1564. #endif
  1565. }
  1566. #endif /* SAI5 */
  1567. #if defined(SAI6)
  1568. void SAI6_DriverIRQHandler(void)
  1569. {
  1570. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1571. if ((s_saiHandle[6][1]) && ((SAI6->RCSR & kSAI_FIFORequestFlag) || (SAI6->RCSR & kSAI_FIFOErrorFlag)) &&
  1572. ((SAI6->RCSR & kSAI_FIFORequestInterruptEnable) || (SAI6->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1573. #else
  1574. if ((s_saiHandle[6][1]) && ((SAI6->RCSR & kSAI_FIFOWarningFlag) || (SAI6->RCSR & kSAI_FIFOErrorFlag)) &&
  1575. ((SAI6->RCSR & kSAI_FIFOWarningInterruptEnable) || (SAI6->RCSR & kSAI_FIFOErrorInterruptEnable)))
  1576. #endif
  1577. {
  1578. s_saiRxIsr(SAI6, s_saiHandle[6][1]);
  1579. }
  1580. #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
  1581. if ((s_saiHandle[6][0]) && ((SAI6->TCSR & kSAI_FIFORequestFlag) || (SAI6->TCSR & kSAI_FIFOErrorFlag)) &&
  1582. ((SAI6->TCSR & kSAI_FIFORequestInterruptEnable) || (SAI6->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1583. #else
  1584. if ((s_saiHandle[6][0]) && ((SAI6->TCSR & kSAI_FIFOWarningFlag) || (SAI6->TCSR & kSAI_FIFOErrorFlag)) &&
  1585. ((SAI6->TCSR & kSAI_FIFOWarningInterruptEnable) || (SAI6->TCSR & kSAI_FIFOErrorInterruptEnable)))
  1586. #endif
  1587. {
  1588. s_saiTxIsr(SAI6, s_saiHandle[6][0]);
  1589. }
  1590. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1591. exception return operation might vector to incorrect interrupt */
  1592. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1593. __DSB();
  1594. #endif
  1595. }
  1596. #endif /* SAI6 */