gpdma_001.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * @brief GPDMA Registers and control functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  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 "gpdma_001.h"
  32. /*****************************************************************************
  33. * Private types/enumerations/variables
  34. ****************************************************************************/
  35. /*****************************************************************************
  36. * Public types/enumerations/variables
  37. ****************************************************************************/
  38. /*****************************************************************************
  39. * Private functions
  40. ****************************************************************************/
  41. /*****************************************************************************
  42. * Public functions
  43. ****************************************************************************/
  44. /* Initialize the GPDMA */
  45. void IP_GPDMA_Init(IP_GPDMA_001_Type *pGPDMA) {
  46. uint8_t i;
  47. /* Reset all channel configuration register */
  48. for (i = 8; i > 0; i--) {
  49. pGPDMA->CH[i - 1].CONFIG = 0;
  50. }
  51. /* Clear all DMA interrupt and error flag */
  52. pGPDMA->INTTCCLEAR = 0xFF;
  53. pGPDMA->INTERRCLR = 0xFF;
  54. }
  55. /* Read the status from different registers according to the type */
  56. IntStatus IP_GPDMA_IntGetStatus(IP_GPDMA_001_Type *pGPDMA, GPDMA_Status_Type type, uint8_t channel) {
  57. /**
  58. * TODO check the channel <=8 type is esxited
  59. */
  60. switch (type) {
  61. case GPDMA_STAT_INT:/* check status of DMA channel interrupts */
  62. return (IntStatus) (pGPDMA->INTSTAT & (((1UL << channel) & 0xFF)));
  63. case GPDMA_STAT_INTTC: /* check terminal count interrupt request status for DMA */
  64. return (IntStatus) (pGPDMA->INTTCSTAT & (((1UL << channel) & 0xFF)));
  65. case GPDMA_STAT_INTERR: /* check interrupt status for DMA channels */
  66. return (IntStatus) (pGPDMA->INTERRSTAT & (((1UL << channel) & 0xFF)));
  67. case GPDMA_STAT_RAWINTTC: /* check status of the terminal count interrupt for DMA channels */
  68. return (IntStatus) (pGPDMA->RAWINTTCSTAT & (((1UL << channel) & 0xFF)));
  69. case GPDMA_STAT_RAWINTERR: /* check status of the error interrupt for DMA channels */
  70. return (IntStatus) (pGPDMA->RAWINTERRSTAT & (((1UL << channel) & 0xFF)));
  71. default:/* check enable status for DMA channels */
  72. return (IntStatus) (pGPDMA->ENBLDCHNS & (((1UL << channel) & 0xFF)));
  73. }
  74. }
  75. /* Clear the Interrupt Flag from different registers according to the type */
  76. void IP_GPDMA_ClearIntPending(IP_GPDMA_001_Type *pGPDMA, GPDMA_StateClear_Type type, uint8_t channel) {
  77. if (type == GPDMA_STATCLR_INTTC) {
  78. /* clears the terminal count interrupt request on DMA channel */
  79. pGPDMA->INTTCCLEAR = (((1UL << (channel)) & 0xFF));
  80. }
  81. else {
  82. /* clear the error interrupt request */
  83. pGPDMA->INTERRCLR = (((1UL << (channel)) & 0xFF));
  84. }
  85. }
  86. /* Enable or Disable the GPDMA Channel */
  87. void IP_GPDMA_ChannelCmd(IP_GPDMA_001_Type *pGPDMA, uint8_t channelNum, FunctionalState NewState) {
  88. IP_GPDMA_001_CH_Type *pDMAch;
  89. /* Get Channel pointer */
  90. pDMAch = (IP_GPDMA_001_CH_Type *) &(pGPDMA->CH[channelNum]);
  91. if (NewState == ENABLE) {
  92. pDMAch->CONFIG |= GPDMA_DMACCxConfig_E;
  93. }
  94. else {
  95. pDMAch->CONFIG &= ~GPDMA_DMACCxConfig_E;
  96. }
  97. }
  98. /* Set up the DPDMA according to the specification configuration details */
  99. Status IP_GPDMA_Setup(IP_GPDMA_001_Type *pGPDMA,
  100. GPDMA_Channel_CFG_Type *GPDMAChannelConfig,
  101. uint32_t GPDMA_LUTPerBurstSrcConn,
  102. uint32_t GPDMA_LUTPerBurstDstConn,
  103. uint32_t GPDMA_LUTPerWidSrcConn,
  104. uint32_t GPDMA_LUTPerWidDstConn,
  105. uint32_t GPDMA_LUTPerAddrSrcConn,
  106. uint32_t GPDMA_LUTPerAddrDstConn,
  107. uint8_t SrcPeripheral,
  108. uint8_t DstPeripheral)
  109. {
  110. IP_GPDMA_001_CH_Type *pDMAch;
  111. if (pGPDMA->ENBLDCHNS & ((((1UL << (GPDMAChannelConfig->ChannelNum)) & 0xFF)))) {
  112. /* This channel is enabled, return ERROR, need to release this channel first */
  113. return ERROR;
  114. }
  115. /* Get Channel pointer */
  116. pDMAch = (IP_GPDMA_001_CH_Type *) &(pGPDMA->CH[GPDMAChannelConfig->ChannelNum]);
  117. /* Reset the Interrupt status */
  118. pGPDMA->INTTCCLEAR = (((1UL << (GPDMAChannelConfig->ChannelNum)) & 0xFF));
  119. pGPDMA->INTERRCLR = (((1UL << (GPDMAChannelConfig->ChannelNum)) & 0xFF));
  120. /* Assign Linker List Item value */
  121. pDMAch->LLI = 0;/* Fixed to 0 (no link list) */
  122. /* Enable DMA channels, little endian */
  123. pGPDMA->CONFIG = GPDMA_DMACConfig_E;
  124. while (!(pGPDMA->CONFIG & GPDMA_DMACConfig_E)) {}
  125. pDMAch->SRCADDR = GPDMAChannelConfig->SrcAddr;
  126. pDMAch->DESTADDR = GPDMAChannelConfig->DstAddr;
  127. /* Configure DMA Channel, enable Error Counter and Terminate counter */
  128. pDMAch->CONFIG = GPDMA_DMACCxConfig_IE
  129. | GPDMA_DMACCxConfig_ITC /*| GPDMA_DMACCxConfig_E*/
  130. | GPDMA_DMACCxConfig_TransferType((uint32_t) GPDMAChannelConfig->TransferType)
  131. | GPDMA_DMACCxConfig_SrcPeripheral(SrcPeripheral)
  132. | GPDMA_DMACCxConfig_DestPeripheral(DstPeripheral);
  133. switch (GPDMAChannelConfig->TransferType) {
  134. /* Memory to memory */
  135. case GPDMA_TRANSFERTYPE_M2M_CONTROLLER_DMA:
  136. pDMAch->CONTROL = GPDMA_DMACCxControl_TransferSize(GPDMAChannelConfig->TransferSize)
  137. | GPDMA_DMACCxControl_SBSize((4UL)) /**< Burst size = 32 */
  138. | GPDMA_DMACCxControl_DBSize((4UL)) /**< Burst size = 32 */
  139. | GPDMA_DMACCxControl_SWidth(GPDMAChannelConfig->TransferWidth)
  140. | GPDMA_DMACCxControl_DWidth(GPDMAChannelConfig->TransferWidth)
  141. | GPDMA_DMACCxControl_SI
  142. | GPDMA_DMACCxControl_DI
  143. | GPDMA_DMACCxControl_I;
  144. break;
  145. case GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA:
  146. case GPDMA_TRANSFERTYPE_M2P_CONTROLLER_PERIPHERAL:
  147. pDMAch->CONTROL = GPDMA_DMACCxControl_TransferSize((uint32_t) GPDMAChannelConfig->TransferSize)
  148. | GPDMA_DMACCxControl_SBSize(GPDMA_LUTPerBurstDstConn)
  149. | GPDMA_DMACCxControl_DBSize(GPDMA_LUTPerBurstDstConn)
  150. | GPDMA_DMACCxControl_SWidth(GPDMA_LUTPerWidDstConn)
  151. | GPDMA_DMACCxControl_DWidth(GPDMA_LUTPerWidDstConn)
  152. | GPDMA_DMACCxControl_DestTransUseAHBMaster1
  153. | GPDMA_DMACCxControl_SI
  154. | GPDMA_DMACCxControl_I;
  155. break;
  156. case GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA:
  157. case GPDMA_TRANSFERTYPE_P2M_CONTROLLER_PERIPHERAL:
  158. pDMAch->CONTROL = GPDMA_DMACCxControl_TransferSize((uint32_t) GPDMAChannelConfig->TransferSize)
  159. | GPDMA_DMACCxControl_SBSize(GPDMA_LUTPerBurstSrcConn)
  160. | GPDMA_DMACCxControl_DBSize(GPDMA_LUTPerBurstSrcConn)
  161. | GPDMA_DMACCxControl_SWidth(GPDMA_LUTPerWidSrcConn)
  162. | GPDMA_DMACCxControl_DWidth(GPDMA_LUTPerWidSrcConn)
  163. | GPDMA_DMACCxControl_SrcTransUseAHBMaster1
  164. | GPDMA_DMACCxControl_DI
  165. | GPDMA_DMACCxControl_I;
  166. break;
  167. case GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DMA:
  168. case GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DestPERIPHERAL:
  169. case GPDMA_TRANSFERTYPE_P2P_CONTROLLER_SrcPERIPHERAL:
  170. pDMAch->CONTROL = GPDMA_DMACCxControl_TransferSize((uint32_t) GPDMAChannelConfig->TransferSize)
  171. | GPDMA_DMACCxControl_SBSize(GPDMA_LUTPerBurstSrcConn)
  172. | GPDMA_DMACCxControl_DBSize(GPDMA_LUTPerBurstDstConn)
  173. | GPDMA_DMACCxControl_SWidth(GPDMA_LUTPerWidSrcConn)
  174. | GPDMA_DMACCxControl_DWidth(GPDMA_LUTPerWidDstConn)
  175. | GPDMA_DMACCxControl_SrcTransUseAHBMaster1
  176. | GPDMA_DMACCxControl_DestTransUseAHBMaster1
  177. | GPDMA_DMACCxControl_I;
  178. break;
  179. /* Do not support any more transfer type, return ERROR */
  180. default:
  181. return ERROR;
  182. }
  183. return SUCCESS;
  184. }