fsl_spdif_edma.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "fsl_spdif_edma.h"
  31. /*******************************************************************************
  32. * Definitations
  33. ******************************************************************************/
  34. /* Used for 32byte aligned */
  35. #define STCD_ADDR(address) (edma_tcd_t *)(((uint32_t)address + 32) & ~0x1FU)
  36. /*<! Structure definition for uart_edma_private_handle_t. The structure is private. */
  37. typedef struct _spdif_edma_private_handle
  38. {
  39. SPDIF_Type *base;
  40. spdif_edma_handle_t *handle;
  41. } spdif_edma_private_handle_t;
  42. enum _spdif_edma_transfer_state
  43. {
  44. kSPDIF_Busy = 0x0U, /*!< SPDIF is busy */
  45. kSPDIF_Idle, /*!< Transfer is done. */
  46. };
  47. /*<! Private handle only used for internally. */
  48. static spdif_edma_private_handle_t s_edmaPrivateHandle[FSL_FEATURE_SOC_I2S_COUNT][2];
  49. static uint8_t s_spdif_tx_watermark[4] = {16, 12, 8, 4};
  50. static uint8_t s_spdif_rx_watermark[4] = {1, 4, 8, 16};
  51. /*******************************************************************************
  52. * Prototypes
  53. ******************************************************************************/
  54. /*!
  55. * @brief Get the instance number for SPDIF.
  56. *
  57. * @param base SPDIF base pointer.
  58. */
  59. extern uint32_t SPDIF_GetInstance(SPDIF_Type *base);
  60. /*!
  61. * @brief Submit SPDIF tcds to EDMA.
  62. *
  63. * @param base SPDIF base pointer.
  64. */
  65. static status_t SPDIF_SubmitTransfer(edma_handle_t *handle,
  66. const edma_transfer_config_t *config,
  67. uint32_t rightChannel);
  68. /*!
  69. * @brief SPDIF EDMA callback for send.
  70. *
  71. * @param handle pointer to spdif_edma_handle_t structure which stores the transfer state.
  72. * @param userData Parameter for user callback.
  73. * @param done If the DMA transfer finished.
  74. * @param tcds The TCD index.
  75. */
  76. static void SPDIF_TxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds);
  77. /*!
  78. * @brief SPDIF EDMA callback for receive.
  79. *
  80. * @param handle pointer to spdif_edma_handle_t structure which stores the transfer state.
  81. * @param userData Parameter for user callback.
  82. * @param done If the DMA transfer finished.
  83. * @param tcds The TCD index.
  84. */
  85. static void SPDIF_RxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds);
  86. /*******************************************************************************
  87. * Code
  88. ******************************************************************************/
  89. static void SPDIF_TxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds)
  90. {
  91. spdif_edma_private_handle_t *privHandle = (spdif_edma_private_handle_t *)userData;
  92. spdif_edma_handle_t *spdifHandle = privHandle->handle;
  93. /* If finished a blcok, call the callback function */
  94. memset(&spdifHandle->spdifQueue[spdifHandle->queueDriver], 0, sizeof(spdif_edma_transfer_t));
  95. spdifHandle->queueDriver = (spdifHandle->queueDriver + 1) % SPDIF_XFER_QUEUE_SIZE;
  96. if (spdifHandle->callback)
  97. {
  98. (spdifHandle->callback)(privHandle->base, spdifHandle, kStatus_SPDIF_TxIdle, spdifHandle->userData);
  99. }
  100. /* If all data finished, just stop the transfer */
  101. if (spdifHandle->spdifQueue[spdifHandle->queueDriver].rightData == NULL)
  102. {
  103. SPDIF_TransferAbortSendEDMA(privHandle->base, spdifHandle);
  104. }
  105. }
  106. static void SPDIF_RxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds)
  107. {
  108. spdif_edma_private_handle_t *privHandle = (spdif_edma_private_handle_t *)userData;
  109. spdif_edma_handle_t *spdifHandle = privHandle->handle;
  110. /* If finished a blcok, call the callback function */
  111. memset(&spdifHandle->spdifQueue[spdifHandle->queueDriver], 0, sizeof(spdif_edma_transfer_t));
  112. spdifHandle->queueDriver = (spdifHandle->queueDriver + 1) % SPDIF_XFER_QUEUE_SIZE;
  113. if (spdifHandle->callback)
  114. {
  115. (spdifHandle->callback)(privHandle->base, spdifHandle, kStatus_SPDIF_RxIdle, spdifHandle->userData);
  116. }
  117. /* If all data finished, just stop the transfer */
  118. if (spdifHandle->spdifQueue[spdifHandle->queueDriver].rightData == NULL)
  119. {
  120. SPDIF_TransferAbortReceiveEDMA(privHandle->base, spdifHandle);
  121. }
  122. }
  123. static status_t SPDIF_SubmitTransfer(edma_handle_t *handle, const edma_transfer_config_t *config, uint32_t rightChannel)
  124. {
  125. edma_tcd_t *tcdRegs = (edma_tcd_t *)&handle->base->TCD[handle->channel];
  126. uint32_t primask;
  127. uint32_t csr;
  128. int8_t currentTcd;
  129. int8_t previousTcd;
  130. int8_t nextTcd;
  131. /* Check if tcd pool is full. */
  132. primask = DisableGlobalIRQ();
  133. if (handle->tcdUsed >= handle->tcdSize)
  134. {
  135. EnableGlobalIRQ(primask);
  136. return kStatus_EDMA_QueueFull;
  137. }
  138. currentTcd = handle->tail;
  139. handle->tcdUsed++;
  140. /* Calculate index of next TCD */
  141. nextTcd = currentTcd + 1U;
  142. if (nextTcd == handle->tcdSize)
  143. {
  144. nextTcd = 0U;
  145. }
  146. /* Advance queue tail index */
  147. handle->tail = nextTcd;
  148. EnableGlobalIRQ(primask);
  149. /* Calculate index of previous TCD */
  150. previousTcd = currentTcd ? currentTcd - 1U : handle->tcdSize - 1U;
  151. /* Configure current TCD block. */
  152. EDMA_TcdReset(&handle->tcdPool[currentTcd]);
  153. EDMA_TcdSetTransferConfig(&handle->tcdPool[currentTcd], config, NULL);
  154. /* Set channel link */
  155. EDMA_TcdSetChannelLink(&handle->tcdPool[currentTcd], kEDMA_MinorLink, rightChannel);
  156. EDMA_TcdSetChannelLink(&handle->tcdPool[currentTcd], kEDMA_MajorLink, rightChannel);
  157. /* Enable major interrupt */
  158. handle->tcdPool[currentTcd].CSR |= DMA_CSR_INTMAJOR_MASK;
  159. /* Link current TCD with next TCD for identification of current TCD */
  160. handle->tcdPool[currentTcd].DLAST_SGA = (uint32_t)&handle->tcdPool[nextTcd];
  161. /* Chain from previous descriptor unless tcd pool size is 1(this descriptor is its own predecessor). */
  162. if (currentTcd != previousTcd)
  163. {
  164. /* Enable scatter/gather feature in the previous TCD block. */
  165. csr = (handle->tcdPool[previousTcd].CSR | DMA_CSR_ESG_MASK) & ~DMA_CSR_DREQ_MASK;
  166. handle->tcdPool[previousTcd].CSR = csr;
  167. /*
  168. Check if the TCD blcok in the registers is the previous one (points to current TCD block). It
  169. is used to check if the previous TCD linked has been loaded in TCD register. If so, it need to
  170. link the TCD register in case link the current TCD with the dead chain when TCD loading occurs
  171. before link the previous TCD block.
  172. */
  173. if (tcdRegs->DLAST_SGA == (uint32_t)&handle->tcdPool[currentTcd])
  174. {
  175. /* Enable scatter/gather also in the TCD registers. */
  176. csr = (tcdRegs->CSR | DMA_CSR_ESG_MASK) & ~DMA_CSR_DREQ_MASK;
  177. /* Must write the CSR register one-time, because the transfer maybe finished anytime. */
  178. tcdRegs->CSR = csr;
  179. /*
  180. It is very important to check the ESG bit!
  181. Because this hardware design: if DONE bit is set, the ESG bit can not be set. So it can
  182. be used to check if the dynamic TCD link operation is successful. If ESG bit is not set
  183. and the DLAST_SGA is not the next TCD address(it means the dynamic TCD link succeed and
  184. the current TCD block has been loaded into TCD registers), it means transfer finished
  185. and TCD link operation fail, so must install TCD content into TCD registers and enable
  186. transfer again. And if ESG is set, it means transfer has notfinished, so TCD dynamic
  187. link succeed.
  188. */
  189. if (tcdRegs->CSR & DMA_CSR_ESG_MASK)
  190. {
  191. return kStatus_Success;
  192. }
  193. /*
  194. Check whether the current TCD block is already loaded in the TCD registers. It is another
  195. condition when ESG bit is not set: it means the dynamic TCD link succeed and the current
  196. TCD block has been loaded into TCD registers.
  197. */
  198. if (tcdRegs->DLAST_SGA == (uint32_t)&handle->tcdPool[nextTcd])
  199. {
  200. return kStatus_Success;
  201. }
  202. /*
  203. If go to this, means the previous transfer finished, and the DONE bit is set.
  204. So shall configure TCD registers.
  205. */
  206. }
  207. else if (tcdRegs->DLAST_SGA != 0)
  208. {
  209. /* The current TCD block has been linked successfully. */
  210. return kStatus_Success;
  211. }
  212. else
  213. {
  214. /*
  215. DLAST_SGA is 0 and it means the first submit transfer, so shall configure
  216. TCD registers.
  217. */
  218. }
  219. }
  220. /* There is no live chain, TCD block need to be installed in TCD registers. */
  221. EDMA_InstallTCD(handle->base, handle->channel, &handle->tcdPool[currentTcd]);
  222. /* Enable channel request again. */
  223. if (handle->flags & 0x80)
  224. {
  225. handle->base->SERQ = DMA_SERQ_SERQ(handle->channel);
  226. }
  227. return kStatus_Success;
  228. }
  229. void SPDIF_TransferTxCreateHandleEDMA(SPDIF_Type *base,
  230. spdif_edma_handle_t *handle,
  231. spdif_edma_callback_t callback,
  232. void *userData,
  233. edma_handle_t *dmaLeftHandle,
  234. edma_handle_t *dmaRightHandle)
  235. {
  236. assert(handle && dmaLeftHandle && dmaRightHandle);
  237. uint32_t instance = SPDIF_GetInstance(base);
  238. /* Zero the handle */
  239. memset(handle, 0, sizeof(*handle));
  240. /* Set spdif base to handle */
  241. handle->dmaLeftHandle = dmaLeftHandle;
  242. handle->dmaRightHandle = dmaRightHandle;
  243. handle->callback = callback;
  244. handle->userData = userData;
  245. handle->count =
  246. s_spdif_tx_watermark[(base->SCR & SPDIF_SCR_TXFIFOEMPTY_SEL_MASK) >> SPDIF_SCR_TXFIFOEMPTY_SEL_SHIFT];
  247. /* Set SPDIF state to idle */
  248. handle->state = kSPDIF_Idle;
  249. s_edmaPrivateHandle[instance][0].base = base;
  250. s_edmaPrivateHandle[instance][0].handle = handle;
  251. /* Need to use scatter gather */
  252. EDMA_InstallTCDMemory(dmaLeftHandle, STCD_ADDR(handle->leftTcd), SPDIF_XFER_QUEUE_SIZE);
  253. EDMA_InstallTCDMemory(dmaRightHandle, STCD_ADDR(handle->rightTcd), SPDIF_XFER_QUEUE_SIZE);
  254. /* Install callback for Tx dma channel, only right channel finished, a transfer finished */
  255. EDMA_SetCallback(dmaRightHandle, SPDIF_TxEDMACallback, &s_edmaPrivateHandle[instance][0]);
  256. }
  257. void SPDIF_TransferRxCreateHandleEDMA(SPDIF_Type *base,
  258. spdif_edma_handle_t *handle,
  259. spdif_edma_callback_t callback,
  260. void *userData,
  261. edma_handle_t *dmaLeftHandle,
  262. edma_handle_t *dmaRightHandle)
  263. {
  264. assert(handle && dmaLeftHandle && dmaRightHandle);
  265. uint32_t instance = SPDIF_GetInstance(base);
  266. /* Zero the handle */
  267. memset(handle, 0, sizeof(*handle));
  268. /* Set spdif base to handle */
  269. handle->dmaLeftHandle = dmaLeftHandle;
  270. handle->dmaRightHandle = dmaRightHandle;
  271. handle->callback = callback;
  272. handle->userData = userData;
  273. handle->count = s_spdif_rx_watermark[(base->SCR & SPDIF_SCR_RXFIFOFULL_SEL_MASK) >> SPDIF_SCR_RXFIFOFULL_SEL_SHIFT];
  274. /* Set SPDIF state to idle */
  275. handle->state = kSPDIF_Idle;
  276. s_edmaPrivateHandle[instance][1].base = base;
  277. s_edmaPrivateHandle[instance][1].handle = handle;
  278. /* Need to use scatter gather */
  279. EDMA_InstallTCDMemory(dmaLeftHandle, STCD_ADDR(handle->leftTcd), SPDIF_XFER_QUEUE_SIZE);
  280. EDMA_InstallTCDMemory(dmaRightHandle, STCD_ADDR(handle->rightTcd), SPDIF_XFER_QUEUE_SIZE);
  281. /* Install callback for Tx dma channel */
  282. EDMA_SetCallback(dmaRightHandle, SPDIF_RxEDMACallback, &s_edmaPrivateHandle[instance][1]);
  283. }
  284. status_t SPDIF_TransferSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer)
  285. {
  286. assert(handle && xfer);
  287. edma_transfer_config_t config = {0};
  288. uint32_t destAddr = SPDIF_TxGetLeftDataRegisterAddress(base);
  289. /* Check if input parameter invalid */
  290. if ((xfer->leftData == NULL) || (xfer->dataSize == 0U) || (xfer->rightData == NULL))
  291. {
  292. return kStatus_InvalidArgument;
  293. }
  294. if ((handle->spdifQueue[handle->queueUser].leftData) || (handle->spdifQueue[handle->queueUser].rightData))
  295. {
  296. return kStatus_SPDIF_QueueFull;
  297. }
  298. /* Change the state of handle */
  299. handle->state = kSPDIF_Busy;
  300. /* Update the queue state */
  301. handle->transferSize[handle->queueUser] = xfer->dataSize;
  302. handle->spdifQueue[handle->queueUser].leftData = xfer->leftData;
  303. handle->spdifQueue[handle->queueUser].dataSize = xfer->dataSize;
  304. handle->spdifQueue[handle->queueUser].rightData = xfer->rightData;
  305. handle->queueUser = (handle->queueUser + 1) % SPDIF_XFER_QUEUE_SIZE;
  306. /* Store the initially configured eDMA minor byte transfer count into the SPDIF handle */
  307. handle->nbytes = handle->count * 8U;
  308. /* Prepare edma configure */
  309. EDMA_PrepareTransfer(&config, xfer->leftData, 4U, (void *)destAddr, 4U, handle->count * 4U, xfer->dataSize,
  310. kEDMA_MemoryToPeripheral);
  311. SPDIF_SubmitTransfer(handle->dmaLeftHandle, &config, handle->dmaRightHandle->channel);
  312. /* Prepare right channel */
  313. destAddr = SPDIF_TxGetRightDataRegisterAddress(base);
  314. EDMA_PrepareTransfer(&config, xfer->rightData, 4U, (void *)destAddr, 4U, handle->count * 4U, xfer->dataSize,
  315. kEDMA_MemoryToPeripheral);
  316. EDMA_SubmitTransfer(handle->dmaRightHandle, &config);
  317. /* Start DMA transfer */
  318. EDMA_StartTransfer(handle->dmaLeftHandle);
  319. EDMA_StartTransfer(handle->dmaRightHandle);
  320. /* Enable DMA enable bit */
  321. SPDIF_EnableDMA(base, kSPDIF_TxDMAEnable, true);
  322. /* Enable SPDIF Tx clock */
  323. SPDIF_TxEnable(base, true);
  324. return kStatus_Success;
  325. }
  326. status_t SPDIF_TransferReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer)
  327. {
  328. assert(handle && xfer);
  329. edma_transfer_config_t config = {0};
  330. uint32_t srcAddr = SPDIF_RxGetLeftDataRegisterAddress(base);
  331. /* Check if input parameter invalid */
  332. if ((xfer->leftData == NULL) || (xfer->dataSize == 0U) || (xfer->rightData == NULL))
  333. {
  334. return kStatus_InvalidArgument;
  335. }
  336. if ((handle->spdifQueue[handle->queueUser].leftData) || (handle->spdifQueue[handle->queueUser].rightData))
  337. {
  338. return kStatus_SPDIF_QueueFull;
  339. }
  340. /* Change the state of handle */
  341. handle->state = kSPDIF_Busy;
  342. /* Update the queue state */
  343. handle->transferSize[handle->queueUser] = xfer->dataSize;
  344. handle->spdifQueue[handle->queueUser].leftData = xfer->leftData;
  345. handle->spdifQueue[handle->queueUser].dataSize = xfer->dataSize;
  346. handle->spdifQueue[handle->queueUser].rightData = xfer->rightData;
  347. handle->queueUser = (handle->queueUser + 1) % SPDIF_XFER_QUEUE_SIZE;
  348. /* Store the initially configured eDMA minor byte transfer count into the SPDIF handle */
  349. handle->nbytes = handle->count * 8U;
  350. /* Prepare edma configure */
  351. EDMA_PrepareTransfer(&config, (void *)srcAddr, 4U, xfer->leftData, 4U, handle->count * 4U, xfer->dataSize,
  352. kEDMA_PeripheralToMemory);
  353. /* Use specific submit function to enable channel link */
  354. SPDIF_SubmitTransfer(handle->dmaLeftHandle, &config, handle->dmaRightHandle->channel);
  355. /* Prepare right channel */
  356. srcAddr = SPDIF_RxGetRightDataRegisterAddress(base);
  357. EDMA_PrepareTransfer(&config, (void *)srcAddr, 4U, xfer->rightData, 4U, handle->count * 4U, xfer->dataSize,
  358. kEDMA_PeripheralToMemory);
  359. EDMA_SubmitTransfer(handle->dmaRightHandle, &config);
  360. /* Start DMA transfer */
  361. EDMA_StartTransfer(handle->dmaLeftHandle);
  362. EDMA_StartTransfer(handle->dmaRightHandle);
  363. /* Enable DMA enable bit */
  364. SPDIF_EnableDMA(base, kSPDIF_RxDMAEnable, true);
  365. /* Enable SPDIF Rx clock */
  366. SPDIF_RxEnable(base, true);
  367. return kStatus_Success;
  368. }
  369. void SPDIF_TransferAbortSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle)
  370. {
  371. assert(handle);
  372. /* Disable dma */
  373. EDMA_AbortTransfer(handle->dmaLeftHandle);
  374. EDMA_AbortTransfer(handle->dmaRightHandle);
  375. /* Disable DMA enable bit */
  376. SPDIF_EnableDMA(base, kSPDIF_TxDMAEnable, false);
  377. /* Set internal state */
  378. memset(handle->spdifQueue, 0U, sizeof(handle->spdifQueue));
  379. memset(handle->transferSize, 0U, sizeof(handle->transferSize));
  380. handle->queueUser = 0U;
  381. handle->queueDriver = 0U;
  382. /* Set the handle state */
  383. handle->state = kSPDIF_Idle;
  384. }
  385. void SPDIF_TransferAbortReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle)
  386. {
  387. assert(handle);
  388. /* Disable dma */
  389. EDMA_AbortTransfer(handle->dmaLeftHandle);
  390. EDMA_AbortTransfer(handle->dmaRightHandle);
  391. /* Disable DMA enable bit */
  392. SPDIF_EnableDMA(base, kSPDIF_RxDMAEnable, false);
  393. /* Set internal state */
  394. memset(handle->spdifQueue, 0U, sizeof(handle->spdifQueue));
  395. memset(handle->transferSize, 0U, sizeof(handle->transferSize));
  396. handle->queueUser = 0U;
  397. handle->queueDriver = 0U;
  398. /* Set the handle state */
  399. handle->state = kSPDIF_Idle;
  400. }
  401. status_t SPDIF_TransferGetSendCountEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, size_t *count)
  402. {
  403. assert(handle);
  404. status_t status = kStatus_Success;
  405. if (handle->state != kSPDIF_Busy)
  406. {
  407. status = kStatus_NoTransferInProgress;
  408. }
  409. else
  410. {
  411. *count = (handle->transferSize[handle->queueDriver] -
  412. (uint32_t)handle->nbytes *
  413. EDMA_GetRemainingMajorLoopCount(handle->dmaRightHandle->base, handle->dmaRightHandle->channel));
  414. }
  415. return status;
  416. }
  417. status_t SPDIF_TransferGetReceiveCountEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, size_t *count)
  418. {
  419. assert(handle);
  420. status_t status = kStatus_Success;
  421. if (handle->state != kSPDIF_Busy)
  422. {
  423. status = kStatus_NoTransferInProgress;
  424. }
  425. else
  426. {
  427. *count = (handle->transferSize[handle->queueDriver] -
  428. (uint32_t)handle->nbytes *
  429. EDMA_GetRemainingMajorLoopCount(handle->dmaRightHandle->base, handle->dmaRightHandle->channel));
  430. }
  431. return status;
  432. }