⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_dma.c

📁 诺基亚5110 LCD资料
💻 C
📖 第 1 页 / 共 3 页
字号:
  DMA_InitStruct->DMA_MemoryBaseAddr = 0;

  /* Initialize the DMA_DIR member */
  DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;

  /* Initialize the DMA_BufferSize member */
  DMA_InitStruct->DMA_BufferSize = 0;

  /* Initialize the DMA_PeripheralInc member */
  DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  /* Initialize the DMA_MemoryInc member */
  DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;

  /* Initialize the DMA_PeripheralDataSize member */
  DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

  /* Initialize the DMA_MemoryDataSize member */
  DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

  /* Initialize the DMA_Mode member */
  DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;

  /* Initialize the DMA_Priority member */
  DMA_InitStruct->DMA_Priority = DMA_Priority_Low;

  /* Initialize the DMA_M2M member */
  DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
}

/*******************************************************************************
* Function Name  : DMA_Cmd
* Description    : Enables or disables the specified DMAy Channelx.
* Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
*                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
*                    DMA Channel.
*                  - NewState: new state of the DMAy Channelx. 
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected DMAy Channelx */
    DMAy_Channelx->CCR |= CCR_ENABLE_Set;
  }
  else
  {
    /* Disable the selected DMAy Channelx */
    DMAy_Channelx->CCR &= CCR_ENABLE_Reset;
  }
}

/*******************************************************************************
* Function Name  : DMA_ITConfig
* Description    : Enables or disables the specified DMAy Channelx interrupts.
* Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
*                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
*                    DMA Channel.
*                  - DMA_IT: specifies the DMA interrupts sources to be enabled
*                    or disabled. 
*                    This parameter can be any combination of the following values:
*                       - DMA_IT_TC:  Transfer complete interrupt mask
*                       - DMA_IT_HT:  Half transfer interrupt mask
*                       - DMA_IT_TE:  Transfer error interrupt mask
*                  - NewState: new state of the specified DMA interrupts.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, u32 DMA_IT, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  assert_param(IS_DMA_CONFIG_IT(DMA_IT));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected DMA interrupts */
    DMAy_Channelx->CCR |= DMA_IT;
  }
  else
  {
    /* Disable the selected DMA interrupts */
    DMAy_Channelx->CCR &= ~DMA_IT;
  }
}

/*******************************************************************************
* Function Name  : DMA_GetCurrDataCounter
* Description    : Returns the number of remaining data units in the current
*                  DMAy Channelx transfer.
* Input          : - DMAy_Channelx: where y can be 1 or 2 to select the DMA and 
*                    x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the 
*                    DMA Channel.
* Output         : None
* Return         : The number of remaining data units in the current DMAy Channelx
*                  transfer.
*******************************************************************************/
u16 DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
{
  /* Check the parameters */
  assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));

  /* Return the number of remaining data units for DMAy Channelx */
  return ((u16)(DMAy_Channelx->CNDTR));
}

/*******************************************************************************
* Function Name  : DMA_GetFlagStatus
* Description    : Checks whether the specified DMAy Channelx flag is set or not.
* Input          : - DMA_FLAG: specifies the flag to check.
*                    This parameter can be one of the following values:
*                       - DMA1_FLAG_GL1: DMA1 Channel1 global flag.
*                       - DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
*                       - DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
*                       - DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
*                       - DMA1_FLAG_GL2: DMA1 Channel2 global flag.
*                       - DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
*                       - DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
*                       - DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
*                       - DMA1_FLAG_GL3: DMA1 Channel3 global flag.
*                       - DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
*                       - DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
*                       - DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
*                       - DMA1_FLAG_GL4: DMA1 Channel4 global flag.
*                       - DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
*                       - DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
*                       - DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
*                       - DMA1_FLAG_GL5: DMA1 Channel5 global flag.
*                       - DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
*                       - DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
*                       - DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
*                       - DMA1_FLAG_GL6: DMA1 Channel6 global flag.
*                       - DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
*                       - DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
*                       - DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
*                       - DMA1_FLAG_GL7: DMA1 Channel7 global flag.
*                       - DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
*                       - DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
*                       - DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
*                       - DMA2_FLAG_GL1: DMA2 Channel1 global flag.
*                       - DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
*                       - DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
*                       - DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
*                       - DMA2_FLAG_GL2: DMA2 Channel2 global flag.
*                       - DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
*                       - DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
*                       - DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
*                       - DMA2_FLAG_GL3: DMA2 Channel3 global flag.
*                       - DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
*                       - DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
*                       - DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
*                       - DMA2_FLAG_GL4: DMA2 Channel4 global flag.
*                       - DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
*                       - DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
*                       - DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
*                       - DMA2_FLAG_GL5: DMA2 Channel5 global flag.
*                       - DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
*                       - DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
*                       - DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
* Output         : None
* Return         : The new state of DMA_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus DMA_GetFlagStatus(u32 DMA_FLAG)
{
  FlagStatus bitstatus = RESET;
  u32 tmpreg = 0;

  /* Check the parameters */
  assert_param(IS_DMA_GET_FLAG(DMA_FLAG));

  /* Calculate the used DMA */
  if ((DMA_FLAG & FLAG_Mask) != (u32)RESET)
  {
    /* Get DMA2 ISR register value */
    tmpreg = DMA2->ISR ;
  }
  else
  {
    /* Get DMA1 ISR register value */
    tmpreg = DMA1->ISR ;
  }

  /* Check the status of the specified DMA flag */
  if ((tmpreg & DMA_FLAG) != (u32)RESET)
  {
    /* DMA_FLAG is set */
    bitstatus = SET;
  }
  else
  {
    /* DMA_FLAG is reset */
    bitstatus = RESET;
  }
  
  /* Return the DMA_FLAG status */
  return  bitstatus;
}

/*******************************************************************************
* Function Name  : DMA_ClearFlag
* Description    : Clears the DMAy Channelx's pending flags.
* Input          : - DMA_FLAG: specifies the flag to clear.
*                    This parameter can be any combination (for the same DMA) of 
*                    the following values:
*                       - DMA1_FLAG_GL1: DMA1 Channel1 global flag.
*                       - DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
*                       - DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
*                       - DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
*                       - DMA1_FLAG_GL2: DMA1 Channel2 global flag.
*                       - DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
*                       - DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
*                       - DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
*                       - DMA1_FLAG_GL3: DMA1 Channel3 global flag.
*                       - DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
*                       - DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
*                       - DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
*                       - DMA1_FLAG_GL4: DMA1 Channel4 global flag.
*                       - DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -