romapi_dma.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * @brief DMA controller 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. #ifndef __ROMAPI_DMA_H_
  32. #define __ROMAPI_DMA_H_
  33. #include "hw_dmaaltd.h"
  34. /** @defgroup ROMAPI_DMA_WRAPPER CHIP: DMA controller ROM wrapper functions
  35. * @ingroup ROMAPI_5410X
  36. * @{
  37. */
  38. /** @brief Minimum byte alignment value needed for the channel table.
  39. * Use 4 for 4 byte alginment, 8 for 8 byte alignment, etc. */
  40. #define MINDMATABLEALIGN 512
  41. /** @brief Number of DMA channels the DMA controller supports. */
  42. #define NUMDMACHANNELS 22
  43. /**
  44. * @brief Get memory size in bytes needed for DMA controller driver context
  45. * @return Size in bytes needed for the ROM driver
  46. */
  47. uint32_t ROM_DMA_GetMemSize(void);
  48. /**
  49. * @brief Initialize DMA controller
  50. * @param mem : Pointer to memory area used to driver context
  51. * @param pInit : Pointer to DMA controller init data
  52. * @return NULL on error, or a pointer to the device context handle
  53. */
  54. ROM_DMA_HANDLE_T ROM_DMA_Init(void *mem, ROM_DMA_INIT_T *pInit);
  55. /**
  56. * @brief Configures a DMA channel
  57. * @param pHandle : Pointer to driver context handle
  58. * @param pCfg : Pointer to DMA channel configuration structure
  59. * @param dmaCh : DMA channel to configure
  60. * @return LPC_OK if no errors occured, or an error code
  61. */
  62. ErrorCode_t ROM_DMA_SetupChannel(ROM_DMA_HANDLE_T pHandle, ROM_DMA_CHAN_CFG_T *pCfg, uint8_t dmaCh);
  63. /**
  64. * @brief Initialzies a transfer descriptor queue for a channel
  65. * @param pHandle : Pointer to driver context handle
  66. * @param dmaCh : DMA channel to configure
  67. * @param pQueue : Pointer to a queue to initialize
  68. * @return LPC_OK if no errors occured, or an error code
  69. */
  70. ErrorCode_t ROM_DMA_InitQueue(ROM_DMA_HANDLE_T pHandle, uint8_t dmaCh, ROM_DMA_QUEUE_T *pQueue);
  71. /**
  72. * @brief Registers an DMA controller callback for a queue
  73. * @param pHandle : Pointer to driver context handle
  74. * @param pQueue : Pointer to a queue
  75. * @param cbIndex : Callback to register
  76. * @param pCB : Pointer to callback function
  77. * @return Nothing
  78. */
  79. void ROM_DMA_RegisterQueueCallback(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue, uint32_t cbIndex, void *pCB);
  80. /**
  81. * @brief Builds a transfer descriptor chain from the passed settings
  82. * @param pHandle : Pointer to driver context handle
  83. * @param pXferCfg : Pointer to the transfer configuration
  84. * @param pDesc : Pointer to a descriptor to setup
  85. * @param pDescPrev : Pointer to previous descriptor that will link to this one
  86. * @return LPC_OK if no errors occured, or an error code
  87. * @note When creating a DMA descriptor chain (more than 1 link), chain the descriptors
  88. * together by passing the previous descriptor pointers for subsequenct calls to this function.
  89. */
  90. ErrorCode_t ROM_DMA_BuildDescriptorChain(ROM_DMA_HANDLE_T pHandle,
  91. ROM_DMA_XFERDESC_CFG_T *pXferCfg,
  92. ROM_DMA_DESC_T *pDesc,
  93. ROM_DMA_DESC_T *pDescPrev);
  94. /**
  95. * @brief Returns the number of items transferred on the last descriptor chain (spent status only)
  96. * @param pHandle : Pointer to driver context handle
  97. * @param pDesc : Pointer to a descriptor chain to count
  98. * @return LPC_OK if no errors occured, or an error code
  99. */
  100. uint32_t ROM_DMA_GetTransferCount(ROM_DMA_HANDLE_T pHandle, ROM_DMA_DESC_T *pDesc);
  101. /**
  102. * @brief Unstalls a descriptor chain that has been setup using the stallDesc option
  103. * @param pHandle : Pointer to driver context handle
  104. * @param pQueue : Pointer to a descriptor chain to unstall
  105. * @return Nothing
  106. * @note If a descriptor in a chain is setup with the stallDesc!=0 option in the
  107. * @ref ROM_DMA_XFERDESC_CFG_T setup structure, the descriptor will stall when it
  108. * is loaded. A stalled descriptor is ready to be processed, but won't start until a
  109. * call to this fucntion is made.
  110. */
  111. void ROM_DMA_UnstallDescriptorChain(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  112. /**
  113. * @brief Queues a transfer descriptor chain
  114. * @param pHandle : Pointer to driver context handle
  115. * @param pQueue : Pointer to a queue
  116. * @param pDescChainHead : Pointer to the start of a descriptor chain to queue
  117. * @return Nothing
  118. */
  119. void ROM_DMA_QueueDescriptor(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue, ROM_DMA_DESC_T *pDescChainHead);
  120. /**
  121. * @brief Returns current status of next descriptor to be popped from the queue
  122. * @param pHandle : Pointer to driver context handle
  123. * @param pQueue : Pointer to a queue
  124. * @return Pointer to next pop descriptor, or ROM_DMA_DESC_STS_INVALID if no descriptors exist to be popped
  125. * @note Only descriptors that are spent, aborted, or have an error can be popped. Calling ROM_DMA_StopQueue()
  126. * will abort the current descriptor in progress. This function returns the next descriptor that can be popped
  127. * regardless of status without actually popping it.
  128. */
  129. ROM_DMA_DESC_STS_T ROM_DMA_GetQueuePopDescriptorStatus(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  130. /**
  131. * @brief Pops (unqueues) an expired transfer descriptor from the queue - expired descriptors are in spent, error, or abort states
  132. * @param pHandle : Pointer to driver context handle
  133. * @param pQueue : Pointer to a queue
  134. * @return Pointer to popped descriptor, or NULL if no descriptors exist to be popped
  135. * @note Only descriptors that are spent, aborted, or have an error can be popped. Calling ROM_DMA_StopQueue()
  136. * will abort the current descriptor in progress.
  137. */
  138. ROM_DMA_DESC_T *ROM_DMA_UnQueueDescriptor(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  139. /**
  140. * @brief Starts or restarts a queue at the next descriptor chain
  141. * @param pHandle : Pointer to driver context handle
  142. * @param pQueue : Pointer to a queue
  143. * @return LPC_OK if the queue is started or currently started, or an error code
  144. */
  145. ErrorCode_t ROM_DMA_StartQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  146. /**
  147. * @brief Stops DMA and aborts current descriptor chain being processed in queue
  148. * @param pHandle : Pointer to driver context handle
  149. * @param pQueue : Pointer to a queue
  150. * @return LPC_OK if the queue is stopped or already stopped, or an error code
  151. * @note If multiple descriptor chains are queued up, this aborts the current one
  152. * being processed in queueing, ready, or busy states. All descriptors after the aborted
  153. * descriptor remain ready.
  154. */
  155. ErrorCode_t ROM_DMA_StopQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  156. /**
  157. * @brief Stops DMA and completely flushes a transfer queue, queue is completely reset
  158. * @param pHandle : Pointer to driver context handle
  159. * @param pQueue : Pointer to a queue
  160. * @return Nothing
  161. * @note Flushes the entire queue of all descriptors and stops DMA.
  162. */
  163. void ROM_DMA_FlushQueue(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  164. /**
  165. * @brief Returns the current queue state (ROM_DMA_QUEUE_STATES_T)
  166. * @param pHandle : Pointer to driver context handle
  167. * @param pQueue : Pointer to a queue
  168. * @return Current queue status (ROM_DMA_QUEUE_STATES_T)
  169. */
  170. uint8_t ROM_DMA_GetQueueState(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  171. /**
  172. * @brief Forces a DMA transfer to trigger
  173. * @param pHandle : Pointer to driver context handle
  174. * @param pQueue : Pointer to a queue
  175. * @return Nothing
  176. */
  177. void ROM_DMA_ForceTrigger(ROM_DMA_HANDLE_T pHandle, ROM_DMA_QUEUE_T *pQueue);
  178. /**
  179. * @brief DMA controller (interrupt) handler
  180. * @param pHandle : Pointer to driver context handle
  181. * @return Nothing
  182. * @note This function should be called from the DMA interrupt handler.
  183. */
  184. void ROM_DMA_DMAHandler(ROM_DMA_HANDLE_T pHandle);
  185. /**
  186. * @brief Return the DMA controller ROM driver version
  187. * @return Driver version number
  188. * @note The returned driver version number consists of a major and minor
  189. * number, with the minor number in the lower 8 bits and the major number in
  190. * the upper 8 bits.
  191. */
  192. uint16_t ROM_DMA_GetDriverVersion(void);
  193. /**
  194. * @}
  195. */
  196. #endif /* __ROMAPI_DMA_H_ */