📄 73x_dma.c
字号:
* - 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(DMA_TypeDef* DMAx, u16 DMA_IT, FunctionalState NewState)
{
if(NewState == ENABLE)
{
DMAx->MASK |= DMA_IT;
}
else
{
DMAx->MASK &= ~DMA_IT;
}
}
/*******************************************************************************
* Function Name : DMA_GetCurrDSTAddr
* Description : Returns the current value of the destination address pointer
* related to the specified DMA stream.
* Input : - DMAx: where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Stream: specifies the DMA stream to get its destination
* address pointer current value.
* This parameter can be one of the following values:
* - DMA_Stream0
* - DMA_Stream1
* - DMA_Stream2
* - DMA_Stream3
* Output : None
* Return : The current value of the destination address pointer related
* to the specified DMA stream.
*******************************************************************************/
u32 DMA_GetCurrDSTAddr(DMA_TypeDef* DMAx, u8 DMA_Stream)
{
u32 Stream_BaseAddr = 0;
/* get the base address of the stream to be used:
Stream_BaseAddr := DMAx_Base + Stream offset */
Stream_BaseAddr = (*(u32*)&(DMAx)) + DMA_Stream ;
return(*(u32*)(Stream_BaseAddr+DMA_DECURRL)|(*(u32*)(Stream_BaseAddr+DMA_DECURRH)<<16));
}
/*******************************************************************************
* Function Name : DMA_GetCurrSRCAddr
* Description : Returns the current value of the source address pointer
* related to the specified DMA stream.
* Input : - DMAx: where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Stream: specifies the DMA stream to get its source
* address pointer current value.
* This parameter can be one of the following values:
* - DMA_Stream0
* - DMA_Stream1
* - DMA_Stream2
* - DMA_Stream3
* Output : None
* Return : The current value of the source address pointer related to
* the specified DMA stream.
*******************************************************************************/
u32 DMA_GetCurrSRCAddr(DMA_TypeDef* DMAx, u8 DMA_Stream)
{
u32 Stream_BaseAddr = 0;
/* get the base address of the stream to be used:
Stream_BaseAddr := DMAx_Base + Stream offset */
Stream_BaseAddr = (*(u32*)&(DMAx)) + DMA_Stream ;
return(*(u32*)(Stream_BaseAddr+DMA_SOCURRL)|(*(u32*)(Stream_BaseAddr+DMA_SOCURRH)<<16));
}
/*******************************************************************************
* Function Name : DMA_GetTerminalCounter
* Description : Returns the number of data units remaining in the current
* DMAx stream transfer.
* Input : - DMAx: where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Stream: specifies the DMA stream to get its number of
* data units remaining in the current DMA transfer.
* This parameter can be one of the following values:
* - DMA_Stream0
* - DMA_Stream1
* - DMA_Stream2
* - DMA_Stream3
* Output : None
* Return : The number of data units remaining in the current DMAx stream
* transfer.
*******************************************************************************/
u16 DMA_GetTerminalCounter(DMA_TypeDef* DMAx, u8 DMA_Stream)
{
u32 Stream_BaseAddr = 0;
/* get the base address of the stream to be used:
Stream_BaseAddr := DMAx_Base + Stream offset */
Stream_BaseAddr = (*(u32*)&(DMAx)) + DMA_Stream ;
return(*(u32*)(Stream_BaseAddr+DMA_TCNT));
}
/*******************************************************************************
* Function Name : DMA_LastBufferSweepConfig
* Description : Activates the last buffer sweep mode for the DMAx stream
* configured in circular buffer mode.
* Input : - DMAx: where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Stream: specifies the DMA stream to start its last
* circular buffer sweep.
* This parameter can be one of the following values:
* - DMA_Stream0
* - DMA_Stream1
* - DMA_Stream2
* - DMA_Stream3
* Output : None
* Return : None
*******************************************************************************/
void DMA_LastBufferSweepConfig(DMA_TypeDef* DMAx, u8 DMA_Stream)
{
switch(DMA_Stream)
{
case DMA_Stream0 :
DMAx->Last |= DMA_LAST0;
break;
case DMA_Stream1 :
DMAx->Last |= DMA_LAST1;
break;
case DMA_Stream2:
DMAx->Last |= DMA_LAST2;
break;
case DMA_Stream3:
DMAx->Last |= DMA_LAST3;
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 : - DMAx: where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Stream: specifies the DMA stream to configure.
* This parameter can be one of the following values:
* - DMA_Stream0
* - DMA_Stream1
* - DMA_Stream2
* - DMA_Stream3
* - DMA_LastBufferAddr: specifies the circular buffer position
* where the last data to be used by the specified DMA stream
* is located.
* Output : None
* Return : None
*******************************************************************************/
void DMA_LastBufferAddrConfig(DMA_TypeDef* DMAx, u8 DMA_Stream, u16 DMA_LastBufferAddr)
{
u32 Stream_BaseAddr = 0;
/* get the base address of the stream to be used:
Stream_BaseAddr := DMAx_Base + Stream offset */
Stream_BaseAddr = (*(u32*)&(DMAx)) + DMA_Stream ;
*(u16 *)(Stream_BaseAddr + DMA_LUBUFF) = DMA_LastBufferAddr;
}
/*******************************************************************************
* Function Name : DMA_TimeOutConfig
* Description : Sets DMA transaction time out.
* Input : TimeOut_Value: specifies the DMA Time Out value.
* Output : None
* Return : None
*******************************************************************************/
void DMA_TimeOutConfig(u16 TimeOut_Value)
{
/* set the DMA Time Out value */
ARB->TOR = TimeOut_Value;
}
/*******************************************************************************
* Function Name : DMA_FlagStatus
* Description : Checks whether the specified DMA controller flag is set or not.
* Input : - DMAx : where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Flag: flag to check. This parameter can be one of the
* following values:
* - DMA_FLAG_INT0: Stream0 transfer end interrupt flag
* - DMA_FLAG_INT1: Stream1 transfer end interrupt flag
* - DMA_FLAG_INT2: Stream2 transfer end interrupt flag
* - DMA_FLAG_INT3: Stream3 transfer end interrupt flag
* - DMA_FLAG_ERR0: Stream0 transfer error interrupt flag
* - DMA_FLAG_ERR1: Stream1 transfer error interrupt flag
* - DMA_FLAG_ERR2: Stream2 transfer error interrupt flag
* - DMA_FLAG_ERR3: Stream3 transfer error interrupt 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_FlagStatus(DMA_TypeDef* DMAx, u16 DMA_Flag)
{
if((DMAx->STATUS & DMA_Flag) != RESET)
{
return SET;
}
else
{
return RESET;
}
}
/*******************************************************************************
* Function Name : DMA_FlagClear
* Description : Clears the pending interrupt flags corresponding to the
* specified DMA stream.
* Input : - DMAx : where x can be 0, 1, 2 or 3 to select the DMA controller.
* - DMA_Flag: flags to clear. This parameter can be any
* combination of the following values:
* - DMA_FLAG_INT0: Clears the pending flag of Stream0
* transfer end interrupt.
* - DMA_FLAG_INT1: Clears the pending flag of Stream1
* transfer end interrupt.
* - DMA_FLAG_INT2: Clears the pending flag of Stream2
* transfer end interrupt.
* - DMA_FLAG_INT3: Clears the pending flag of Stream3
* transfer end interrupt.
* - DMA_FLAG_ERR0: Clears the pending flag of Stream0
* transfer error interrupt.
* - DMA_FLAG_ERR1: Clears the pending flag of Stream1
* transfer error interrupt.
* - DMA_FLAG_ERR2: Clears the pending flag of Stream2
* transfer error interrupt.
* - DMA_FLAG_ERR3: Clears the pending flag of Stream3
* transfer error interrupt.
* Output : None
* Return : None
*******************************************************************************/
void DMA_FlagClear(DMA_TypeDef* DMAx, u16 DMA_Flag)
{
/* Set the bit corresponding to the flags to clear */
DMAx->CLR = DMA_Flag ;
}
/******************* (C) COPYRIGHT 2005 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -