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

📄 75x_dma.c

📁 嵌入式实验源码。包括:电源管理、复位、时钟管理
💻 C
📖 第 1 页 / 共 2 页
字号:
* Description    : Enables or disables the specified DMA interrupts.
* Input          : - DMA_IT: specifies the DMA interrupts sources to be enabled
*                    or disabled. This parameter can be any combination of the
*                    following values:
*                         - DMA_IT_SI0: Stream0 transfer end interrupt mask
*                         - DMA_IT_SI1: Stream1 transfer end interrupt mask
*                         - DMA_IT_SI2: Stream2 transfer end interrupt mask
*                         - DMA_IT_SI3: Stream3 transfer end interrupt mask
*                         - DMA_IT_SE0: Stream0 transfer error interrupt mask
*                         - DMA_IT_SE1: Stream1 transfer error interrupt mask
*                         - DMA_IT_SE2: Stream2 transfer error interrupt mask
*                         - DMA_IT_SE3: Stream3 transfer error interrupt mask
*                         - DMA_IT_ALL: ALL DMA interrupts mask
*                  - NewState: new state of the specified DMA interrupts.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_ITConfig(u16 DMA_IT, FunctionalState NewState)
{
  if(NewState == ENABLE)
  {
    /* Enable the selected DMA interrupts */
    DMA->MASK |= DMA_IT;
  }
  else
  {
    /* Disable the selected DMA interrupts */
    DMA->MASK &= ~DMA_IT;
  }
}

/*******************************************************************************
* Function Name  : DMA_GetCurrDSTAddr
* Description    : Returns the current value of the destination address pointer
*                  related to the specified DMA stream.
* Input          : - DMA_Streamx: where x can be 0, 1, 2 or 3 to select the DMA
*                    Stream.
* Output         : None
* Return         : The current value of the destination address pointer related
*                  to the specified DMA stream.
*******************************************************************************/
u32 DMA_GetCurrDSTAddr(DMA_Stream_TypeDef*  DMA_Streamx)
{ 
  u32 Tmp = 0;

  /* Get high current destination address */
  Tmp = (DMA_Streamx->DECURRH)<<16;
  /* Get low current destination address */
  Tmp |= DMA_Streamx->DECURRL;

  /* Return the current destination address value for streamx */
  return Tmp;
}

/*******************************************************************************
* Function Name  : DMA_GetCurrSRCAddr
* Description    : Returns the current value of the source address pointer
*                  related to the specified DMA stream.
* Input          : - DMA_Streamx: where x can be 0, 1, 2 or 3 to select the DMA
*                    Stream.
* Output         : None
* Return         : The current value of the source address pointer related to
*                  the specified DMA stream.
*******************************************************************************/
u32 DMA_GetCurrSRCAddr(DMA_Stream_TypeDef*  DMA_Streamx)
{
  u32 Tmp = 0;

  /* Get high current source address */
  Tmp = (DMA_Streamx->SOCURRH)<<16;
  /* Get slow current source address */
  Tmp |= DMA_Streamx->SOCURRL;

  /* Return the current source address value for streamx */
  return Tmp;
}

/*******************************************************************************
* Function Name  : DMA_GetTerminalCounter
* Description    : Returns the number of data units remaining in the current
*                  DMA stream transfer.
* Input          : - DMA_Streamx: where x can be 0, 1, 2 or 3 to select the DMA
*                    Stream.
* Output         : None
* Return         : The number of data units remaining in the current DMA stream
*                  transfer.
*******************************************************************************/
u16 DMA_GetTerminalCounter(DMA_Stream_TypeDef*  DMA_Streamx)
{
  /* Return the terminal counter value for streamx */
  return(DMA_Streamx->TCNT);
}

/*******************************************************************************
* Function Name  : DMA_LastBufferSweepConfig
* Description    : Activates or disactivates the last buffer sweep mode for the 
*                  DMA streamx configured in circular buffer mode.
* Input          : - DMA_Streamx: where x can be 0, 1, 2 or 3 to select the DMA
*                    Stream.
*                  - NewState: new state of the Last buffer sweep DMA_Streamx.                 
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_LastBufferSweepConfig(DMA_Stream_TypeDef* DMA_Streamx, FunctionalState NewState)
{  
  switch(*(u32*)&DMA_Streamx)
  {
    case DMA_Stream0_BASE:
      if(NewState == ENABLE)
      {
        /* Activates the last circular buffer sweep mode for stream0 */
        DMA->LAST |= DMA_Last0_Enable_Mask;
      }
      else
      {
        /* Disactivates the last circular buffer sweep mode for stream0 */
        DMA->LAST &= DMA_Last0_Disable_Mask;
      }	
      break;

    case DMA_Stream1_BASE:
      if(NewState == ENABLE)
      {
        /* Activates the last circular buffer sweep mode for stream1 */
        DMA->LAST |= DMA_Last1_Enable_Mask;
      }
      else
      {
        /* Disactivates the last circular buffer sweep mode for stream1 */
        DMA->LAST &= DMA_Last1_Disable_Mask;
      }	
      break;

    case DMA_Stream2_BASE:
      if(NewState == ENABLE)
      {
        /* Activates the last circular buffer sweep mode for stream2 */
        DMA->LAST |= DMA_Last2_Enable_Mask;
      }
      else
      {
        /* Disactivates the last circular buffer sweep mode for stream2 */
        DMA->LAST &= DMA_Last2_Disable_Mask;
      }	
      break;

    case DMA_Stream3_BASE:
      if(NewState == ENABLE)
      {
        /* Activates the last circular buffer sweep mode for stream3 */
        DMA->LAST |= DMA_Last3_Enable_Mask;
      }
      else
      {
        /* Disactivates the last circular buffer sweep mode for stream3 */
        DMA->LAST &= DMA_Last3_Disable_Mask;
      }	
      break;
    
    default:
      break;      
  }
}

/*******************************************************************************
* Function Name  : DMA_LastBufferAddrConfig
* Description    : Configures the circular buffer position where the last data 
*                  to be used by the specified DMA stream is located.
* Input          : - DMA_Streamx: where x can be 0, 1, 2 or 3 to select the DMA
*                    Stream.
*                  - DMA_LastBufferAddr: specifies the circular buffer position
*                    where the last data to be used by the specified DMA stream
*                    is located.
*                    This member must be a number between 0 and the stream BufferSize-1.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_LastBufferAddrConfig(DMA_Stream_TypeDef*  DMA_Streamx, u16 DMA_LastBufferAddr)
{
  /* Set the streamx last data circular buffer location */
  DMA_Streamx->LUBUFF = DMA_LastBufferAddr;
}

