sys_dma.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /** @file dma.c
  2. * @brief DMA Driver Inmplmentation File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. */
  7. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  8. #include "sys_dma.h"
  9. /** @fn void dmaEnable(void)
  10. * @brief enables DMA module
  11. *
  12. * This function brings DMA out of reset
  13. */
  14. void dmaEnable(void)
  15. {
  16. dmaREG->GCTRL = 0x00000001U; /* reset dma */
  17. dmaREG->GCTRL |= 0x00010000U; /* enable dma */
  18. dmaREG->GCTRL |= 0x00000300U; /* stop at suspend */
  19. }
  20. /** @fn void dmaDisable(void)
  21. * @brief disables DMA module
  22. *
  23. * This function disables DMA module
  24. */
  25. void dmaDisable(void)
  26. {
  27. /* Wait until DMA's external bus has completed data transfer */
  28. while((dmaREG->GCTRL & DMA_GCTRL_BUSBUSY) != 0U)
  29. {
  30. } /* Wait */
  31. /* Disable DMA module */
  32. dmaREG->GCTRL = 0U;
  33. }
  34. /** @fn void dmaReqAssign(uint32 channel,uint32 reqline)
  35. * @brief Initializes the DMA Driver
  36. * @param[in] channel DMA channel
  37. * @param[in] reqline DMA request line
  38. *
  39. * This function assigns dma request lines to channels
  40. */
  41. void dmaReqAssign(uint32 channel,uint32 reqline)
  42. {
  43. register uint32 i=0U,j=0U;
  44. i = channel >> 2U; /* Find the register to configure */
  45. j = channel -(i<<2U); /* Find the offset of the type */
  46. j = 3U-j; /* reverse the byte order */
  47. j = j<<3U; /* find the bit location */
  48. /* mapping channel 'i' to request line 'j' */
  49. dmaREG->DREQASI[i] &= ~(0xffU<<j);
  50. dmaREG->DREQASI[i] |= (reqline<<j);
  51. }
  52. /** @fn uint32 dmaGetReq(uint32 channel)
  53. * @brief Gets the request line number mapped to the selected channel
  54. * @param[in] channel DMA channel
  55. *
  56. * This function returns the request line number mapped to the selected channel
  57. */
  58. uint32 dmaGetReq(uint32 channel)
  59. {
  60. register uint32 i=0U,j=0U;
  61. i = channel >> 2U; /* Find the register to configure */
  62. j = channel -(i<<2U); /* Find the offset of the type */
  63. j = 3U-j; /* reverse the byte order */
  64. j = j<<3U; /* find the bit location */
  65. return ((dmaREG->DREQASI[i] >> j) &0xffU);
  66. }
  67. /** @fn void dmaSetCtrlPacket(uint32 channel)
  68. * @brief Initializes the DMA Driver
  69. *
  70. * This function sets control packet
  71. */
  72. void dmaSetCtrlPacket(uint32 channel, g_dmaCTRL g_dmaCTRLPKT)
  73. {
  74. register uint32 i=0U,j=0U;
  75. dmaRAMREG->PCP[channel].ISADDR = g_dmaCTRLPKT.SADD;
  76. dmaRAMREG->PCP[channel].IDADDR = g_dmaCTRLPKT.DADD;
  77. dmaRAMREG->PCP[channel].ITCOUNT = (g_dmaCTRLPKT.FRCNT << 16U) | g_dmaCTRLPKT.ELCNT;
  78. dmaRAMREG->PCP[channel].CHCTRL = (g_dmaCTRLPKT.RDSIZE << 14U) | (g_dmaCTRLPKT.WRSIZE << 12U) | (g_dmaCTRLPKT.TTYPE << 8U)| \
  79. (g_dmaCTRLPKT.ADDMODERD << 3U ) | (g_dmaCTRLPKT.ADDMODEWR << 1U ) | (g_dmaCTRLPKT.AUTOINIT);
  80. dmaRAMREG->PCP[channel].CHCTRL |= (g_dmaCTRLPKT.CHCTRL << 16U);
  81. dmaRAMREG->PCP[channel].EIOFF = (g_dmaCTRLPKT.ELDOFFSET << 16U) | (g_dmaCTRLPKT.ELSOFFSET);
  82. dmaRAMREG->PCP[channel].FIOFF = (g_dmaCTRLPKT.FRDOFFSET << 16U) | (g_dmaCTRLPKT.FRSOFFSET);
  83. i = channel >> 3U; /* Find the register to write */
  84. j = channel -(i << 3U); /* Find the offset of the 4th bit */
  85. j = 7U -j; /* Reverse the order of the 4th bit offset */
  86. j = j<<2U; /* Find the bit location of the 4th bit to write */
  87. dmaREG->PAR[i] &= ~(0xfU<<j);
  88. dmaREG->PAR[i] |= (g_dmaCTRLPKT.PORTASGN<<j);
  89. }
  90. /** @fn void dmaSetChEnable(uint32 channel,uint32 type)
  91. * @brief Enable channel
  92. * @param[in] channel DMA channel
  93. * @param[in] type Type of triggering
  94. * - DMA_HW: Enables the selected DMA channel for hardware triggering
  95. * - DMA_SW: Enables the selected DMA channel for software triggering
  96. *
  97. * This function enables the DMA channel for hardware or software triggering
  98. */
  99. void dmaSetChEnable(uint32 channel,uint32 type)
  100. {
  101. if(type == DMA_HW)
  102. {
  103. dmaREG->HWCHENAS = (1U << channel);
  104. }
  105. else if(type == DMA_SW)
  106. {
  107. dmaREG->SWCHENAS = (1U << channel);
  108. }
  109. else
  110. {
  111. /** Empty */
  112. }
  113. }
  114. /** @fn void dmaSetPriority(uint32 channel, dmaPRIORITY_t priority)
  115. * @brief Assign Priority to the channel
  116. * @param[in] channel DMA channel
  117. * @param[in] priority Priority queue to which channel needs to be assigned
  118. * - LOWPRIORITY : The selected channel will be assigned to low priority queue
  119. * - HIGHPRIORITY: The selected channel will be assigned to high priority queue
  120. *
  121. * This function assigns the selected priority to the selected channel
  122. */
  123. void dmaSetPriority(uint32 channel, dmaPRIORITY_t priority)
  124. {
  125. if (priority == LOWPRIORITY)
  126. {
  127. dmaREG->CHPRIOR |= 1U << channel;
  128. }
  129. else
  130. {
  131. dmaREG->CHPRIOS |= 1U << channel;
  132. }
  133. }
  134. /** @fn void dmaEnableInterrupt(uint32 channel, dmaInterrupt_t inttype)
  135. * @brief Enable selected interrupt
  136. * @param[in] channel DMA channel
  137. * @param[in] inttype Interrupt to be enabled
  138. * - FTC: Frame Transfer Complete Interrupt will be disabled for the selected channel
  139. * - LFS: Last Frame Transfer Started Interrupt will be disabled for the selected channel
  140. * - HBC: First Half Of Block Complete Interrupt will be disabled for the selected channel
  141. * - BTC: Block transfer complete Interrupt will be disabled for the selected channel
  142. * - BER: Bus Error Interrupt will be disabled for the selected channel
  143. *
  144. * This function enables the selected interrupt for the selected channel
  145. */
  146. void dmaEnableInterrupt(uint32 channel, dmaInterrupt_t inttype)
  147. {
  148. dmaREG->GCHIENAS = 1 << channel;
  149. switch (inttype)
  150. {
  151. case FTC: dmaREG->FTCINTENAS |= 1U << channel;
  152. break;
  153. case LFS: dmaREG->LFSINTENAS |= 1U << channel;
  154. break;
  155. case HBC: dmaREG->HBCINTENAS |= 1U << channel;
  156. break;
  157. case BTC: dmaREG->BTCINTENAS |= 1U << channel;
  158. break;
  159. default :
  160. break;
  161. }
  162. }
  163. /** @fn void dmaDisableInterrupt(uint32 channel, dmaInterrupt_t inttype)
  164. * @brief Disable selected interrupt
  165. * @param[in] channel DMA channel
  166. * @param[in] inttype Interrupt to be disabled
  167. * - FTC: Frame Transfer Complete Interrupt will be disabled for the selected channel
  168. * - LFS: Last Frame Transfer Started Interrupt will be disabled for the selected channel
  169. * - HBC: First Half Of Block Complete Interrupt will be disabled for the selected channel
  170. * - BTC: Block transfer complete Interrupt will be disabled for the selected channel
  171. * - BER: Bus Error Interrupt will be disabled for the selected channel
  172. *
  173. * This function disables the selected interrupt for the selected channel
  174. */
  175. void dmaDisableInterrupt(uint32 channel, dmaInterrupt_t inttype)
  176. {
  177. switch (inttype)
  178. {
  179. case FTC: dmaREG->FTCINTENAR |= 1U << channel;
  180. break;
  181. case LFS: dmaREG->LFSINTENAR |= 1U << channel;
  182. break;
  183. case HBC: dmaREG->HBCINTENAR |= 1U << channel;
  184. break;
  185. case BTC: dmaREG->BTCINTENAR |= 1U << channel;
  186. break;
  187. default :
  188. break;
  189. }
  190. }
  191. /** @fn void dmaDefineRegion(dmaREGION_t region, uint32 start_add, uint32 end_add)
  192. * @brief Configure start and end address of the region
  193. * @param[in] region Memory Region
  194. * - DMA_REGION0
  195. * - DMA_REGION1
  196. * - DMA_REGION2
  197. * - DMA_REGION3
  198. * @param[in] start_add Start address of the the region
  199. * @param[in] end_add End address of the region
  200. *
  201. * This function configure start and end address of the selected region
  202. */
  203. void dmaDefineRegion(dmaREGION_t region, uint32 start_add, uint32 end_add)
  204. {
  205. dmaREG->DMAMPR[region].STARTADD = start_add;
  206. dmaREG->DMAMPR[region].ENDADD = end_add;
  207. }
  208. /** @fn void dmaEnableRegion(dmaREGION_t region, dmaRegionAccess_t access, boolean intenable)
  209. * @brief Enable the selected region
  210. * @param[in] region Memory Region
  211. * - DMA_REGION0
  212. * - DMA_REGION1
  213. * - DMA_REGION2
  214. * - DMA_REGION3
  215. * @param[in] access Access permission of the selected region
  216. * - FULLACCESS
  217. * - READONLY
  218. * - WRITEONLY
  219. * - NOACCESS
  220. * @param[in] intenable Interrupt to be enabled or not
  221. * - INTERRUPT_ENABLE : Enable interrupt for the selected region
  222. * - INTERRUPT_DISABLE: Disable interrupt for the selected region
  223. *
  224. * This function enables the selected region with selected access permission with or without interrupt enable
  225. */
  226. void dmaEnableRegion(dmaREGION_t region, dmaRegionAccess_t access, boolean intenable)
  227. {
  228. /* Enable the region */
  229. dmaREG->DMAMPCTRL |= 1U << (region*8U);
  230. /* Set access permission for the region */
  231. dmaREG->DMAMPCTRL |= access << ((region*8U) + 1U);
  232. /* Enable or Disable interrupt */
  233. dmaREG->DMAMPCTRL |= intenable << ((region*8U) + 3U);
  234. }
  235. /** @fn void dmaDisableRegion(dmaREGION_t region)
  236. * @brief Disable the selected region
  237. * @param[in] region Memory Region
  238. * - DMA_REGION0
  239. * - DMA_REGION1
  240. * - DMA_REGION2
  241. * - DMA_REGION3
  242. *
  243. * This function disables the selected region(no address checking done).
  244. */
  245. void dmaDisableRegion(dmaREGION_t region)
  246. {
  247. dmaREG->DMAMPCTRL &= ~(1U << (region*8U));
  248. }
  249. /** @fn void dmaEnableParityCheck(void)
  250. * @brief Enable Parity Check
  251. *
  252. * This function enables parit check
  253. */
  254. void dmaEnableParityCheck(void)
  255. {
  256. dmaREG->DMAPCR = 0x5U;
  257. }
  258. /** @fn void dmaDisableParityCheck(void)
  259. * @brief Disable Parity Check
  260. *
  261. * This function disables parity check
  262. */
  263. void dmaDisableParityCheck(void)
  264. {
  265. dmaREG->DMAPCR = 0xAU;
  266. }