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

📄 91x_dma.c

📁 a set or ARM9 examples by STM
💻 C
📖 第 1 页 / 共 3 页
字号:
{
  u32 DMAReg = 0;

  switch(DMA_ITReq)

 {

   case (DMA_IS):  /*The status of the interrupts after masking : logical or of all Interrupts after Masking*/
    DMAReg = DMA->ISR;	
    break;

  			

   case (DMA_TCS):     /* The status of the Terminal count request after masking */
    DMAReg = DMA->TCISR;
    break;


   case (DMA_ES):   /* The status of the error request after masking */
    DMAReg = DMA->EISR;
    break;


   case (DMA_TCRS): /* Indicates if the DMA channel is requesting a transfer complete (terminal count Interrupt) prior to masking or Not. */
    DMAReg = DMA->TCRISR;
    break;

   case (DMA_ERS):  /* Indicates if the DMA channel is requesting an Error Interrupt prior to masking or Not. */
     DMAReg = DMA->ERISR;
     break;


  }

  if((DMAReg &(1 <<  ChannelIndx )) != RESET )

  {
   return SET;
  }

  else

  {

  return RESET;
				

  }

}


/********************************************************************************
* Function Name  : DMA_ClearIT
* Description    : Clears The Interrupt pending bits for termnal count or Error interrupts for a specified DMA Channel.
*                  - ChannelIndx:specifies the DMA Channel to be checked.
*                   This parameter can be:
*				      - Channel0
*					  - Channel1
*					  - Channel2
*					  - Channel3
*					  - Channel4
*					  - Channel5
*				      - Channel6
*					  - Channel7
*				  - DMA_ITClr : Specifies the DMA interrupt pending to be cleared.
*.                    This parameter can be:
*                     - DMA_TCC
*					  - DMA_EC.
*
* Output         : None.

* Return         : SET or RESET.
*******************************************************************************/


void DMA_ClearIT(u8 ChannelIndx,u8 DMA_ITClr)

{


 switch(DMA_ITClr)

 {

  case (DMA_TCC): /* Clear The status of the Terminal count interrupt on the corresponding channel.*/
    DMA->TCICR |=(1 <<  ChannelIndx );
    break;         	



  case (DMA_EC): /* Clear The status of the error interrupt on the corresponding channel.*/
    DMA->EICR |=(1 <<  ChannelIndx );
    break;		

				

 }



}


/*******************************************************************************
* Function Name  : DMA_Cmd(FunctionalState NewState)
* Description    : Enables or disables the DMA peripheral.
*
* Input          :
*                  -NewState: new state of the DMA.
*                             This parameter can be: ENABLE or DISABLE.
* Output         : None.
* Return         : None.
*******************************************************************************/


void DMA_Cmd(FunctionalState NewState)

{
  if (NewState==ENABLE) /* ENABLE the DMA peripheral  */

  {
    DMA-> CNFR |= DMA_Enable ;
  }

  else /* DISABLE the DMA peripheral */
  {
    DMA-> CNFR &= ~ DMA_Enable ;
  }
}



/*******************************************************************************
* Function Name  : DMA_ChannelCmd
* Description    : Enables or disables the specified DMA_Channelx
*
* Input          :
*                  -DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
*                  -NewState: new state of the specified DMA_Channelx mask interrupt.
*                             This parameter can be: ENABLE or DISABLE.
* Output         : None.
* Return         : None.
*******************************************************************************/


void DMA_ChannelCmd (DMA_Channel_TypeDef *DMA_Channelx,FunctionalState NewState)

{
  if (NewState==ENABLE) /*  Enable The Channelx */

  {
    DMA_Channelx->CCNF |= DMA_ChannelEnable ;
  }

  else /* Disable The Channelx */
  {
    DMA_Channelx-> CCNF &= ~ DMA_ChannelEnable ;
  }
}



/********************************************************************************
* Function Name  : DMA_GetChannelActiveStatus
* Description    : Checks The DMA_Channelx FIFO if it has data or not.
* Input          :
*                  -DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
*
*
* Output         : None.
*
* Return         : SET or RESET.
*******************************************************************************/


FlagStatus  DMA_GetChannelActiveStatus( DMA_Channel_TypeDef * DMA_Channelx )

{

 if ( ( DMA_Channelx->CCNF & DMA_ChannelActive) != RESET )
 {
   return SET; /* The DMA_Channelx FIFO has data */
 }

 else

 {

  return RESET; /* No data in the DMA_Channelx FIFO */


 }

}


/********************************************************************************
* Function Name   : DMA_DeInit
* Description     : Initializes the DMA peripheral registers to their default reset values.
*
*
* Input           : None
*
* Output          : None.
*
* Called Functions:
*
*                   - SCU_AHBPeriphReset: Function defined in the System clock Unit "scu.c".
*
*
* Return          : None
*******************************************************************************/


void DMA_DeInit(void)

{
 
  SCU_AHBPeriphReset(__DMA, ENABLE);         /*DMA peripheral is under Reset " Reset on"*/
  SCU_AHBPeriphReset(__DMA, DISABLE);        /*DMA peripheral Reset off*/
}



/********************************************************************************
* Function Name  : DMA_StructInit
* Description    : Fills each DMA_InitStruct member with its reset value.
* Input          :
*                  -DMA_InitStruct: pointer to a DMA_InitTypeDef structure which will be initialized.
*
* Output         : None.
*
* Return         : None
*******************************************************************************/


void DMA_StructInit(DMA_InitTypeDef * DMA_InitStruct)

{

	 /* Initialize The current source address */
     DMA_InitStruct-> DMA_Channel_SrcAdd =0x0000000;


     /* Initialize The current Destination address */
     DMA_InitStruct->DMA_Channel_DesAdd=0x00000000;



	 /* Initialize The Linked List Items */
     DMA_InitStruct->DMA_Channel_LLstItm=0x00000000 ;



     /* Initialize The Destination width */
	 DMA_InitStruct->DMA_Channel_DesWidth= DMA_DesWidth_Byte;



     /* Initialize The source width */
     DMA_InitStruct->DMA_Channel_SrcWidth= DMA_SrcWidth_Byte;


     /* Initialize The Burst Size for the Destination */
     DMA_InitStruct->DMA_Channel_DesBstSize= DMA_DesBst_1Data; /* 1 Data "one Data can be byte, halfword or word depending on the Destination width  */



     /* Initialize The Burst Size for the Source*/
     DMA_InitStruct->DMA_Channel_SrcBstSize= DMA_SrcBst_1Data; /* 1 Data "one Data can be byte, halfword or word depending on the source width  */

    /* Initialize The Flow control and transfer type for the DMA transfer */
     DMA_InitStruct->DMA_Channel_FlowCntrl=DMA_FlowCntrlt0_DMA; /* memory to memory transfer with DMA as flow controller */


     /* Initialize The Transfer Size */
     DMA_InitStruct->DMA_Channel_TrsfSize =0x00;

	

     /* Initialize the DMA source request peripheral :"This field is ignored if the source of the transfer is from memory" */
     DMA_InitStruct->DMA_Channel_Src =0x00;



     /* Initialize the DMA Destination request peripheral :"This field is ignored if the destination of the transfer is to memory.*/

     DMA_InitStruct->DMA_Channel_Des=0x00;


}




/********************************************************************************
* Function Name  : DMA_Init
* Description    : Initializes the DMA_Channelx according to the specified parameters
*                    in the DMA_InitStruct .
*
* Input          :
*                  -DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
*				  -DMA_InitStruct: pointer to a DMA_InitTypeDef structure
*				  ( Structure Config to be load in DMA Registers). .
*
* Output         : None.
*
* Return         : None
*******************************************************************************/


void DMA_Init(DMA_Channel_TypeDef * DMA_Channelx, DMA_InitTypeDef * DMA_InitStruct)

{



   /* Select the DMA source peripheral request */
    DMA_Channelx->CCNF &= SRC_Mask;
    DMA_Channelx->CCNF |= DMA_InitStruct->DMA_Channel_Src;


 /* Select the flow controller and the transfer type */
    DMA_Channelx->CCNF &= DMA_FlowCntrl_Mask;
    DMA_Channelx->CCNF |=DMA_InitStruct->DMA_Channel_FlowCntrl;


    /* Select the DMA Destination peripheral request*/
    DMA_Channelx->CCNF &= DES_Mask;
    DMA_Channelx->CCNF |= DMA_InitStruct->DMA_Channel_Des;

    /* Set the source address */
    DMA_Channelx->SRC = DMA_InitStruct-> DMA_Channel_SrcAdd ;


	 /* Set the destination address */

    DMA_Channelx->DES = DMA_InitStruct->DMA_Channel_DesAdd ;



    /* Set the linked list Items address */
    DMA_Channelx->LLI = DMA_InitStruct->DMA_Channel_LLstItm ;


    /* Set The Destination width */
    DMA_Channelx->CC &= DMA_Width_DES_MASK;
    DMA_Channelx->CC |= DMA_InitStruct->DMA_Channel_DesWidth;


    /* Set The Source width  */
    DMA_Channelx->CC &= DMA_Width_SRC_MASK;
    DMA_Channelx->CC |= DMA_InitStruct->DMA_Channel_SrcWidth;

    /* Set The Burst Size for the Destination */
    DMA_Channelx->CC &= DMA_Bst_DES_MASK;
    DMA_Channelx->CC |= DMA_InitStruct->DMA_Channel_DesBstSize;

   /* Set The Burst Size for the Source */
   DMA_Channelx->CC &= DMA_Bst_SRC_MASK;
   DMA_Channelx->CC |=DMA_InitStruct->DMA_Channel_SrcBstSize;


    /* Initialize The Transfer Size for the Source */
    DMA_Channelx->CC &= DMA_TrsfSisze_Mask;
    DMA_Channelx->CC |= DMA_InitStruct->DMA_Channel_TrsfSize;


}


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

⌨️ 快捷键说明

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