/*******************************************************************************
* Function Name  : DMA_GetFlagStatus
* Description    : Checks whether the specified DMA flag is set or not.
* Input          : - DMA_FLAG: specifies the flag to check. This parameter can 
*                    be one of the following values:
*                         - DMA_FLAG_SI0:  Stream0 transfer end flag.
*                         - DMA_FLAG_SI1:  Stream1 transfer end flag.
*                         - DMA_FLAG_SI2:  Stream2 transfer end flag.
*                         - DMA_FLAG_SI3:  Stream3 transfer end flag.
*                         - DMA_FLAG_SE0:  Stream0 transfer error flag.
*                         - DMA_FLAG_SE1:  Stream1 transfer error flag.
*                         - DMA_FLAG_SE2:  Stream2 transfer error flag.
*                         - DMA_FLAG_SE3:  Stream3 transfer error flag.
*                         - DMA_FLAG_ACT0: Stream0 status.
*                         - DMA_FLAG_ACT1: Stream1 status.
*                         - DMA_FLAG_ACT2: Stream2 status.
*                         - DMA_FLAG_ACT3: Stream3 status.
* Output         : None
* Return         : The new state of DMA_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus DMA_GetFlagStatus(u16 DMA_FLAG)
{
  /* Check the status of the specified DMA flag */
  if((DMA->STATUS & DMA_FLAG) != RESET)
  {
    /* Return SET if DMA_FLAG is set */
    return SET;
  }
  else
  {
    /* Return RESET if DMA_FLAG is reset */
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : DMA_ClearFlag
* Description    : Clears the DMA抯 pending flags.
* Input          : - DMA_FLAG: specifies the flag to clear. This parameter can 
*                    be any combination of the following values:
*                         - DMA_FLAG_SI0:  Stream0 transfer end flag.
*                         - DMA_FLAG_SI1:  Stream1 transfer end flag.
*                         - DMA_FLAG_SI2:  Stream2 transfer end flag.
*                         - DMA_FLAG_SI3:  Stream3 transfer end flag.
*                         - DMA_FLAG_SE0:  Stream0 transfer error flag.
*                         - DMA_FLAG_SE1:  Stream1 transfer error flag.
*                         - DMA_FLAG_SE2:  Stream2 transfer error flag.
*                         - DMA_FLAG_SE3:  Stream3 transfer error flag.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_ClearFlag(u16 DMA_FLAG)
{
  /* Clear the selected DMA flags */ 
  DMA->CLR = DMA_FLAG ;
}

/*******************************************************************************
* Function Name  : DMA_GetITStatus
* Description    : Checks whether the specified DMA interrupt has occured or not.
* Input          : - DMA_IT: specifies the DMA interrupt source to check.  
*                    This parameter can be one of the following values:
*                         - DMA_IT_SI0: Stream0 transfer end interrupt 
*                         - DMA_IT_SI1: Stream1 transfer end interrupt 
*                         - DMA_IT_SI2: Stream2 transfer end interrupt 
*                         - DMA_IT_SI3: Stream3 transfer end interrupt 
*                         - DMA_IT_SE0: Stream0 transfer error interrupt 
*                         - DMA_IT_SE1: Stream1 transfer error interrupt 
*                         - DMA_IT_SE2: Stream2 transfer error interrupt 
*                         - DMA_IT_SE3: Stream3 transfer error interrupt 
* Output         : None
* Return         : The new state of DMA_IT (SET or RESET).
*******************************************************************************/
ITStatus DMA_GetITStatus(u16 DMA_IT)
{
  /* Check the status of the specified DMA interrupt */
  if((DMA->STATUS & DMA_IT) != RESET)
  {
    /* Return SET if the DMA interrupt flag is set */
    return SET;
  }
  else
  {
    /* Return RESET if the DMA interrupt flag is reset */
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : DMA_ClearITPendingBit
* Description    : Clears the DMA抯 interrupt pending bits. 
* Input          : - DMA_IT: specifies the interrupt pending bit to clear.  
*                    This parameter can be any combination of the following values:
*                         - DMA_IT_SI0:  Stream0 transfer end interrupt.
*                         - DMA_IT_SI1:  Stream1 transfer end interrupt.
*                         - DMA_IT_SI2:  Stream2 transfer end interrupt.
*                         - DMA_IT_SI3:  Stream3 transfer end interrupt.
*                         - DMA_IT_SE0:  Stream0 transfer error interrupt.
*                         - DMA_IT_SE1:  Stream1 transfer error interrupt.
*                         - DMA_IT_SE2:  Stream2 transfer error interrupt.
*                         - DMA_IT_SE3:  Stream3 transfer error interrupt.
*                         - DMA_IT_ALL:  All DMA interrupts.
* Output         : None
* Return         : None
*******************************************************************************/
void DMA_ClearITPendingBit(u16 DMA_IT)
{
  /* Clear the selected DMA interrupts pending bits */
  DMA->CLR = DMA_IT ;
}

/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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