dmacHw.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*****************************************************************************
  2. * Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. /****************************************************************************/
  15. /**
  16. * @file dmacHw.h
  17. *
  18. * @brief API definitions for low level DMA controller driver
  19. *
  20. */
  21. /****************************************************************************/
  22. #ifndef _DMACHW_H
  23. #define _DMACHW_H
  24. #include <stddef.h>
  25. #include <csp/stdint.h>
  26. #include <mach/csp/dmacHw_reg.h>
  27. /* Define DMA Channel ID using DMA controller number (m) and channel number (c).
  28. System specific channel ID should be defined as follows
  29. For example:
  30. #include <dmacHw.h>
  31. ...
  32. #define systemHw_LCD_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,5)
  33. #define systemHw_SWITCH_RX_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,0)
  34. #define systemHw_SWITCH_TX_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,1)
  35. #define systemHw_APM_RX_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,3)
  36. #define systemHw_APM_TX_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,4)
  37. ...
  38. #define systemHw_SHARED1_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(1,4)
  39. #define systemHw_SHARED2_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(1,5)
  40. #define systemHw_SHARED3_CHANNEL_ID dmacHw_MAKE_CHANNEL_ID(0,6)
  41. ...
  42. */
  43. #define dmacHw_MAKE_CHANNEL_ID(m, c) (m << 8 | c)
  44. typedef enum {
  45. dmacHw_CHANNEL_PRIORITY_0 = dmacHw_REG_CFG_LO_CH_PRIORITY_0, /* Channel priority 0. Lowest priority DMA channel */
  46. dmacHw_CHANNEL_PRIORITY_1 = dmacHw_REG_CFG_LO_CH_PRIORITY_1, /* Channel priority 1 */
  47. dmacHw_CHANNEL_PRIORITY_2 = dmacHw_REG_CFG_LO_CH_PRIORITY_2, /* Channel priority 2 */
  48. dmacHw_CHANNEL_PRIORITY_3 = dmacHw_REG_CFG_LO_CH_PRIORITY_3, /* Channel priority 3 */
  49. dmacHw_CHANNEL_PRIORITY_4 = dmacHw_REG_CFG_LO_CH_PRIORITY_4, /* Channel priority 4 */
  50. dmacHw_CHANNEL_PRIORITY_5 = dmacHw_REG_CFG_LO_CH_PRIORITY_5, /* Channel priority 5 */
  51. dmacHw_CHANNEL_PRIORITY_6 = dmacHw_REG_CFG_LO_CH_PRIORITY_6, /* Channel priority 6 */
  52. dmacHw_CHANNEL_PRIORITY_7 = dmacHw_REG_CFG_LO_CH_PRIORITY_7 /* Channel priority 7. Highest priority DMA channel */
  53. } dmacHw_CHANNEL_PRIORITY_e;
  54. /* Source destination master interface */
  55. typedef enum {
  56. dmacHw_SRC_MASTER_INTERFACE_1 = dmacHw_REG_CTL_SMS_1, /* Source DMA master interface 1 */
  57. dmacHw_SRC_MASTER_INTERFACE_2 = dmacHw_REG_CTL_SMS_2, /* Source DMA master interface 2 */
  58. dmacHw_DST_MASTER_INTERFACE_1 = dmacHw_REG_CTL_DMS_1, /* Destination DMA master interface 1 */
  59. dmacHw_DST_MASTER_INTERFACE_2 = dmacHw_REG_CTL_DMS_2 /* Destination DMA master interface 2 */
  60. } dmacHw_MASTER_INTERFACE_e;
  61. typedef enum {
  62. dmacHw_SRC_TRANSACTION_WIDTH_8 = dmacHw_REG_CTL_SRC_TR_WIDTH_8, /* Source 8 bit (1 byte) per transaction */
  63. dmacHw_SRC_TRANSACTION_WIDTH_16 = dmacHw_REG_CTL_SRC_TR_WIDTH_16, /* Source 16 bit (2 byte) per transaction */
  64. dmacHw_SRC_TRANSACTION_WIDTH_32 = dmacHw_REG_CTL_SRC_TR_WIDTH_32, /* Source 32 bit (4 byte) per transaction */
  65. dmacHw_SRC_TRANSACTION_WIDTH_64 = dmacHw_REG_CTL_SRC_TR_WIDTH_64, /* Source 64 bit (8 byte) per transaction */
  66. dmacHw_DST_TRANSACTION_WIDTH_8 = dmacHw_REG_CTL_DST_TR_WIDTH_8, /* Destination 8 bit (1 byte) per transaction */
  67. dmacHw_DST_TRANSACTION_WIDTH_16 = dmacHw_REG_CTL_DST_TR_WIDTH_16, /* Destination 16 bit (2 byte) per transaction */
  68. dmacHw_DST_TRANSACTION_WIDTH_32 = dmacHw_REG_CTL_DST_TR_WIDTH_32, /* Destination 32 bit (4 byte) per transaction */
  69. dmacHw_DST_TRANSACTION_WIDTH_64 = dmacHw_REG_CTL_DST_TR_WIDTH_64 /* Destination 64 bit (8 byte) per transaction */
  70. } dmacHw_TRANSACTION_WIDTH_e;
  71. typedef enum {
  72. dmacHw_SRC_BURST_WIDTH_0 = dmacHw_REG_CTL_SRC_MSIZE_0, /* Source No burst */
  73. dmacHw_SRC_BURST_WIDTH_4 = dmacHw_REG_CTL_SRC_MSIZE_4, /* Source 4 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  74. dmacHw_SRC_BURST_WIDTH_8 = dmacHw_REG_CTL_SRC_MSIZE_8, /* Source 8 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  75. dmacHw_SRC_BURST_WIDTH_16 = dmacHw_REG_CTL_SRC_MSIZE_16, /* Source 16 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  76. dmacHw_DST_BURST_WIDTH_0 = dmacHw_REG_CTL_DST_MSIZE_0, /* Destination No burst */
  77. dmacHw_DST_BURST_WIDTH_4 = dmacHw_REG_CTL_DST_MSIZE_4, /* Destination 4 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  78. dmacHw_DST_BURST_WIDTH_8 = dmacHw_REG_CTL_DST_MSIZE_8, /* Destination 8 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  79. dmacHw_DST_BURST_WIDTH_16 = dmacHw_REG_CTL_DST_MSIZE_16 /* Destination 16 X dmacHw_TRANSACTION_WIDTH_xxx bytes per burst */
  80. } dmacHw_BURST_WIDTH_e;
  81. typedef enum {
  82. dmacHw_TRANSFER_TYPE_MEM_TO_MEM = dmacHw_REG_CTL_TTFC_MM_DMAC, /* Memory to memory transfer */
  83. dmacHw_TRANSFER_TYPE_PERIPHERAL_TO_MEM = dmacHw_REG_CTL_TTFC_PM_DMAC, /* Peripheral to memory transfer */
  84. dmacHw_TRANSFER_TYPE_MEM_TO_PERIPHERAL = dmacHw_REG_CTL_TTFC_MP_DMAC, /* Memory to peripheral transfer */
  85. dmacHw_TRANSFER_TYPE_PERIPHERAL_TO_PERIPHERAL = dmacHw_REG_CTL_TTFC_PP_DMAC /* Peripheral to peripheral transfer */
  86. } dmacHw_TRANSFER_TYPE_e;
  87. typedef enum {
  88. dmacHw_TRANSFER_MODE_PERREQUEST, /* Block transfer per DMA request */
  89. dmacHw_TRANSFER_MODE_CONTINUOUS, /* Continuous transfer of streaming data */
  90. dmacHw_TRANSFER_MODE_PERIODIC /* Periodic transfer of streaming data */
  91. } dmacHw_TRANSFER_MODE_e;
  92. typedef enum {
  93. dmacHw_SRC_ADDRESS_UPDATE_MODE_INC = dmacHw_REG_CTL_SINC_INC, /* Increment source address after every transaction */
  94. dmacHw_SRC_ADDRESS_UPDATE_MODE_DEC = dmacHw_REG_CTL_SINC_DEC, /* Decrement source address after every transaction */
  95. dmacHw_DST_ADDRESS_UPDATE_MODE_INC = dmacHw_REG_CTL_DINC_INC, /* Increment destination address after every transaction */
  96. dmacHw_DST_ADDRESS_UPDATE_MODE_DEC = dmacHw_REG_CTL_DINC_DEC, /* Decrement destination address after every transaction */
  97. dmacHw_SRC_ADDRESS_UPDATE_MODE_NC = dmacHw_REG_CTL_SINC_NC, /* No change in source address after every transaction */
  98. dmacHw_DST_ADDRESS_UPDATE_MODE_NC = dmacHw_REG_CTL_DINC_NC /* No change in destination address after every transaction */
  99. } dmacHw_ADDRESS_UPDATE_MODE_e;
  100. typedef enum {
  101. dmacHw_FLOW_CONTROL_DMA, /* DMA working as flow controller (default) */
  102. dmacHw_FLOW_CONTROL_PERIPHERAL /* Peripheral working as flow controller */
  103. } dmacHw_FLOW_CONTROL_e;
  104. typedef enum {
  105. dmacHw_TRANSFER_STATUS_BUSY, /* DMA Transfer ongoing */
  106. dmacHw_TRANSFER_STATUS_DONE, /* DMA Transfer completed */
  107. dmacHw_TRANSFER_STATUS_ERROR /* DMA Transfer error */
  108. } dmacHw_TRANSFER_STATUS_e;
  109. typedef enum {
  110. dmacHw_INTERRUPT_DISABLE, /* Interrupt disable */
  111. dmacHw_INTERRUPT_ENABLE /* Interrupt enable */
  112. } dmacHw_INTERRUPT_e;
  113. typedef enum {
  114. dmacHw_INTERRUPT_STATUS_NONE = 0x0, /* No DMA interrupt */
  115. dmacHw_INTERRUPT_STATUS_TRANS = 0x1, /* End of DMA transfer interrupt */
  116. dmacHw_INTERRUPT_STATUS_BLOCK = 0x2, /* End of block transfer interrupt */
  117. dmacHw_INTERRUPT_STATUS_ERROR = 0x4 /* Error interrupt */
  118. } dmacHw_INTERRUPT_STATUS_e;
  119. typedef enum {
  120. dmacHw_CONTROLLER_ATTRIB_CHANNEL_NUM, /* Number of DMA channel */
  121. dmacHw_CONTROLLER_ATTRIB_CHANNEL_MAX_BLOCK_SIZE, /* Maximum channel burst size */
  122. dmacHw_CONTROLLER_ATTRIB_MASTER_INTF_NUM, /* Number of DMA master interface */
  123. dmacHw_CONTROLLER_ATTRIB_CHANNEL_BUS_WIDTH, /* Channel Data bus width */
  124. dmacHw_CONTROLLER_ATTRIB_CHANNEL_FIFO_SIZE /* Channel FIFO size */
  125. } dmacHw_CONTROLLER_ATTRIB_e;
  126. typedef unsigned long dmacHw_HANDLE_t; /* DMA channel handle */
  127. typedef uint32_t dmacHw_ID_t; /* DMA channel Id. Must be created using
  128. "dmacHw_MAKE_CHANNEL_ID" macro
  129. */
  130. /* DMA channel configuration parameters */
  131. typedef struct {
  132. uint32_t srcPeripheralPort; /* Source peripheral port */
  133. uint32_t dstPeripheralPort; /* Destination peripheral port */
  134. uint32_t srcStatusRegisterAddress; /* Source status register address */
  135. uint32_t dstStatusRegisterAddress; /* Destination status register address of type */
  136. uint32_t srcGatherWidth; /* Number of bytes gathered before successive gather opearation */
  137. uint32_t srcGatherJump; /* Number of bytes jumpped before successive gather opearation */
  138. uint32_t dstScatterWidth; /* Number of bytes sacattered before successive scatter opearation */
  139. uint32_t dstScatterJump; /* Number of bytes jumpped before successive scatter opearation */
  140. uint32_t maxDataPerBlock; /* Maximum number of bytes to be transferred per block/descrptor.
  141. 0 = Maximum possible.
  142. */
  143. dmacHw_ADDRESS_UPDATE_MODE_e srcUpdate; /* Source address update mode */
  144. dmacHw_ADDRESS_UPDATE_MODE_e dstUpdate; /* Destination address update mode */
  145. dmacHw_TRANSFER_TYPE_e transferType; /* DMA transfer type */
  146. dmacHw_TRANSFER_MODE_e transferMode; /* DMA transfer mode */
  147. dmacHw_MASTER_INTERFACE_e srcMasterInterface; /* DMA source interface */
  148. dmacHw_MASTER_INTERFACE_e dstMasterInterface; /* DMA destination interface */
  149. dmacHw_TRANSACTION_WIDTH_e srcMaxTransactionWidth; /* Source transaction width */
  150. dmacHw_TRANSACTION_WIDTH_e dstMaxTransactionWidth; /* Destination transaction width */
  151. dmacHw_BURST_WIDTH_e srcMaxBurstWidth; /* Source burst width */
  152. dmacHw_BURST_WIDTH_e dstMaxBurstWidth; /* Destination burst width */
  153. dmacHw_INTERRUPT_e blockTransferInterrupt; /* Block trsnafer interrupt */
  154. dmacHw_INTERRUPT_e completeTransferInterrupt; /* Complete DMA trsnafer interrupt */
  155. dmacHw_INTERRUPT_e errorInterrupt; /* Error interrupt */
  156. dmacHw_CHANNEL_PRIORITY_e channelPriority; /* Channel priority */
  157. dmacHw_FLOW_CONTROL_e flowControler; /* Data flow controller */
  158. } dmacHw_CONFIG_t;
  159. /****************************************************************************/
  160. /**
  161. * @brief Initializes DMA
  162. *
  163. * This function initializes DMA CSP driver
  164. *
  165. * @note
  166. * Must be called before using any DMA channel
  167. */
  168. /****************************************************************************/
  169. void dmacHw_initDma(void);
  170. /****************************************************************************/
  171. /**
  172. * @brief Exit function for DMA
  173. *
  174. * This function isolates DMA from the system
  175. *
  176. */
  177. /****************************************************************************/
  178. void dmacHw_exitDma(void);
  179. /****************************************************************************/
  180. /**
  181. * @brief Gets a handle to a DMA channel
  182. *
  183. * This function returns a handle, representing a control block of a particular DMA channel
  184. *
  185. * @return -1 - On Failure
  186. * handle - On Success, representing a channel control block
  187. *
  188. * @note
  189. * None Channel ID must be created using "dmacHw_MAKE_CHANNEL_ID" macro
  190. */
  191. /****************************************************************************/
  192. dmacHw_HANDLE_t dmacHw_getChannelHandle(dmacHw_ID_t channelId /* [ IN ] DMA Channel Id */
  193. );
  194. /****************************************************************************/
  195. /**
  196. * @brief Initializes a DMA channel for use
  197. *
  198. * This function initializes and resets a DMA channel for use
  199. *
  200. * @return -1 - On Failure
  201. * 0 - On Success
  202. *
  203. * @note
  204. * None
  205. */
  206. /****************************************************************************/
  207. int dmacHw_initChannel(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  208. );
  209. /****************************************************************************/
  210. /**
  211. * @brief Estimates number of descriptor needed to perform certain DMA transfer
  212. *
  213. *
  214. * @return On failure : -1
  215. * On success : Number of descriptor count
  216. *
  217. *
  218. */
  219. /****************************************************************************/
  220. int dmacHw_calculateDescriptorCount(dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  221. void *pSrcAddr, /* [ IN ] Source (Peripheral/Memory) address */
  222. void *pDstAddr, /* [ IN ] Destination (Peripheral/Memory) address */
  223. size_t dataLen /* [ IN ] Data length in bytes */
  224. );
  225. /****************************************************************************/
  226. /**
  227. * @brief Initializes descriptor ring
  228. *
  229. * This function will initializes the descriptor ring of a DMA channel
  230. *
  231. *
  232. * @return -1 - On failure
  233. * 0 - On success
  234. * @note
  235. * - "len" parameter should be obtained from "dmacHw_descriptorLen"
  236. * - Descriptor buffer MUST be 32 bit aligned and uncached as it
  237. * is accessed by ARM and DMA
  238. */
  239. /****************************************************************************/
  240. int dmacHw_initDescriptor(void *pDescriptorVirt, /* [ IN ] Virtual address of uncahced buffer allocated to form descriptor ring */
  241. uint32_t descriptorPhyAddr, /* [ IN ] Physical address of pDescriptorVirt (descriptor buffer) */
  242. uint32_t len, /* [ IN ] Size of the pBuf */
  243. uint32_t num /* [ IN ] Number of descriptor in the ring */
  244. );
  245. /****************************************************************************/
  246. /**
  247. * @brief Finds amount of memory required to form a descriptor ring
  248. *
  249. *
  250. * @return Number of bytes required to form a descriptor ring
  251. *
  252. *
  253. * @note
  254. * None
  255. */
  256. /****************************************************************************/
  257. uint32_t dmacHw_descriptorLen(uint32_t descCnt /* [ IN ] Number of descriptor in the ring */
  258. );
  259. /****************************************************************************/
  260. /**
  261. * @brief Configure DMA channel
  262. *
  263. * @return 0 : On success
  264. * -1 : On failure
  265. */
  266. /****************************************************************************/
  267. int dmacHw_configChannel(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  268. dmacHw_CONFIG_t *pConfig /* [ IN ] Configuration settings */
  269. );
  270. /****************************************************************************/
  271. /**
  272. * @brief Set descriptors for known data length
  273. *
  274. * When DMA has to work as a flow controller, this function prepares the
  275. * descriptor chain to transfer data
  276. *
  277. * from:
  278. * - Memory to memory
  279. * - Peripheral to memory
  280. * - Memory to Peripheral
  281. * - Peripheral to Peripheral
  282. *
  283. * @return -1 - On failure
  284. * 0 - On success
  285. *
  286. */
  287. /****************************************************************************/
  288. int dmacHw_setDataDescriptor(dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  289. void *pDescriptor, /* [ IN ] Descriptor buffer */
  290. void *pSrcAddr, /* [ IN ] Source (Peripheral/Memory) address */
  291. void *pDstAddr, /* [ IN ] Destination (Peripheral/Memory) address */
  292. size_t dataLen /* [ IN ] Length in bytes */
  293. );
  294. /****************************************************************************/
  295. /**
  296. * @brief Indicates whether DMA transfer is in progress or completed
  297. *
  298. * @return DMA transfer status
  299. * dmacHw_TRANSFER_STATUS_BUSY: DMA Transfer ongoing
  300. * dmacHw_TRANSFER_STATUS_DONE: DMA Transfer completed
  301. * dmacHw_TRANSFER_STATUS_ERROR: DMA Transfer error
  302. *
  303. */
  304. /****************************************************************************/
  305. dmacHw_TRANSFER_STATUS_e dmacHw_transferCompleted(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  306. );
  307. /****************************************************************************/
  308. /**
  309. * @brief Set descriptor carrying control information
  310. *
  311. * This function will be used to send specific control information to the device
  312. * using the DMA channel
  313. *
  314. *
  315. * @return -1 - On failure
  316. * 0 - On success
  317. *
  318. * @note
  319. * None
  320. */
  321. /****************************************************************************/
  322. int dmacHw_setControlDescriptor(dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  323. void *pDescriptor, /* [ IN ] Descriptor buffer */
  324. uint32_t ctlAddress, /* [ IN ] Address of the device control register */
  325. uint32_t control /* [ IN ] Device control information */
  326. );
  327. /****************************************************************************/
  328. /**
  329. * @brief Read data DMA transferred to memory
  330. *
  331. * This function will read data that has been DMAed to memory while transfering from:
  332. * - Memory to memory
  333. * - Peripheral to memory
  334. *
  335. * @return 0 - No more data is available to read
  336. * 1 - More data might be available to read
  337. *
  338. */
  339. /****************************************************************************/
  340. int dmacHw_readTransferredData(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  341. dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  342. void *pDescriptor, /* [ IN ] Descriptor buffer */
  343. void **ppBbuf, /* [ OUT ] Data received */
  344. size_t *pLlen /* [ OUT ] Length of the data received */
  345. );
  346. /****************************************************************************/
  347. /**
  348. * @brief Prepares descriptor ring, when source peripheral working as a flow controller
  349. *
  350. * This function will form the descriptor ring by allocating buffers, when source peripheral
  351. * has to work as a flow controller to transfer data from:
  352. * - Peripheral to memory.
  353. *
  354. * @return -1 - On failure
  355. * 0 - On success
  356. *
  357. *
  358. * @note
  359. * None
  360. */
  361. /****************************************************************************/
  362. int dmacHw_setVariableDataDescriptor(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  363. dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  364. void *pDescriptor, /* [ IN ] Descriptor buffer */
  365. uint32_t srcAddr, /* [ IN ] Source peripheral address */
  366. void *(*fpAlloc) (int len), /* [ IN ] Function pointer that provides destination memory */
  367. int len, /* [ IN ] Number of bytes "fpAlloc" will allocate for destination */
  368. int num /* [ IN ] Number of descriptor to set */
  369. );
  370. /****************************************************************************/
  371. /**
  372. * @brief Program channel register to initiate transfer
  373. *
  374. * @return void
  375. *
  376. *
  377. * @note
  378. * - Descriptor buffer MUST ALWAYS be flushed before calling this function
  379. * - This function should also be called from ISR to program the channel with
  380. * pending descriptors
  381. */
  382. /****************************************************************************/
  383. void dmacHw_initiateTransfer(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  384. dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  385. void *pDescriptor /* [ IN ] Descriptor buffer */
  386. );
  387. /****************************************************************************/
  388. /**
  389. * @brief Resets descriptor control information
  390. *
  391. * @return void
  392. */
  393. /****************************************************************************/
  394. void dmacHw_resetDescriptorControl(void *pDescriptor /* [ IN ] Descriptor buffer */
  395. );
  396. /****************************************************************************/
  397. /**
  398. * @brief Program channel register to stop transfer
  399. *
  400. * Ensures the channel is not doing any transfer after calling this function
  401. *
  402. * @return void
  403. *
  404. */
  405. /****************************************************************************/
  406. void dmacHw_stopTransfer(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  407. );
  408. /****************************************************************************/
  409. /**
  410. * @brief Check the existance of pending descriptor
  411. *
  412. * This function confirmes if there is any pending descriptor in the chain
  413. * to program the channel
  414. *
  415. * @return 1 : Channel need to be programmed with pending descriptor
  416. * 0 : No more pending descriptor to programe the channel
  417. *
  418. * @note
  419. * - This function should be called from ISR in case there are pending
  420. * descriptor to program the channel.
  421. *
  422. * Example:
  423. *
  424. * dmac_isr ()
  425. * {
  426. * ...
  427. * if (dmacHw_descriptorPending (handle))
  428. * {
  429. * dmacHw_initiateTransfer (handle);
  430. * }
  431. * }
  432. *
  433. */
  434. /****************************************************************************/
  435. uint32_t dmacHw_descriptorPending(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  436. void *pDescriptor /* [ IN ] Descriptor buffer */
  437. );
  438. /****************************************************************************/
  439. /**
  440. * @brief Deallocates source or destination memory, allocated
  441. *
  442. * This function can be called to deallocate data memory that was DMAed successfully
  443. *
  444. * @return -1 - On failure
  445. * 0 - On success
  446. *
  447. * @note
  448. * This function will be called ONLY, when source OR destination address is pointing
  449. * to dynamic memory
  450. */
  451. /****************************************************************************/
  452. int dmacHw_freeMem(dmacHw_CONFIG_t *pConfig, /* [ IN ] Configuration settings */
  453. void *pDescriptor, /* [ IN ] Descriptor buffer */
  454. void (*fpFree) (void *) /* [ IN ] Function pointer to free data memory */
  455. );
  456. /****************************************************************************/
  457. /**
  458. * @brief Clears the interrupt
  459. *
  460. * This function clears the DMA channel specific interrupt
  461. *
  462. * @return N/A
  463. *
  464. * @note
  465. * Must be called under the context of ISR
  466. */
  467. /****************************************************************************/
  468. void dmacHw_clearInterrupt(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  469. );
  470. /****************************************************************************/
  471. /**
  472. * @brief Returns the cause of channel specific DMA interrupt
  473. *
  474. * This function returns the cause of interrupt
  475. *
  476. * @return Interrupt status, each bit representing a specific type of interrupt
  477. * of type dmacHw_INTERRUPT_STATUS_e
  478. * @note
  479. * This function should be called under the context of ISR
  480. */
  481. /****************************************************************************/
  482. dmacHw_INTERRUPT_STATUS_e dmacHw_getInterruptStatus(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  483. );
  484. /****************************************************************************/
  485. /**
  486. * @brief Indentifies a DMA channel causing interrupt
  487. *
  488. * This functions returns a channel causing interrupt of type dmacHw_INTERRUPT_STATUS_e
  489. *
  490. * @return NULL : No channel causing DMA interrupt
  491. * ! NULL : Handle to a channel causing DMA interrupt
  492. * @note
  493. * dmacHw_clearInterrupt() must be called with a valid handle after calling this function
  494. */
  495. /****************************************************************************/
  496. dmacHw_HANDLE_t dmacHw_getInterruptSource(void);
  497. /****************************************************************************/
  498. /**
  499. * @brief Sets channel specific user data
  500. *
  501. * This function associates user data to a specif DMA channel
  502. *
  503. */
  504. /****************************************************************************/
  505. void dmacHw_setChannelUserData(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  506. void *userData /* [ IN ] User data */
  507. );
  508. /****************************************************************************/
  509. /**
  510. * @brief Gets channel specific user data
  511. *
  512. * This function returns user data specific to a DMA channel
  513. *
  514. * @return user data
  515. */
  516. /****************************************************************************/
  517. void *dmacHw_getChannelUserData(dmacHw_HANDLE_t handle /* [ IN ] DMA Channel handle */
  518. );
  519. /****************************************************************************/
  520. /**
  521. * @brief Displays channel specific registers and other control parameters
  522. *
  523. *
  524. * @return void
  525. *
  526. * @note
  527. * None
  528. */
  529. /****************************************************************************/
  530. void dmacHw_printDebugInfo(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  531. void *pDescriptor, /* [ IN ] Descriptor buffer */
  532. int (*fpPrint) (const char *, ...) /* [ IN ] Print callback function */
  533. );
  534. /****************************************************************************/
  535. /**
  536. * @brief Provides DMA controller attributes
  537. *
  538. *
  539. * @return DMA controller attributes
  540. *
  541. * @note
  542. * None
  543. */
  544. /****************************************************************************/
  545. uint32_t dmacHw_getDmaControllerAttribute(dmacHw_HANDLE_t handle, /* [ IN ] DMA Channel handle */
  546. dmacHw_CONTROLLER_ATTRIB_e attr /* [ IN ] DMA Controler attribute of type dmacHw_CONTROLLER_ATTRIB_e */
  547. );
  548. #endif /* _DMACHW_H */