hal_dma.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**************************************************************************************************
  2. Filename: hal_dma.h
  3. Revised: $Date: 2009-03-29 10:51:47 -0700 (Sun, 29 Mar 2009) $
  4. Revision: $Revision: 19585 $
  5. Description: This file contains the interface to the DMA Service.
  6. Copyright 2007-2011 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef HAL_DMA_H
  34. #define HAL_DMA_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "hal_board.h"
  43. #include "hal_types.h"
  44. #if ((defined HAL_DMA) && (HAL_DMA == TRUE))
  45. /*********************************************************************
  46. * MACROS
  47. */
  48. #define HAL_DMA_SET_ADDR_DESC0( a ) \
  49. st( \
  50. DMA0CFGH = (uint8)( (uint16)(a) >> 8 ); \
  51. DMA0CFGL = (uint8)( (uint16)(a) & 0xFF ); \
  52. )
  53. #define HAL_DMA_SET_ADDR_DESC1234( a ) \
  54. st( \
  55. DMA1CFGH = (uint8)( (uint16)(a) >> 8 ); \
  56. DMA1CFGL = (uint8)( (uint16)(a) & 0xFF ); \
  57. )
  58. #define HAL_DMA_GET_DESC0() &dmaCh0
  59. #define HAL_DMA_GET_DESC1234( a ) (dmaCh1234+((a)-1))
  60. #define HAL_DMA_ARM_CH( ch ) DMAARM = (0x01 << (ch))
  61. #define HAL_DMA_CH_ARMED( ch ) (DMAARM & (0x01 << (ch)))
  62. #define HAL_DMA_ABORT_CH( ch ) DMAARM = (0x80 | (0x01 << (ch)))
  63. #define HAL_DMA_MAN_TRIGGER( ch ) DMAREQ = (0x01 << (ch))
  64. #define HAL_DMA_START_CH( ch ) HAL_DMA_MAN_TRIGGER( (ch) )
  65. #define HAL_DMA_CLEAR_IRQ( ch ) DMAIRQ = ~( 1 << (ch) )
  66. #define HAL_DMA_CHECK_IRQ( ch ) (DMAIRQ & ( 1 << (ch) ))
  67. // Macro for quickly setting the source address of a DMA structure.
  68. #define HAL_DMA_SET_SOURCE( pDesc, src ) \
  69. st( \
  70. pDesc->srcAddrH = (uint8)((uint16)(src) >> 8); \
  71. pDesc->srcAddrL = (uint8)( (uint16)(src) & 0xFF ); \
  72. )
  73. // Macro for quickly setting the destination address of a DMA structure.
  74. #define HAL_DMA_SET_DEST( pDesc, dst ) \
  75. st( \
  76. pDesc->dstAddrH = (uint8)((uint16)(dst) >> 8); \
  77. pDesc->dstAddrL = (uint8)( (uint16)(dst) & 0xFF ); \
  78. )
  79. // Macro for quickly setting the number of bytes to be transferred by the DMA,
  80. // max length is 0x1FFF.
  81. #define HAL_DMA_SET_LEN( pDesc, len ) \
  82. st( \
  83. pDesc->xferLenL = (uint8)( (uint16)(len) & 0xFF); \
  84. pDesc->xferLenV &= ~HAL_DMA_LEN_H; \
  85. pDesc->xferLenV |= (uint8)((uint16)(len) >> 8); \
  86. )
  87. #define HAL_DMA_GET_LEN( pDesc ) \
  88. (((uint16)(pDesc->xferLenV & HAL_DMA_LEN_H) << 8) | pDesc->xferLenL)
  89. #define HAL_DMA_SET_VLEN( pDesc, vMode ) \
  90. st( \
  91. pDesc->xferLenV &= ~HAL_DMA_LEN_V; \
  92. pDesc->xferLenV |= (vMode << 5); \
  93. )
  94. #define HAL_DMA_SET_WORD_SIZE( pDesc, xSz ) \
  95. st( \
  96. pDesc->ctrlA &= ~HAL_DMA_WORD_SIZE; \
  97. pDesc->ctrlA |= (xSz << 7); \
  98. )
  99. #define HAL_DMA_SET_TRIG_MODE( pDesc, tMode ) \
  100. st( \
  101. pDesc->ctrlA &= ~HAL_DMA_TRIG_MODE; \
  102. pDesc->ctrlA |= (tMode << 5); \
  103. )
  104. #define HAL_DMA_GET_TRIG_MODE( pDesc ) ((pDesc->ctrlA >> 5) & 0x3)
  105. #define HAL_DMA_SET_TRIG_SRC( pDesc, tSrc ) \
  106. st( \
  107. pDesc->ctrlA &= ~HAL_DMA_TRIG_SRC; \
  108. pDesc->ctrlA |= tSrc; \
  109. )
  110. #define HAL_DMA_SET_SRC_INC( pDesc, srcInc ) \
  111. st( \
  112. pDesc->ctrlB &= ~HAL_DMA_SRC_INC; \
  113. pDesc->ctrlB |= (srcInc << 6); \
  114. )
  115. #define HAL_DMA_SET_DST_INC( pDesc, dstInc ) \
  116. st( \
  117. pDesc->ctrlB &= ~HAL_DMA_DST_INC; \
  118. pDesc->ctrlB |= (dstInc << 4); \
  119. )
  120. #define HAL_DMA_SET_IRQ( pDesc, enable ) \
  121. st( \
  122. pDesc->ctrlB &= ~HAL_DMA_IRQ_MASK; \
  123. pDesc->ctrlB |= (enable << 3); \
  124. )
  125. #define HAL_DMA_SET_M8( pDesc, m8 ) \
  126. st( \
  127. pDesc->ctrlB &= ~HAL_DMA_M8; \
  128. pDesc->ctrlB |= (m8 << 2); \
  129. )
  130. #define HAL_DMA_SET_PRIORITY( pDesc, pri ) \
  131. st( \
  132. pDesc->ctrlB &= ~HAL_DMA_PRIORITY; \
  133. pDesc->ctrlB |= pri; \
  134. )
  135. /*********************************************************************
  136. * CONSTANTS
  137. */
  138. // Use LEN for transfer count
  139. #define HAL_DMA_VLEN_USE_LEN 0x00
  140. // Transfer the first byte + the number of bytes indicated by the first byte
  141. #define HAL_DMA_VLEN_1_P_VALOFFIRST 0x01
  142. // Transfer the number of bytes indicated by the first byte (starting with the first byte)
  143. #define HAL_DMA_VLEN_VALOFFIRST 0x02
  144. // Transfer the first byte + the number of bytes indicated by the first byte + 1 more byte
  145. #define HAL_DMA_VLEN_1_P_VALOFFIRST_P_1 0x03
  146. // Transfer the first byte + the number of bytes indicated by the first byte + 2 more bytes
  147. #define HAL_DMA_VLEN_1_P_VALOFFIRST_P_2 0x04
  148. #define HAL_DMA_WORDSIZE_BYTE 0x00 /* Transfer a byte at a time. */
  149. #define HAL_DMA_WORDSIZE_WORD 0x01 /* Transfer a 16-bit word at a time. */
  150. #define HAL_DMA_TMODE_SINGLE 0x00 /* Transfer a single byte/word after each DMA trigger. */
  151. #define HAL_DMA_TMODE_BLOCK 0x01 /* Transfer block of data (length len) after each DMA trigger. */
  152. #define HAL_DMA_TMODE_SINGLE_REPEATED 0x02 /* Transfer single byte/word (after len transfers, rearm DMA). */
  153. #define HAL_DMA_TMODE_BLOCK_REPEATED 0x03 /* Transfer block of data (after len transfers, rearm DMA). */
  154. #define HAL_DMA_TRIG_NONE 0 /* No trigger, setting DMAREQ.DMAREQx bit starts transfer. */
  155. #define HAL_DMA_TRIG_PREV 1 /* DMA channel is triggered by completion of previous channel. */
  156. #define HAL_DMA_TRIG_T1_CH0 2 /* Timer 1, compare, channel 0. */
  157. #define HAL_DMA_TRIG_T1_CH1 3 /* Timer 1, compare, channel 1. */
  158. #define HAL_DMA_TRIG_T1_CH2 4 /* Timer 1, compare, channel 2. */
  159. #define HAL_DMA_TRIG_T2_COMP 5 /* Timer 2, compare. */
  160. #define HAL_DMA_TRIG_T2_OVFL 6 /* Timer 2, overflow. */
  161. #define HAL_DMA_TRIG_T3_CH0 7 /* Timer 3, compare, channel 0. */
  162. #define HAL_DMA_TRIG_T3_CH1 8 /* Timer 3, compare, channel 1. */
  163. #define HAL_DMA_TRIG_T4_CH0 9 /* Timer 4, compare, channel 0. */
  164. #define HAL_DMA_TRIG_T4_CH1 10 /* Timer 4, compare, channel 1. */
  165. #define HAL_DMA_TRIG_ST 11 /* Sleep Timer compare. */
  166. #define HAL_DMA_TRIG_IOC_0 12 /* Port 0 I/O pin input transition. */
  167. #define HAL_DMA_TRIG_IOC_1 13 /* Port 1 I/O pin input transition. */
  168. #define HAL_DMA_TRIG_URX0 14 /* USART0 RX complete. */
  169. #define HAL_DMA_TRIG_UTX0 15 /* USART0 TX complete. */
  170. #define HAL_DMA_TRIG_URX1 16 /* USART1 RX complete. */
  171. #define HAL_DMA_TRIG_UTX1 17 /* USART1 TX complete. */
  172. #define HAL_DMA_TRIG_FLASH 18 /* Flash data write complete. */
  173. #define HAL_DMA_TRIG_RADIO 19 /* RF packet byte received/transmit. */
  174. #define HAL_DMA_TRIG_ADC_CHALL 20 /* ADC end of a conversion in a sequence, sample ready. */
  175. #define HAL_DMA_TRIG_ADC_CH0 21 /* ADC end of conversion channel 0 in sequence, sample ready. */
  176. #define HAL_DMA_TRIG_ADC_CH1 22 /* ADC end of conversion channel 1 in sequence, sample ready. */
  177. #define HAL_DMA_TRIG_ADC_CH2 23 /* ADC end of conversion channel 2 in sequence, sample ready. */
  178. #define HAL_DMA_TRIG_ADC_CH3 24 /* ADC end of conversion channel 3 in sequence, sample ready. */
  179. #define HAL_DMA_TRIG_ADC_CH4 25 /* ADC end of conversion channel 4 in sequence, sample ready. */
  180. #define HAL_DMA_TRIG_ADC_CH5 26 /* ADC end of conversion channel 5 in sequence, sample ready. */
  181. #define HAL_DMA_TRIG_ADC_CH6 27 /* ADC end of conversion channel 6 in sequence, sample ready. */
  182. #define HAL_DMA_TRIG_ADC_CH7 28 /* ADC end of conversion channel 7 in sequence, sample ready. */
  183. #define HAL_DMA_TRIG_ENC_DW 29 /* AES encryption processor requests download input data. */
  184. #define HAL_DMA_TRIG_ENC_UP 30 /* AES encryption processor requests upload output data. */
  185. #define HAL_DMA_SRCINC_0 0x00 /* Increment source pointer by 0 bytes/words after each transfer. */
  186. #define HAL_DMA_SRCINC_1 0x01 /* Increment source pointer by 1 bytes/words after each transfer. */
  187. #define HAL_DMA_SRCINC_2 0x02 /* Increment source pointer by 2 bytes/words after each transfer. */
  188. #define HAL_DMA_SRCINC_M1 0x03 /* Decrement source pointer by 1 bytes/words after each transfer. */
  189. #define HAL_DMA_DSTINC_0 0x00 /* Increment destination pointer by 0 bytes/words after each transfer. */
  190. #define HAL_DMA_DSTINC_1 0x01 /* Increment destination pointer by 1 bytes/words after each transfer. */
  191. #define HAL_DMA_DSTINC_2 0x02 /* Increment destination pointer by 2 bytes/words after each transfer. */
  192. #define HAL_DMA_DSTINC_M1 0x03 /* Decrement destination pointer by 1 bytes/words after each transfer. */
  193. #define HAL_DMA_IRQMASK_DISABLE 0x00 /* Disable interrupt generation. */
  194. #define HAL_DMA_IRQMASK_ENABLE 0x01 /* Enable interrupt generation upon DMA channel done. */
  195. #define HAL_DMA_M8_USE_8_BITS 0x00 /* Use all 8 bits for transfer count. */
  196. #define HAL_DMA_M8_USE_7_BITS 0x01 /* Use 7 LSB for transfer count. */
  197. #define HAL_DMA_PRI_LOW 0x00 /* Low, CPU has priority. */
  198. #define HAL_DMA_PRI_GUARANTEED 0x01 /* Guaranteed, DMA at least every second try. */
  199. #define HAL_DMA_PRI_HIGH 0x02 /* High, DMA has priority. */
  200. #define HAL_DMA_PRI_ABSOLUTE 0x03 /* Highest, DMA has priority. Reserved for DMA port access.. */
  201. #define HAL_DMA_MAX_ARM_CLOCKS 45 // Maximum number of clocks required if arming all 5 at once.
  202. /*********************************************************************
  203. * TYPEDEFS
  204. */
  205. // Bit fields of the 'lenModeH'
  206. #define HAL_DMA_LEN_V 0xE0
  207. #define HAL_DMA_LEN_H 0x1F
  208. // Bit fields of the 'ctrlA'
  209. #define HAL_DMA_WORD_SIZE 0x80
  210. #define HAL_DMA_TRIG_MODE 0x60
  211. #define HAL_DMA_TRIG_SRC 0x1F
  212. // Bit fields of the 'ctrlB'
  213. #define HAL_DMA_SRC_INC 0xC0
  214. #define HAL_DMA_DST_INC 0x30
  215. #define HAL_DMA_IRQ_MASK 0x08
  216. #define HAL_DMA_M8 0x04
  217. #define HAL_DMA_PRIORITY 0x03
  218. typedef struct {
  219. uint8 srcAddrH;
  220. uint8 srcAddrL;
  221. uint8 dstAddrH;
  222. uint8 dstAddrL;
  223. uint8 xferLenV;
  224. uint8 xferLenL;
  225. uint8 ctrlA;
  226. uint8 ctrlB;
  227. } halDMADesc_t;
  228. /*********************************************************************
  229. * GLOBAL VARIABLES
  230. */
  231. extern halDMADesc_t dmaCh0;
  232. extern halDMADesc_t dmaCh1234[4];
  233. /*********************************************************************
  234. * FUNCTIONS - API
  235. */
  236. void HalDmaInit( void );
  237. #endif // #if (defined HAL_DMA) && (HAL_DMA == TRUE)
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. #endif // #ifndef HAL_DMA_H
  242. /******************************************************************************
  243. ******************************************************************************/