2022-10-19 22:44:15 +08:00

139 lines
5.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************************************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_dma.c
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <20><EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*
*******************************************************************************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM320.h"
#include "SWM320_dma.h"
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CHM_Config()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMAͨ<41><CDA8><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD><E4A3A8>Flash<73><68>RAM<41><EFBFBD><E4A3A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* uint32_t src_addr Դ<><D4B4>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EBA3AC><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>00
* uint32_t src_addr_incr 0 <20>̶<EFBFBD><CCB6><EFBFBD>ַ 1 <20><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
* uint32_t dst_addr Ŀ<>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EBA3AC><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>00
* uint32_t dst_addr_incr 0 <20>̶<EFBFBD><CCB6><EFBFBD>ַ 1 <20><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
* uint32_t num_word Ҫ<><D2AA><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1024
* uint32_t int_en <09>ж<EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD>1 <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> 0 <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ󲻲<C9BA><F3B2BBB2><EFBFBD><EFBFBD>ж<EFBFBD>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
******************************************************************************************************************************************/
void DMA_CHM_Config(uint32_t chn, uint32_t src_addr, uint32_t src_addr_incr, uint32_t dst_addr, uint32_t dst_addr_incr, uint32_t num_word, uint32_t int_en)
{
DMA->EN = 1; //ÿ<><C3BF>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ؿ<EFBFBD><D8BF>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD><DCBF>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DMA_CH_Close(chn); //<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD>ȹرո<D8B1>ͨ<EFBFBD><CDA8>
DMA->CH[chn].SRC = src_addr;
DMA->CH[chn].DST = dst_addr;
DMA->CH[chn].CR = ((num_word*4-1) << DMA_CR_LEN_Pos) |
(0 << DMA_CR_AUTORE_Pos);
DMA->CH[chn].AM = (src_addr_incr << DMA_AM_SRCAM_Pos) |
(dst_addr_incr << DMA_AM_DSTAM_Pos) |
(0 << DMA_AM_BURST_Pos);
DMA->IF = (1 << chn); //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
DMA->IE |= (1 << chn);
if(int_en) DMA->IM &= ~(1 << chn);
else DMA->IM |= (1 << chn);
if(int_en)
{
NVIC_EnableIRQ(DMA_IRQn);
}
else
{
//<2F><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>NVIC_DisalbeIRQ(DMA_IRQn)<29><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>DMA<4D>ж<EFBFBD>
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_Open()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMAͨ<41><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void DMA_CH_Open(uint32_t chn)
{
DMA->CH[chn].CR |= (1 << DMA_CR_TXEN_Pos);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_Close()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMAͨ<41><CDA8><EFBFBD>ر<EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void DMA_CH_Close(uint32_t chn)
{
DMA->CH[chn].CR &= ~(1 << DMA_CR_TXEN_Pos);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_INTEn()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMA<4D>ж<EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ󴥷<C9BA><F3B4A5B7>ж<EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void DMA_CH_INTEn(uint32_t chn)
{
DMA->IM &= ~(1 << chn);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_INTDis()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMA<4D>жϽ<D0B6>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ󲻴<C9BA><F3B2BBB4><EFBFBD><EFBFBD>ж<EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void DMA_CH_INTDis(uint32_t chn)
{
DMA->IM |= (1 << chn);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_INTClr()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMA<4D>жϱ<D0B6>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void DMA_CH_INTClr(uint32_t chn)
{
DMA->IF = (1 << chn);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: DMA_CH_INTStat()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: DMA<4D>ж<EFBFBD>״̬<D7B4><CCAC>ѯ
* <20><> <20><>: uint32_t chn ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>DMA_CH0<48><30>DMA_CH1<48><31>DMA_CH2
* <20><> <20><>: uint32_t 1 <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint32_t DMA_CH_INTStat(uint32_t chn)
{
return (DMA->IF & (1 << chn)) ? 1 : 0;
}