GPDMA_LPC18xx.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V1.2
  20. *
  21. * Project: GPDMA Driver Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __GPDMA_LPC18XX_H
  24. #define __GPDMA_LPC18XX_H
  25. #include <stdint.h>
  26. // Number of GPDMA channels
  27. #define GPDMA_NUMBER_OF_CHANNELS ((uint8_t) 8)
  28. // GPDMA Events
  29. #define GPDMA_EVENT_TERMINAL_COUNT_REQUEST (1)
  30. #define GPDMA_EVENT_ERROR (2)
  31. // GPDMA Burst size in Source and Destination definitions
  32. #define GPDMA_BSIZE_1 (0) // Burst size = 1
  33. #define GPDMA_BSIZE_4 (1) // Burst size = 4
  34. #define GPDMA_BSIZE_8 (2) // Burst size = 8
  35. #define GPDMA_BSIZE_16 (3) // Burst size = 16
  36. #define GPDMA_BSIZE_32 (4) // Burst size = 32
  37. #define GPDMA_BSIZE_64 (5) // Burst size = 64
  38. #define GPDMA_BSIZE_128 (6) // Burst size = 128
  39. #define GPDMA_BSIZE_256 (7) // Burst size = 256
  40. // Width in Source transfer width and Destination transfer width definitions
  41. #define GPDMA_WIDTH_BYTE (0) // Width = 1 byte
  42. #define GPDMA_WIDTH_HALFWORD (1) // Width = 2 bytes
  43. #define GPDMA_WIDTH_WORD (2) // Width = 4 bytes
  44. // GPDMA Transfer type and flow control
  45. #define GPDMA_TRANSFER_M2M_CTRL_DMA (0) // Memory to memory - DMA control
  46. #define GPDMA_TRANSFER_M2P_CTRL_DMA (1) // Memory to peripheral - DMA control
  47. #define GPDMA_TRANSFER_P2M_CTRL_DMA (2) // Peripheral to memory - DMA control
  48. #define GPDMA_TRANSFER_P2P_CTRL_DMA (3) // Source peripheral to destination peripheral - DMA control
  49. #define GPDMA_TRANSFER_P2P_CTRL_DEST_PERI (4) // Source peripheral to destination peripheral - destination peripheral control
  50. #define GPDMA_TRANSFER_M2P_CTRL_PERI (5) // Memory to peripheral - peripheral control
  51. #define GPDMA_TRANSFER_P2M_CTRL_PERI (6) // Peripheral to memory - peripheral control
  52. #define GPDMA_TRANSFER_P2P_CTRL_SRC_PERI (7) // Source peripheral to destination peripheral - source peripheral control
  53. // GPDMA Configuration register definitions
  54. #define GPDMA_CONFIG_E (1 << 0)
  55. #define GPDMA_CONFIG_M0 (1 << 1)
  56. #define GPDMA_CONFIG_M1 (1 << 2)
  57. // GPDMA Channel Configuration registers definitions
  58. #define GPDMA_CH_CONFIG_E (1 << 0)
  59. #define GPDMA_CH_CONFIG_SRC_PERI_POS ( 1)
  60. #define GPDMA_CH_CONFIG_SRC_PERI_MSK (0x1F << GPDMA_CH_CONFIG_SRC_PERI_POS)
  61. #define GPDMA_CH_CONFIG_SRC_PERI(n) (((n) << GPDMA_CH_CONFIG_SRC_PERI_POS) & GPDMA_CH_CONFIG_SRC_PERI_MSK)
  62. #define GPDMA_CH_CONFIG_DEST_PERI_POS ( 6)
  63. #define GPDMA_CH_CONFIG_DEST_PERI_MSK (0x1F << GPDMA_CH_CONFIG_DEST_PERI_POS)
  64. #define GPDMA_CH_CONFIG_DEST_PERI(n) (((n) << GPDMA_CH_CONFIG_DEST_PERI_POS) & GPDMA_CH_CONFIG_DEST_PERI_MSK)
  65. #define GPDMA_CH_CONFIG_FLOWCNTRL_POS ( 11)
  66. #define GPDMA_CH_CONFIG_FLOWCNTRL_MSK (0x03 << GPDMA_CH_CONFIG_FLOWCNTRL_POS)
  67. #define GPDMA_CH_CONFIG_FLOWCNTRL(n) (((n) << GPDMA_CH_CONFIG_FLOWCNTRL_POS) & GPDMA_CH_CONFIG_FLOWCNTRL_MSK)
  68. #define GPDMA_CH_CONFIG_IE (1 << 14)
  69. #define GPDMA_CH_CONFIG_ITC (1 << 15)
  70. #define GPDMA_CH_CONFIG_L (1 << 16)
  71. #define GPDMA_CH_CONFIG_A (1 << 17)
  72. #define GPDMA_CH_CONFIG_H (1 << 18)
  73. // GPDMA Channel Control register definition
  74. #define GPDMA_CH_CONTROL_TRANSFERSIZE_POS ( 0)
  75. #define GPDMA_CH_CONTROL_TRANSFERSIZE_MSK (0xFFF << GPDMA_CH_CONTROL_TRANSFERSIZE_POS)
  76. #define GPDMA_CH_CONTROL_TRANSFERSIZE(n) (((n) << GPDMA_CH_CONTROL_TRANSFERSIZE_POS) & GPDMA_CH_CONTROL_TRANSFERSIZE_MSK)
  77. #define GPDMA_CH_CONTROL_SBSIZE_POS ( 12)
  78. #define GPDMA_CH_CONTROL_SBSIZE_MSK (0x03 << GPDMA_CH_CONTROL_SBSIZE_POS)
  79. #define GPDMA_CH_CONTROL_SBSIZE(n) (((n) << GPDMA_CH_CONTROL_SBSIZE_POS) & GPDMA_CH_CONTROL_SBSIZE_MSK)
  80. #define GPDMA_CH_CONTROL_DBSIZE_POS ( 15)
  81. #define GPDMA_CH_CONTROL_DBSIZE_MSK (0x03 << GPDMA_CH_CONTROL_DBSIZE_POS)
  82. #define GPDMA_CH_CONTROL_DBSIZE(n) (((n) << GPDMA_CH_CONTROL_DBSIZE_POS) & GPDMA_CH_CONTROL_DBSIZE_MSK)
  83. #define GPDMA_CH_CONTROL_SWIDTH_POS ( 18)
  84. #define GPDMA_CH_CONTROL_SWIDTH_MSK (0x03 << GPDMA_CH_CONTROL_SWIDTH_POS)
  85. #define GPDMA_CH_CONTROL_SWIDTH(n) (((n) << GPDMA_CH_CONTROL_SWIDTH_POS) & GPDMA_CH_CONTROL_SWIDTH_MSK)
  86. #define GPDMA_CH_CONTROL_DWIDTH_POS ( 21)
  87. #define GPDMA_CH_CONTROL_DWIDTH_MSK (0x03 << GPDMA_CH_CONTROL_DWIDTH_POS)
  88. #define GPDMA_CH_CONTROL_DWIDTH(n) (((n) << GPDMA_CH_CONTROL_DWIDTH_POS) & GPDMA_CH_CONTROL_DWIDTH_MSK)
  89. #define GPDMA_CH_CONTROL_S (1 << 24)
  90. #define GPDMA_CH_CONTROL_D (1 << 25)
  91. #define GPDMA_CH_CONTROL_SI (1 << 26)
  92. #define GPDMA_CH_CONTROL_DI (1 << 27)
  93. #define GPDMA_CH_CONTROL_PROT1 (1 << 28)
  94. #define GPDMA_CH_CONTROL_PROT2 (1 << 29)
  95. #define GPDMA_CH_CONTROL_PROT3 (1 << 30)
  96. #define GPDMA_CH_CONTROL_I (1UL << 31)
  97. /**
  98. \fn void GPDMA_SignalEvent_t (uint32_t event)
  99. \brief Signal GPDMA Events.
  100. \param[in] event GPDMA Event mask
  101. \return none
  102. */
  103. typedef void (*GPDMA_SignalEvent_t) (uint32_t event);
  104. /**
  105. \fn int32_t GPDMA_Initialize (void)
  106. \brief Initialize GPDMA peripheral
  107. \returns
  108. - \b 0: function succeeded
  109. - \b -1: function failed
  110. */
  111. extern int32_t GPDMA_Initialize (void);
  112. /**
  113. \fn int32_t GPDMA_Uninitialize (void)
  114. \brief De-initialize GPDMA peripheral
  115. \returns
  116. - \b 0: function succeeded
  117. - \b -1: function failed
  118. */
  119. extern int32_t GPDMA_Uninitialize (void);
  120. /**
  121. \fn int32_t GPDMA_PeripheralSelect (uint8_t peri, uint8_t sel)
  122. \brief Selects GPDMA requests
  123. \param[in] peri GPDMA peripheral (0..15)
  124. \param[in] sel Selects the DMA request for GPDMA input (0..3)
  125. \returns
  126. - \b 0: function succeeded
  127. - \b -1: function failed
  128. */
  129. extern int32_t GPDMA_PeripheralSelect (uint8_t peri, uint8_t sel);
  130. /**
  131. \fn int32_t GPDMA_ChannelConfigure (uint8_t ch,
  132. uint32_t src_addr,
  133. uint32_t dest_addr,
  134. uint32_t size,
  135. uint32_t control,
  136. uint32_t config,
  137. GPDMA_SignalEvent_t cb_event)
  138. \brief Configure GPDMA channel for next transfer
  139. \param[in] ch Channel number (0..7)
  140. \param[in] src_addr Source address
  141. \param[in] dest_addr Destination address
  142. \param[in] size Amount of data to transfer
  143. \param[in] control Channel control
  144. \param[in] config Channel configuration
  145. \param[in] cb_event Channel callback pointer
  146. \returns
  147. - \b 0: function succeeded
  148. - \b -1: function failed
  149. */
  150. extern int32_t GPDMA_ChannelConfigure (uint8_t ch,
  151. uint32_t src_addr,
  152. uint32_t dest_addr,
  153. uint32_t size,
  154. uint32_t control,
  155. uint32_t config,
  156. GPDMA_SignalEvent_t cb_event);
  157. /**
  158. \fn int32_t GPDMA_ChannelEnable (uint8_t ch)
  159. \brief Enable GPDMA channel
  160. \param[in] ch Channel number (0..7)
  161. \returns
  162. - \b 0: function succeeded
  163. - \b -1: function failed
  164. */
  165. extern int32_t GPDMA_ChannelEnable (uint8_t ch);
  166. /**
  167. \fn int32_t GPDMA_ChannelDisable (uint8_t ch)
  168. \brief Disable GPDMA channel
  169. \param[in] ch Channel number (0..7)
  170. \returns
  171. - \b 0: function succeeded
  172. - \b -1: function failed
  173. */
  174. extern int32_t GPDMA_ChannelDisable (uint8_t ch);
  175. /**
  176. \fn uint32_t GPDMA_ChannelGetStatus (uint8_t ch)
  177. \brief Check if GPDMA channel is enabled or disabled
  178. \param[in] ch Channel number (0..7)
  179. \returns Channel status
  180. - \b 1: channel enabled
  181. - \b 0: channel disabled
  182. */
  183. extern uint32_t GPDMA_ChannelGetStatus (uint8_t ch);
  184. /**
  185. \fn uint32_t GPDMA_ChannelGetCount (uint8_t ch)
  186. \brief Get number of transferred data
  187. \param[in] ch Channel number (0..7)
  188. \returns Number of transferred data
  189. */
  190. extern uint32_t GPDMA_ChannelGetCount (uint8_t ch);
  191. #endif /* __GPDMA_LPC18XX_H */