edma.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /**
  2. * \file edma.h
  3. *
  4. * \brief This file contains the function prototypes for the device
  5. * abstraction layer for EDMA. It also contains some
  6. * related macro definitions and some files to be included.
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef __EDMA_H__
  42. #define __EDMA_H__
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include "hw_edma3cc.h"
  46. #include "hw_edma3tc.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. //***********************************************************************
  51. // Values that can be used by the application for configuration via APIs
  52. //***********************************************************************/
  53. /** Maximum number of EDMA Shadow regions available */
  54. #define EDMA3_MAX_REGIONS (2u)
  55. /** Number of PaRAM Sets available */
  56. #define EDMA3_NUM_PARAMSET (128u)
  57. /** Number of Event Queues available */
  58. #define EDMA3_0_NUM_EVTQUE (2u)
  59. /** Number of Transfer Controllers available */
  60. #define EDMA3_0_NUM_TC (2u)
  61. /** Interrupt no. for Transfer Completion */
  62. #define EDMA3_0_CC_XFER_COMPLETION_INT (11u)
  63. /** Interrupt no. for CC Error */
  64. #define EDMA3_0_CC0_ERRINT (12u)
  65. /** Interrupt no. for TCs Error */
  66. #define EDMA3_0_TC0_ERRINT (13u)
  67. #define EDMA3_0_TC1_ERRINT (32u)
  68. #define EDMA3CC_DMA_CHANNELS (32u)
  69. #define EDMA3CC_QDMA_CHANNELS (8u)
  70. /** DMAQNUM bits Clear */
  71. #define EDMA3CC_DMAQNUM_CLR(chNum) ( ~ (0x7u << (((chNum) % 8u) \
  72. * 4u)))
  73. /** DMAQNUM bits Set */
  74. #define EDMA3CC_DMAQNUM_SET(chNum,queNum) ((0x7u & (queNum)) << \
  75. (((chNum) % 8u) * 4u))
  76. /** QDMAQNUM bits Clear */
  77. #define EDMA3CC_QDMAQNUM_CLR(chNum) ( ~ (0x7u << ((chNum) * 4u)))
  78. /** QDMAQNUM bits Set */
  79. #define EDMA3CC_QDMAQNUM_SET(chNum,queNum) ((0x7u & (queNum)) << \
  80. ((chNum) * 4u))
  81. #define EDMA3CC_QCHMAP_PAENTRY_CLR (~EDMA3CC_QCHMAP_PAENTRY)
  82. /** QCHMAP-PaRAMEntry bitfield Set */
  83. #define EDMA3CC_QCHMAP_PAENTRY_SET(paRAMId) (((EDMA3CC_QCHMAP_PAENTRY >> \
  84. EDMA3CC_QCHMAP_PAENTRY_SHIFT) & \
  85. (paRAMId)) << \
  86. EDMA3CC_QCHMAP_PAENTRY_SHIFT)
  87. /** QCHMAP-TrigWord bitfield Clear */
  88. #define EDMA3CC_QCHMAP_TRWORD_CLR (~EDMA3CC_QCHMAP_TRWORD)
  89. /** QCHMAP-TrigWord bitfield Set */
  90. #define EDMA3CC_QCHMAP_TRWORD_SET(paRAMId) (((EDMA3CC_QCHMAP_TRWORD >> \
  91. EDMA3CC_QCHMAP_TRWORD_SHIFT) & \
  92. (paRAMId)) << \
  93. EDMA3CC_QCHMAP_TRWORD_SHIFT)
  94. /** OPT-TCC bitfield Clear */
  95. #define EDMA3CC_OPT_TCC_CLR (~EDMA3CC_OPT_TCC)
  96. /** OPT-TCC bitfield Set */
  97. #define EDMA3CC_OPT_TCC_SET(tcc) (((EDMA3CC_OPT_TCC >> \
  98. EDMA3CC_OPT_TCC_SHIFT) & \
  99. (tcc)) << EDMA3CC_OPT_TCC_SHIFT)
  100. #define EDMA3_SET_ALL_BITS (0xFFFFFFFFu)
  101. #define EDMA3_CLR_ALL_BITS (0x00000000u)
  102. #define EDMA3CC_COMPL_HANDLER_RETRY_COUNT (10u)
  103. #define EDMA3CC_ERR_HANDLER_RETRY_COUNT (10u)
  104. #define EDMA3_TRIG_MODE_MANUAL (0u)
  105. #define EDMA3_TRIG_MODE_QDMA (1u)
  106. #define EDMA3_TRIG_MODE_EVENT (2u)
  107. #define EDMA3_CHANNEL_TYPE_DMA (0u)
  108. #define EDMA3_CHANNEL_TYPE_QDMA (1u)
  109. #define EDMA3_XFER_COMPLETE (0u)
  110. #define EDMA3_CC_DMA_EVT_MISS (1u)
  111. #define EDMA3_CC_QDMA_EVT_MISS (2u)
  112. #define EDMA3_SYNC_A (0u)
  113. #define EDMA3_SYNC_AB (1u)
  114. #define EDMA3CC_CLR_TCCERR EDMA3CC_CCERRCLR_TCCERR
  115. #define EDMA3CC_CLR_QTHRQ0 EDMA3CC_CCERRCLR_QTHRXCD0
  116. #define EDMA3CC_CLR_QTHRQ1 EDMA3CC_CCERRCLR_QTHRXCD1
  117. /* paRAMEntry Fields*/
  118. /**
  119. * The OPT field (Offset Address 0x0 Bytes)
  120. */
  121. #define EDMA3CC_PARAM_ENTRY_OPT (0x0u)
  122. /**
  123. * The SRC field (Offset Address 0x4 Bytes)
  124. */
  125. #define EDMA3CC_PARAM_ENTRY_SRC (0x1u)
  126. /**
  127. * The (ACNT+BCNT) field (Offset Address 0x8 Bytes)
  128. */
  129. #define EDMA3CC_PARAM_ENTRY_ACNT_BCNT (0x2u)
  130. /**
  131. * The DST field (Offset Address 0xC Bytes)
  132. */
  133. #define EDMA3CC_PARAM_ENTRY_DST (0x3u)
  134. /**
  135. * The (SRCBIDX+DSTBIDX) field (Offset Address 0x10 Bytes)
  136. */
  137. #define EDMA3CC_PARAM_ENTRY_SRC_DST_BIDX (0x4u)
  138. /**
  139. * The (LINK+BCNTRLD) field (Offset Address 0x14 Bytes)
  140. */
  141. #define EDMA3CC_PARAM_ENTRY_LINK_BCNTRLD (0x5u)
  142. /**
  143. * The (SRCCIDX+DSTCIDX) field (Offset Address 0x18 Bytes)
  144. */
  145. #define EDMA3CC_PARAM_ENTRY_SRC_DST_CIDX (0x6u)
  146. /**
  147. * The (CCNT+RSVD) field (Offset Address 0x1C Bytes)
  148. */
  149. #define EDMA3CC_PARAM_ENTRY_CCNT (0x7u)
  150. /** The offset for each PaRAM Entry field */
  151. #define EDMA3CC_PARAM_FIELD_OFFSET (0x4u)
  152. /** Number of PaRAM Entry fields
  153. * OPT, SRC, A_B_CNT, DST, SRC_DST_BIDX, LINK_BCNTRLD, SRC_DST_CIDX
  154. * and CCNT
  155. */
  156. #define EDMA3CC_PARAM_ENTRY_FIELDS (0x8u)
  157. #define EDMA_REVID_AM335X (0x02u)
  158. #if defined(am335x) || defined(am335x_13x13) || defined(am335x_15x15) || \
  159. defined(c6a811x) || defined(am386x) || defined(c6741x)
  160. #define SOC_EDMA3_NUM_DMACH 64
  161. #define SOC_EDMA3_NUM_QDMACH 8
  162. #define SOC_EDMA3_NUM_PARAMSETS 256
  163. #define SOC_EDMA3_NUM_EVQUE 4
  164. #define SOC_EDMA3_CHMAPEXIST 0
  165. #define SOC_EDMA3_NUM_REGIONS 8
  166. #define SOC_EDMA3_MEMPROTECT 0
  167. #endif
  168. #if defined(am1808) || defined(omapl138) || defined(c6748)
  169. #define SOC_EDMA3_NUM_DMACH 32
  170. #define SOC_EDMA3_NUM_QDMACH 8
  171. #define SOC_EDMA3_NUM_PARAMSETS 128
  172. #define SOC_EDMA3_NUM_EVQUE 2
  173. #define SOC_EDMA3_CHMAPEXIST 0
  174. #define SOC_EDMA3_NUM_REGIONS 4
  175. #define SOC_EDMA3_MEMPROTECT 0
  176. #endif
  177. /** Number of TCCS available */
  178. #define EDMA3_NUM_TCC SOC_EDMA3_NUM_DMACH
  179. /**
  180. * \brief EDMA3 Parameter RAM Set in User Configurable format
  181. *
  182. * This is a mapping of the EDMA3 PaRAM set provided to the user
  183. * for ease of modification of the individual fields
  184. */
  185. typedef struct EDMA3CCPaRAMEntry {
  186. /** OPT field of PaRAM Set */
  187. unsigned int opt;
  188. /**
  189. * \brief Starting byte address of Source
  190. * For FIFO mode, srcAddr must be a 256-bit aligned address.
  191. */
  192. unsigned int srcAddr;
  193. /**
  194. * \brief Number of bytes in each Array (ACNT)
  195. */
  196. unsigned short aCnt;
  197. /**
  198. * \brief Number of Arrays in each Frame (BCNT)
  199. */
  200. unsigned short bCnt;
  201. /**
  202. * \brief Starting byte address of destination
  203. * For FIFO mode, destAddr must be a 256-bit aligned address.
  204. * i.e. 5 LSBs should be 0.
  205. */
  206. unsigned int destAddr;
  207. /**
  208. * \brief Index between consec. arrays of a Source Frame (SRCBIDX)
  209. */
  210. short srcBIdx;
  211. /**
  212. * \brief Index between consec. arrays of a Destination Frame (DSTBIDX)
  213. */
  214. short destBIdx;
  215. /**
  216. * \brief Address for linking (AutoReloading of a PaRAM Set)
  217. * This must point to a valid aligned 32-byte PaRAM set
  218. * A value of 0xFFFF means no linking
  219. */
  220. unsigned short linkAddr;
  221. /**
  222. * \brief Reload value of the numArrInFrame (BCNT)
  223. * Relevant only for A-sync transfers
  224. */
  225. unsigned short bCntReload;
  226. /**
  227. * \brief Index between consecutive frames of a Source Block (SRCCIDX)
  228. */
  229. short srcCIdx;
  230. /**
  231. * \brief Index between consecutive frames of a Dest Block (DSTCIDX)
  232. */
  233. short destCIdx;
  234. /**
  235. * \brief Number of Frames in a block (CCNT)
  236. */
  237. unsigned short cCnt;
  238. /**
  239. * \brief This field is Reserved. Write zero to this field.
  240. */
  241. unsigned short rsvd;
  242. }EDMA3CCPaRAMEntry;
  243. /*
  244. ** Structure to store the EDMA context
  245. */
  246. typedef struct edmaContext {
  247. /* Channel mapping reg Val */
  248. unsigned int dchMap[64];
  249. /* DMA Queue Number Register Val */
  250. unsigned int dmaQNum[8];
  251. /* DMA Region Access Enable Register val */
  252. unsigned int regAccEnableLow;
  253. unsigned int regAccEnableHigh;
  254. /* Event Set Register value */
  255. unsigned int eventSetRegLow;
  256. unsigned int eventSetRegHigh;
  257. /* Enable Event Set Register value */
  258. unsigned int enableEvtSetRegLow;
  259. unsigned int enableEvtSetRegHigh;
  260. /* Interrupt Enable Set Register value */
  261. unsigned int intEnableSetRegLow;
  262. unsigned int intEnableSetRegHigh;
  263. struct EDMA3CCPaRAMEntry dmaParEntry[512];
  264. } EDMACONTEXT;
  265. /****************************************************************************
  266. ** API FUNCTION PROTOTYPES
  267. ****************************************************************************/
  268. void EDMA3Init(unsigned int baseAdd,
  269. unsigned int queNum);
  270. void EDMA3EnableChInShadowReg(unsigned int baseAdd,
  271. unsigned int chType,
  272. unsigned int chNum);
  273. void EDMA3DisableChInShadowReg(unsigned int baseAdd,
  274. unsigned int chType,
  275. unsigned int chNum);
  276. void EDMA3MapChToEvtQ(unsigned int baseAdd,
  277. unsigned int chType,
  278. unsigned int chNum,
  279. unsigned int evtQNum);
  280. void EDMA3UnmapChToEvtQ(unsigned int baseAdd,
  281. unsigned int chType,
  282. unsigned int chNum);
  283. void EDMA3MapQdmaChToPaRAM(unsigned int baseAdd,
  284. unsigned int chNum,
  285. unsigned int *paRAMId);
  286. void EDMA3SetQdmaTrigWord(unsigned int baseAdd,
  287. unsigned int chNum,
  288. unsigned int trigWord);
  289. void EDMA3ClrMissEvt(unsigned int baseAdd,
  290. unsigned int chNum);
  291. void EDMA3QdmaClrMissEvt(unsigned int baseAdd,
  292. unsigned int chNum);
  293. void EDMA3ClrCCErr(unsigned int baseAdd,
  294. unsigned int Flags);
  295. void EDMA3SetEvt(unsigned int baseAdd,
  296. unsigned int chNum);
  297. void EDMA3ClrEvt(unsigned int baseAdd,
  298. unsigned int chNum);
  299. void EDMA3EnableDmaEvt(unsigned int baseAdd,
  300. unsigned int chNum);
  301. void EDMA3DisableDmaEvt(unsigned int baseAdd,
  302. unsigned int chNum);
  303. void EDMA3EnableQdmaEvt(unsigned int baseAdd,
  304. unsigned int chNum);
  305. void EDMA3DisableQdmaEvt(unsigned int baseAdd,
  306. unsigned int chNum);
  307. unsigned int EDMA3GetIntrStatus(unsigned int baseAdd);
  308. void EDMA3EnableEvtIntr(unsigned int baseAdd,
  309. unsigned int chNum);
  310. void EDMA3DisableEvtIntr(unsigned int baseAdd,
  311. unsigned int chNum);
  312. void EDMA3ClrIntr(unsigned int baseAdd, unsigned int value);
  313. void EDMA3GetPaRAM(unsigned int baseAdd,
  314. unsigned int chNum,
  315. EDMA3CCPaRAMEntry* currPaRAM);
  316. void EDMA3QdmaGetPaRAM(unsigned int baseAdd,
  317. unsigned int chNum,
  318. unsigned int paRAMId,
  319. EDMA3CCPaRAMEntry* currPaRAM);
  320. void EDMA3SetPaRAM(unsigned int baseAdd,
  321. unsigned int chNum,
  322. EDMA3CCPaRAMEntry* newPaRAM);
  323. void EDMA3QdmaSetPaRAM(unsigned int baseAdd,
  324. unsigned int chNum,
  325. unsigned int paRAMId,
  326. EDMA3CCPaRAMEntry* newPaRAM);
  327. void EDMA3QdmaSetPaRAMEntry(unsigned int baseAdd,
  328. unsigned int paRAMId,
  329. unsigned int paRAMEntry,
  330. unsigned int newPaRAMEntryVal);
  331. unsigned int EDMA3QdmaGetPaRAMEntry(unsigned int baseAdd,
  332. unsigned int paRAMId,
  333. unsigned int paRAMEntry);
  334. unsigned int EDMA3RequestChannel(unsigned int baseAdd, unsigned int chType,
  335. unsigned int chNum, unsigned int tccNum,
  336. unsigned int evtQNum);
  337. unsigned int EDMA3FreeChannel(unsigned int baseAdd, unsigned int chType,
  338. unsigned int chNum, unsigned int trigMode,
  339. unsigned int tccNum, unsigned int evtQNum);
  340. unsigned int EDMA3EnableTransfer(unsigned int baseAdd,
  341. unsigned int chNum,
  342. unsigned int trigMode);
  343. unsigned int EDMA3DisableTransfer(unsigned int baseAdd,
  344. unsigned int chNum,
  345. unsigned int trigMode);
  346. void EDMA3ClearErrorBits(unsigned int baseAdd,
  347. unsigned int chNum,
  348. unsigned int evtQNum);
  349. unsigned int EDMA3GetCCErrStatus(unsigned int baseAdd);
  350. unsigned int EDMA3GetErrIntrStatus(unsigned int baseAdd);
  351. unsigned int EDMA3QdmaGetErrIntrStatus(unsigned int baseAdd);
  352. void EDMA3Deinit(unsigned int baseAdd,
  353. unsigned int queNum);
  354. unsigned int EDMAVersionGet(void);
  355. unsigned int EDMA3PeripheralIdGet(unsigned int baseAdd);
  356. unsigned int EDMA3IntrStatusHighGet(unsigned int baseAdd);
  357. unsigned int EDMA3ErrIntrHighStatusGet(unsigned int baseAdd);
  358. void EDMA3ChannelToParamMap(unsigned int baseAdd,
  359. unsigned int channel,
  360. unsigned int paramSet);
  361. extern void EDMA3ContextSave(unsigned int baseAddr,
  362. EDMACONTEXT *edmaCntxPtr);
  363. extern void EDMA3ContextRestore(unsigned int baseAddr,
  364. EDMACONTEXT *edmaCntxPtr);
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368. #endif
  369. /* !! EOF !! */