romapi_dma.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * @brief DMA master ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #include "romapi_5410x.h"
  32. /* Get memory size in bytes needed for DMA controller driver context */
  33. uint32_t ROM_DMA_GetMemSize(void)
  34. {
  35. #if defined(ROMDRIVERSV2_PRESENT)
  36. return ROMAPI_DMAALT_API->GetMemSize();
  37. #else
  38. return dmaalt_api.GetMemSize();
  39. #endif
  40. }
  41. /* Initialize DMA controller */
  42. ROM_DMA_HANDLE_T ROM_DMA_Init(void *mem, ROM_DMA_INIT_T *pInit)
  43. {
  44. /* Verify SRAMBASE alginemnt is at least MINDMATABLEALIGN bytes */
  45. if (((uint32_t) pInit->sramBase & (MINDMATABLEALIGN - 1)) != 0) {
  46. return NULL;
  47. }
  48. #if defined(ROMDRIVERSV2_PRESENT)
  49. return ROMAPI_DMAALT_API->Init(mem, pInit);
  50. #else
  51. return dmaalt_api.Init(mem, pInit);
  52. #endif
  53. }
  54. /* Configures a DMA channel */
  55. ErrorCode_t ROM_DMA_SetupChannel(ROM_DMA_HANDLE_T pHandle, ROM_DMA_CHAN_CFG_T *pCfg, uint8_t dmaCh)
  56. {
  57. if (dmaCh >= NUMDMACHANNELS) {
  58. return ERR_DMA_CHANNEL_NUMBER;
  59. }
  60. #if defined(ROMDRIVERSV2_PRESENT)
  61. return ROMAPI_DMAALT_API->SetupChannel(pHandle, pCfg, dmaCh);
  62. #else
  63. return dmaalt_api.SetupChannel(pHandle, pCfg, dmaCh);
  64. #endif
  65. }
  66. /* Initializes a transfer descriptor queue for a channel */
  67. ErrorCode_t ROM_DMA_InitQueue(ROM_DMA_HANDLE_T pHandle, uint8_t dmaCh, ROM_DMA_QUEUE_T *pQueue)
  68. {
  69. if (dmaCh >= NUMDMACHANNELS) {
  70. return ERR_DMA_CHANNEL_NUMBER;
  71. }
  72. #if defined(ROMDRIVERSV2_PRESENT)
  73. return ROMAPI_DMAALT_API->InitQueue(pHandle, dmaCh, pQueue);
  74. #else
  75. return dmaalt_api.InitQueue(pHandle, dmaCh, pQueue);
  76. #endif
  77. }
  78. /* Registers an DMA controller callback for a queue */
  79. void ROM_DMA_RegisterQueueCallback(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue, uint32_t cbIndex, void *pCB)
  80. {
  81. #if defined(ROMDRIVERSV2_PRESENT)
  82. ROMAPI_DMAALT_API->RegisterQueueCallback(pHandle, pQueue, cbIndex, pCB);
  83. #else
  84. dmaalt_api.RegisterQueueCallback(pHandle, pQueue, cbIndex, pCB);
  85. #endif
  86. }
  87. /* Builds a transfer descriptor chain from the passed settings */
  88. ErrorCode_t ROM_DMA_BuildDescriptorChain(ROM_DMA_HANDLE_T pHandle,
  89. ROM_DMA_XFERDESC_CFG_T *pXferCfg,
  90. ROM_DMA_DESC_T *pDesc,
  91. ROM_DMA_DESC_T *pDescPrev)
  92. {
  93. if (pXferCfg->dmaCh >= NUMDMACHANNELS) {
  94. return ERR_DMA_CHANNEL_NUMBER;
  95. }
  96. #if defined(ROMDRIVERSV2_PRESENT)
  97. return ROMAPI_DMAALT_API->BuildDescriptorChain(pHandle, pXferCfg, pDesc, pDescPrev);
  98. #else
  99. return dmaalt_api.BuildDescriptorChain(pHandle, pXferCfg, pDesc, pDescPrev);
  100. #endif
  101. }
  102. /* Returns the number of items transferred on the last descriptor chain (spent status only) */
  103. uint32_t ROM_DMA_GetTransferCount(ROM_DMA_HANDLE_T pHandle, ROM_DMA_DESC_T *pDesc)
  104. {
  105. #if defined(ROMDRIVERSV2_PRESENT)
  106. return ROMAPI_DMAALT_API->GetTransferCount(pHandle, pDesc);
  107. #else
  108. return dmaalt_api.GetTransferCount(pHandle, pDesc);
  109. #endif
  110. }
  111. /* Unstalls a descriptor chain that has been setup using the stallDesc option */
  112. void ROM_DMA_UnstallDescriptorChain(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  113. {
  114. #if defined(ROMDRIVERSV2_PRESENT)
  115. ROMAPI_DMAALT_API->UnstallDescriptorChain(pHandle, pQueue);
  116. #else
  117. dmaalt_api.UnstallDescriptorChain(pHandle, pQueue);
  118. #endif
  119. }
  120. /* Queues a transfer descriptor chain */
  121. void ROM_DMA_QueueDescriptor(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue, ROM_DMA_DESC_T *pDescChainHead)
  122. {
  123. #if defined(ROMDRIVERSV2_PRESENT)
  124. ROMAPI_DMAALT_API->QueueDescriptor(pHandle, pQueue, pDescChainHead);
  125. #else
  126. dmaalt_api.QueueDescriptor(pHandle, pQueue, pDescChainHead);
  127. #endif
  128. }
  129. /* Returns current status of next descriptor to be popped from the queue */
  130. ROM_DMA_DESC_STS_T ROM_DMA_GetQueuePopDescriptorStatus(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  131. {
  132. #if defined(ROMDRIVERSV2_PRESENT)
  133. return ROMAPI_DMAALT_API->GetQueuePopDescriptorStatus(pHandle, pQueue);
  134. #else
  135. return dmaalt_api.GetQueuePopDescriptorStatus(pHandle, pQueue);
  136. #endif
  137. }
  138. /* Pops (unqueues) an expired transfer descriptor from the queue - expired descriptors are in spent, error, or abort states */
  139. ROM_DMA_DESC_T *ROM_DMA_UnQueueDescriptor(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  140. {
  141. #if defined(ROMDRIVERSV2_PRESENT)
  142. return ROMAPI_DMAALT_API->UnQueueDescriptor(pHandle, pQueue);
  143. #else
  144. return dmaalt_api.UnQueueDescriptor(pHandle, pQueue);
  145. #endif
  146. }
  147. /* Starts or restarts a queue at the next descriptor chain */
  148. ErrorCode_t ROM_DMA_StartQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  149. {
  150. #if defined(ROMDRIVERSV2_PRESENT)
  151. return ROMAPI_DMAALT_API->StartQueue(pHandle, pQueue);
  152. #else
  153. return dmaalt_api.StartQueue(pHandle, pQueue);
  154. #endif
  155. }
  156. /* Stops DMA and aborts current descriptor chain being processed in queue */
  157. ErrorCode_t ROM_DMA_StopQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  158. {
  159. #if defined(ROMDRIVERSV2_PRESENT)
  160. return ROMAPI_DMAALT_API->StopQueue(pHandle, pQueue);
  161. #else
  162. return dmaalt_api.StopQueue(pHandle, pQueue);
  163. #endif
  164. }
  165. /* Stops DMA and completely flushes a transfer queue, queue is completely reset */
  166. void ROM_DMA_FlushQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  167. {
  168. #if defined(ROMDRIVERSV2_PRESENT)
  169. ROMAPI_DMAALT_API->FlushQueue(pHandle, pQueue);
  170. #else
  171. dmaalt_api.FlushQueue(pHandle, pQueue);
  172. #endif
  173. }
  174. /* Returns the current queue state (ROM_DMA_QUEUE_STATES_T) */
  175. uint8_t ROM_DMA_GetQueueState(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  176. {
  177. #if defined(ROMDRIVERSV2_PRESENT)
  178. return ROMAPI_DMAALT_API->GetQueueState(pHandle, pQueue);
  179. #else
  180. return dmaalt_api.GetQueueState(pHandle, pQueue);
  181. #endif
  182. }
  183. /* Forces a DMA transfer to trigger */
  184. void ROM_DMA_ForceTrigger(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue)
  185. {
  186. #if defined(ROMDRIVERSV2_PRESENT)
  187. ROMAPI_DMAALT_API->ForceTrigger(pHandle, pQueue);
  188. #else
  189. dmaalt_api.ForceTrigger(pHandle, pQueue);
  190. #endif
  191. }
  192. /* DMA controller (interrupt) handler */
  193. void ROM_DMA_DMAHandler(ROM_DMA_HANDLE_T pHandle)
  194. {
  195. #if defined(ROMDRIVERSV2_PRESENT)
  196. ROMAPI_DMAALT_API->DMAHandler(pHandle);
  197. #else
  198. dmaalt_api.DMAHandler(pHandle);
  199. #endif
  200. }
  201. /* Return the DMA controller ROM driver version */
  202. uint16_t ROM_DMA_GetDriverVersion(void)
  203. {
  204. #if defined(ROMDRIVERSV2_PRESENT)
  205. return ROMAPI_DMAALT_API->GetDriverVersion();
  206. #else
  207. return dmaalt_api.GetDriverVersion();
  208. #endif
  209. }