stm32f10x_dma.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:33k
源码类别:

uCOS

开发平台:

C/C++

  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name          : stm32f10x_dma.c
  3. * Author             : MCD Application Team
  4. * Version            : V2.0.2
  5. * Date               : 07/11/2008
  6. * Description        : This file provides all the DMA firmware functions.
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/
  15. /* Includes ------------------------------------------------------------------*/
  16. #include "stm32f10x_dma.h"
  17. #include "stm32f10x_rcc.h"
  18. /* Private typedef -----------------------------------------------------------*/
  19. /* Private define ------------------------------------------------------------*/
  20. /* DMA ENABLE mask */
  21. #define CCR_ENABLE_Set          ((u32)0x00000001)
  22. #define CCR_ENABLE_Reset        ((u32)0xFFFFFFFE)
  23. /* DMA1 Channelx interrupt pending bit masks */
  24. #define DMA1_Channel1_IT_Mask    ((u32)0x0000000F)
  25. #define DMA1_Channel2_IT_Mask    ((u32)0x000000F0)
  26. #define DMA1_Channel3_IT_Mask    ((u32)0x00000F00)
  27. #define DMA1_Channel4_IT_Mask    ((u32)0x0000F000)
  28. #define DMA1_Channel5_IT_Mask    ((u32)0x000F0000)
  29. #define DMA1_Channel6_IT_Mask    ((u32)0x00F00000)
  30. #define DMA1_Channel7_IT_Mask    ((u32)0x0F000000)
  31. /* DMA2 Channelx interrupt pending bit masks */
  32. #define DMA2_Channel1_IT_Mask    ((u32)0x0000000F)
  33. #define DMA2_Channel2_IT_Mask    ((u32)0x000000F0)
  34. #define DMA2_Channel3_IT_Mask    ((u32)0x00000F00)
  35. #define DMA2_Channel4_IT_Mask    ((u32)0x0000F000)
  36. #define DMA2_Channel5_IT_Mask    ((u32)0x000F0000)
  37. /* DMA2 FLAG mask */
  38. #define FLAG_Mask                ((u32)0x10000000)
  39. /* DMA registers Masks */
  40. #define CCR_CLEAR_Mask           ((u32)0xFFFF800F)
  41. /* Private macro -------------------------------------------------------------*/
  42. /* Private variables ---------------------------------------------------------*/
  43. /* Private function prototypes -----------------------------------------------*/
  44. /* Private functions ---------------------------------------------------------*/
  45. /*******************************************************************************
  46. * Function Name  : DMA_DeInit
  47. * Description    : Deinitializes the DMAy Channelx registers to their default reset
  48. *                  values.
  49. * Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  50. *                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
  51. *                    DMA Channel.
  52. * Output         : None
  53. * Return         : None
  54. *******************************************************************************/
  55. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)
  56. {
  57.   /* Check the parameters */
  58.   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  59.   /* Disable the selected DMAy Channelx */
  60.   DMAy_Channelx->CCR &= CCR_ENABLE_Reset;
  61.   /* Reset DMAy Channelx control register */
  62.   DMAy_Channelx->CCR  = 0;
  63.   
  64.   /* Reset DMAy Channelx remaining bytes register */
  65.   DMAy_Channelx->CNDTR = 0;
  66.   
  67.   /* Reset DMAy Channelx peripheral address register */
  68.   DMAy_Channelx->CPAR  = 0;
  69.   
  70.   /* Reset DMAy Channelx memory address register */
  71.   DMAy_Channelx->CMAR = 0;
  72.   switch (*(u32*)&DMAy_Channelx)
  73.   {
  74.     case DMA1_Channel1_BASE:
  75.       /* Reset interrupt pending bits for DMA1 Channel1 */
  76.       DMA1->IFCR |= DMA1_Channel1_IT_Mask;
  77.       break;
  78.     case DMA1_Channel2_BASE:
  79.       /* Reset interrupt pending bits for DMA1 Channel2 */
  80.       DMA1->IFCR |= DMA1_Channel2_IT_Mask;
  81.       break;
  82.     case DMA1_Channel3_BASE:
  83.       /* Reset interrupt pending bits for DMA1 Channel3 */
  84.       DMA1->IFCR |= DMA1_Channel3_IT_Mask;
  85.       break;
  86.     case DMA1_Channel4_BASE:
  87.       /* Reset interrupt pending bits for DMA1 Channel4 */
  88.       DMA1->IFCR |= DMA1_Channel4_IT_Mask;
  89.       break;
  90.     case DMA1_Channel5_BASE:
  91.       /* Reset interrupt pending bits for DMA1 Channel5 */
  92.       DMA1->IFCR |= DMA1_Channel5_IT_Mask;
  93.       break;
  94.     case DMA1_Channel6_BASE:
  95.       /* Reset interrupt pending bits for DMA1 Channel6 */
  96.       DMA1->IFCR |= DMA1_Channel6_IT_Mask;
  97.       break;
  98.     case DMA1_Channel7_BASE:
  99.       /* Reset interrupt pending bits for DMA1 Channel7 */
  100.       DMA1->IFCR |= DMA1_Channel7_IT_Mask;
  101.       break;
  102.     case DMA2_Channel1_BASE:
  103.       /* Reset interrupt pending bits for DMA2 Channel1 */
  104.       DMA2->IFCR |= DMA2_Channel1_IT_Mask;
  105.       break;
  106.     case DMA2_Channel2_BASE:
  107.       /* Reset interrupt pending bits for DMA2 Channel2 */
  108.       DMA2->IFCR |= DMA2_Channel2_IT_Mask;
  109.       break;
  110.     case DMA2_Channel3_BASE:
  111.       /* Reset interrupt pending bits for DMA2 Channel3 */
  112.       DMA2->IFCR |= DMA2_Channel3_IT_Mask;
  113.       break;
  114.     case DMA2_Channel4_BASE:
  115.       /* Reset interrupt pending bits for DMA2 Channel4 */
  116.       DMA2->IFCR |= DMA2_Channel4_IT_Mask;
  117.       break;
  118.     case DMA2_Channel5_BASE:
  119.       /* Reset interrupt pending bits for DMA2 Channel5 */
  120.       DMA2->IFCR |= DMA2_Channel5_IT_Mask;
  121.       break;
  122.       
  123.     default:
  124.       break;
  125.   }
  126. }
  127. /*******************************************************************************
  128. * Function Name  : DMA_Init
  129. * Description    : Initializes the DMAy Channelx according to the specified
  130. *                  parameters in the DMA_InitStruct.
  131. * Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
  132. *                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
  133. *                    DMA Channel.
  134. *                  - DMA_InitStruct: pointer to a DMA_InitTypeDef structure that
  135. *                    contains the configuration information for the specified
  136. *                    DMA Channel.
  137. * Output         : None
  138. * Return         : None
  139. ******************************************************************************/
  140. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)
  141. {
  142.   u32 tmpreg = 0;
  143.   /* Check the parameters */
  144.   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  145.   assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
  146.   assert_param(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));
  147.   assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
  148.   assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));   
  149.   assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
  150.   assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
  151.   assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
  152.   assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
  153.   assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
  154. /*--------------------------- DMAy Channelx CCR Configuration -----------------*/
  155.   /* Get the DMAy_Channelx CCR value */
  156.   tmpreg = DMAy_Channelx->CCR;
  157.   /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
  158.   tmpreg &= CCR_CLEAR_Mask;
  159.   /* Configure DMAy Channelx: data transfer, data size, priority level and mode */
  160.   /* Set DIR bit according to DMA_DIR value */
  161.   /* Set CIRC bit according to DMA_Mode value */
  162.   /* Set PINC bit according to DMA_PeripheralInc value */
  163.   /* Set MINC bit according to DMA_MemoryInc value */
  164.   /* Set PSIZE bits according to DMA_PeripheralDataSize value */
  165.   /* Set MSIZE bits according to DMA_MemoryDataSize value */
  166.   /* Set PL bits according to DMA_Priority value */
  167.   /* Set the MEM2MEM bit according to DMA_M2M value */
  168.   tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
  169.             DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
  170.             DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
  171.             DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
  172.   /* Write to DMAy Channelx CCR */
  173.   DMAy_Channelx->CCR = tmpreg;
  174. /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
  175.   /* Write to DMAy Channelx CNDTR */
  176.   DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
  177. /*--------------------------- DMAy Channelx CPAR Configuration ----------------*/
  178.   /* Write to DMAy Channelx CPAR */
  179.   DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
  180. /*--------------------------- DMAy Channelx CMAR Configuration ----------------*/
  181.   /* Write to DMAy Channelx CMAR */
  182.   DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
  183. }
  184. /*******************************************************************************
  185. * Function Name  : DMA_StructInit
  186. * Description    : Fills each DMA_InitStruct member with its default value.
  187. * Input          : - DMA_InitStruct : pointer to a DMA_InitTypeDef structure
  188. *                    which will be initialized.
  189. * Output         : None
  190. * Return         : None
  191. *******************************************************************************/
  192. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
  193. {
  194. /*-------------- Reset DMA init structure parameters values ------------------*/
  195.   /* Initialize the DMA_PeripheralBaseAddr member */
  196.   DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
  197.   /* Initialize the DMA_MemoryBaseAddr member */
  198.   DMA_InitStruct->DMA_MemoryBaseAddr = 0;
  199.   /* Initialize the DMA_DIR member */
  200.   DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
  201.   /* Initialize the DMA_BufferSize member */
  202.   DMA_InitStruct->DMA_BufferSize = 0;
  203.   /* Initialize the DMA_PeripheralInc member */
  204.   DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  205.   /* Initialize the DMA_MemoryInc member */
  206.   DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
  207.   /* Initialize the DMA_PeripheralDataSize member */
  208.   DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  209.   /* Initialize the DMA_MemoryDataSize member */
  210.   DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  211.   /* Initialize the DMA_Mode member */
  212.   DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
  213.   /* Initialize the DMA_Priority member */
  214.   DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
  215.   /* Initialize the DMA_M2M member */
  216.   DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
  217. }
  218. /*******************************************************************************
  219. * Function Name  : DMA_Cmd
  220. * Description    : Enables or disables the specified DMAy Channelx.
  221. * Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
  222. *                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
  223. *                    DMA Channel.
  224. *                  - NewState: new state of the DMAy Channelx. 
  225. *                    This parameter can be: ENABLE or DISABLE.
  226. * Output         : None
  227. * Return         : None
  228. *******************************************************************************/
  229. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
  230. {
  231.   /* Check the parameters */
  232.   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  233.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  234.   if (NewState != DISABLE)
  235.   {
  236.     /* Enable the selected DMAy Channelx */
  237.     DMAy_Channelx->CCR |= CCR_ENABLE_Set;
  238.   }
  239.   else
  240.   {
  241.     /* Disable the selected DMAy Channelx */
  242.     DMAy_Channelx->CCR &= CCR_ENABLE_Reset;
  243.   }
  244. }
  245. /*******************************************************************************
  246. * Function Name  : DMA_ITConfig
  247. * Description    : Enables or disables the specified DMAy Channelx interrupts.
  248. * Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
  249. *                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
  250. *                    DMA Channel.
  251. *                  - DMA_IT: specifies the DMA interrupts sources to be enabled
  252. *                    or disabled. 
  253. *                    This parameter can be any combination of the following values:
  254. *                       - DMA_IT_TC:  Transfer complete interrupt mask
  255. *                       - DMA_IT_HT:  Half transfer interrupt mask
  256. *                       - DMA_IT_TE:  Transfer error interrupt mask
  257. *                  - NewState: new state of the specified DMA interrupts.
  258. *                    This parameter can be: ENABLE or DISABLE.
  259. * Output         : None
  260. * Return         : None
  261. *******************************************************************************/
  262. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, u32 DMA_IT, FunctionalState NewState)
  263. {
  264.   /* Check the parameters */
  265.   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  266.   assert_param(IS_DMA_CONFIG_IT(DMA_IT));
  267.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  268.   if (NewState != DISABLE)
  269.   {
  270.     /* Enable the selected DMA interrupts */
  271.     DMAy_Channelx->CCR |= DMA_IT;
  272.   }
  273.   else
  274.   {
  275.     /* Disable the selected DMA interrupts */
  276.     DMAy_Channelx->CCR &= ~DMA_IT;
  277.   }
  278. }
  279. /*******************************************************************************
  280. * Function Name  : DMA_GetCurrDataCounter
  281. * Description    : Returns the number of remaining data units in the current
  282. *                  DMAy Channelx transfer.
  283. * Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
  284. *                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
  285. *                    DMA Channel.
  286. * Output         : None
  287. * Return         : The number of remaining data units in the current DMAy Channelx
  288. *                  transfer.
  289. *******************************************************************************/
  290. u16 DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
  291. {
  292.   /* Check the parameters */
  293.   assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  294.   /* Return the number of remaining data units for DMAy Channelx */
  295.   return ((u16)(DMAy_Channelx->CNDTR));
  296. }
  297. /*******************************************************************************
  298. * Function Name  : DMA_GetFlagStatus
  299. * Description    : Checks whether the specified DMAy Channelx flag is set or not.
  300. * Input          : - DMA_FLAG: specifies the flag to check.
  301. *                    This parameter can be one of the following values:
  302. *                       - DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  303. *                       - DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  304. *                       - DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  305. *                       - DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  306. *                       - DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  307. *                       - DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  308. *                       - DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  309. *                       - DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  310. *                       - DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  311. *                       - DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  312. *                       - DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  313. *                       - DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  314. *                       - DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  315. *                       - DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  316. *                       - DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  317. *                       - DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  318. *                       - DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  319. *                       - DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  320. *                       - DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  321. *                       - DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  322. *                       - DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  323. *                       - DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  324. *                       - DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  325. *                       - DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  326. *                       - DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  327. *                       - DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  328. *                       - DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  329. *                       - DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  330. *                       - DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  331. *                       - DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  332. *                       - DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  333. *                       - DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  334. *                       - DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  335. *                       - DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  336. *                       - DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  337. *                       - DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  338. *                       - DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  339. *                       - DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  340. *                       - DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  341. *                       - DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  342. *                       - DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  343. *                       - DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  344. *                       - DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  345. *                       - DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  346. *                       - DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  347. *                       - DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  348. *                       - DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  349. *                       - DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  350. * Output         : None
  351. * Return         : The new state of DMA_FLAG (SET or RESET).
  352. *******************************************************************************/
  353. FlagStatus DMA_GetFlagStatus(u32 DMA_FLAG)
  354. {
  355.   FlagStatus bitstatus = RESET;
  356.   u32 tmpreg = 0;
  357.   /* Check the parameters */
  358.   assert_param(IS_DMA_GET_FLAG(DMA_FLAG));
  359.   /* Calculate the used DMA */
  360.   if ((DMA_FLAG & FLAG_Mask) != (u32)RESET)
  361.   {
  362.     /* Get DMA2 ISR register value */
  363.     tmpreg = DMA2->ISR ;
  364.   }
  365.   else
  366.   {
  367.     /* Get DMA1 ISR register value */
  368.     tmpreg = DMA1->ISR ;
  369.   }
  370.   /* Check the status of the specified DMA flag */
  371.   if ((tmpreg & DMA_FLAG) != (u32)RESET)
  372.   {
  373.     /* DMA_FLAG is set */
  374.     bitstatus = SET;
  375.   }
  376.   else
  377.   {
  378.     /* DMA_FLAG is reset */
  379.     bitstatus = RESET;
  380.   }
  381.   
  382.   /* Return the DMA_FLAG status */
  383.   return  bitstatus;
  384. }
  385. /*******************************************************************************
  386. * Function Name  : DMA_ClearFlag
  387. * Description    : Clears the DMAy Channelx's pending flags.
  388. * Input          : - DMA_FLAG: specifies the flag to clear.
  389. *                    This parameter can be any combination (for the same DMA) of 
  390. *                    the following values:
  391. *                       - DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  392. *                       - DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  393. *                       - DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  394. *                       - DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  395. *                       - DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  396. *                       - DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  397. *                       - DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  398. *                       - DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  399. *                       - DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  400. *                       - DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  401. *                       - DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  402. *                       - DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  403. *                       - DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  404. *                       - DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  405. *                       - DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  406. *                       - DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  407. *                       - DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  408. *                       - DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  409. *                       - DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  410. *                       - DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  411. *                       - DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  412. *                       - DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  413. *                       - DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  414. *                       - DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  415. *                       - DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  416. *                       - DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  417. *                       - DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  418. *                       - DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  419. *                       - DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  420. *                       - DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  421. *                       - DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  422. *                       - DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  423. *                       - DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  424. *                       - DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  425. *                       - DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  426. *                       - DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  427. *                       - DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  428. *                       - DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  429. *                       - DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  430. *                       - DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  431. *                       - DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  432. *                       - DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  433. *                       - DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  434. *                       - DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  435. *                       - DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  436. *                       - DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  437. *                       - DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  438. *                       - DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  439. * Output         : None
  440. * Return         : None
  441. *******************************************************************************/
  442. void DMA_ClearFlag(u32 DMA_FLAG)
  443. {
  444.   /* Check the parameters */
  445.   assert_param(IS_DMA_CLEAR_FLAG(DMA_FLAG));
  446.   /* Calculate the used DMA */
  447.   if ((DMA_FLAG & FLAG_Mask) != (u32)RESET)
  448.   {
  449.     /* Clear the selected DMA flags */
  450.     DMA2->IFCR = DMA_FLAG;
  451.   }
  452.   else
  453.   {
  454.     /* Clear the selected DMA flags */
  455.     DMA1->IFCR = DMA_FLAG;
  456.   }
  457. }
  458. /*******************************************************************************
  459. * Function Name  : DMA_GetITStatus
  460. * Description    : Checks whether the specified DMAy Channelx interrupt has 
  461. *                  occurred or not.
  462. * Input          : - DMA_IT: specifies the DMA interrupt source to check. 
  463. *                    This parameter can be one of the following values:
  464. *                       - DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  465. *                       - DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  466. *                       - DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  467. *                       - DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  468. *                       - DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  469. *                       - DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  470. *                       - DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  471. *                       - DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  472. *                       - DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  473. *                       - DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  474. *                       - DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  475. *                       - DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  476. *                       - DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  477. *                       - DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  478. *                       - DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  479. *                       - DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  480. *                       - DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  481. *                       - DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  482. *                       - DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  483. *                       - DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  484. *                       - DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  485. *                       - DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  486. *                       - DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  487. *                       - DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  488. *                       - DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  489. *                       - DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  490. *                       - DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  491. *                       - DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  492. *                       - DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  493. *                       - DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  494. *                       - DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  495. *                       - DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  496. *                       - DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  497. *                       - DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  498. *                       - DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  499. *                       - DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  500. *                       - DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  501. *                       - DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  502. *                       - DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  503. *                       - DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  504. *                       - DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  505. *                       - DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  506. *                       - DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  507. *                       - DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  508. *                       - DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  509. *                       - DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  510. *                       - DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  511. *                       - DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  512. * Output         : None
  513. * Return         : The new state of DMA_IT (SET or RESET).
  514. *******************************************************************************/
  515. ITStatus DMA_GetITStatus(u32 DMA_IT)
  516. {
  517.   ITStatus bitstatus = RESET;
  518.   u32 tmpreg = 0;
  519.   /* Check the parameters */
  520.   assert_param(IS_DMA_GET_IT(DMA_IT));
  521.   /* Calculate the used DMA */
  522.   if ((DMA_IT & FLAG_Mask) != (u32)RESET)
  523.   {
  524.     /* Get DMA2 ISR register value */
  525.     tmpreg = DMA2->ISR ;
  526.   }
  527.   else
  528.   {
  529.     /* Get DMA1 ISR register value */
  530.     tmpreg = DMA1->ISR ;
  531.   }
  532.   /* Check the status of the specified DMA interrupt */
  533.   if ((tmpreg & DMA_IT) != (u32)RESET)
  534.   {
  535.     /* DMA_IT is set */
  536.     bitstatus = SET;
  537.   }
  538.   else
  539.   {
  540.     /* DMA_IT is reset */
  541.     bitstatus = RESET;
  542.   }
  543.   /* Return the DMA_IT status */
  544.   return  bitstatus;
  545. }
  546. /*******************************************************************************
  547. * Function Name  : DMA_ClearITPendingBit
  548. * Description    : Clears the DMAy Channelx抯 interrupt pending bits.
  549. * Input          : - DMA_IT: specifies the DMA interrupt pending bit to clear.
  550. *                    This parameter can be any combination (for the same DMA) of
  551. *                    the following values:
  552. *                       - DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  553. *                       - DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  554. *                       - DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  555. *                       - DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  556. *                       - DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  557. *                       - DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  558. *                       - DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  559. *                       - DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  560. *                       - DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  561. *                       - DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  562. *                       - DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  563. *                       - DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  564. *                       - DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  565. *                       - DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  566. *                       - DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  567. *                       - DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  568. *                       - DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  569. *                       - DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  570. *                       - DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  571. *                       - DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  572. *                       - DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  573. *                       - DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  574. *                       - DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  575. *                       - DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  576. *                       - DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  577. *                       - DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  578. *                       - DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  579. *                       - DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  580. *                       - DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  581. *                       - DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  582. *                       - DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  583. *                       - DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  584. *                       - DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  585. *                       - DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  586. *                       - DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  587. *                       - DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  588. *                       - DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  589. *                       - DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  590. *                       - DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  591. *                       - DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  592. *                       - DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  593. *                       - DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  594. *                       - DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  595. *                       - DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  596. *                       - DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  597. *                       - DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  598. *                       - DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  599. *                       - DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  600. * Output         : None
  601. * Return         : None
  602. *******************************************************************************/
  603. void DMA_ClearITPendingBit(u32 DMA_IT)
  604. {
  605.   /* Check the parameters */
  606.   assert_param(IS_DMA_CLEAR_IT(DMA_IT));
  607.   /* Calculate the used DMA */
  608.   if ((DMA_IT & FLAG_Mask) != (u32)RESET)
  609.   {
  610.     /* Clear the selected DMA interrupt pending bits */
  611.     DMA2->IFCR = DMA_IT;
  612.   }
  613.   else
  614.   {
  615.     /* Clear the selected DMA interrupt pending bits */
  616.     DMA1->IFCR = DMA_IT;
  617.   }
  618. }
  619. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/