#include "dma.h"


DMA_InitTypeDef DMA_InitStructure;

u16 DMA1_MEM_LEN;//DMAÿݴ͵ĳ 	    
//DMA1ĸͨ
//Ĵʽǹ̶,Ҫݲͬ޸
//Ӵ洢->ģʽ/8λݿ/洢ģʽ
//DMA_CHx:DMAͨCHx
//cpar:ַ
//cmar:洢ַ
//cndtr:ݴ 
void MYDMA_Config(DMA_Channel_TypeDef* DMA_CHx,u32 cpar,u32 cmar,u16 cndtr)
{
 	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);	//ʹDMA
	
  DMA_DeInit(DMA_CHx);   //DMAͨ1ĴΪȱʡֵ
	DMA1_MEM_LEN=cndtr;
	DMA_InitStructure.DMA_PeripheralBaseAddr = cpar;  //DMAADCַ
	DMA_InitStructure.DMA_MemoryBaseAddr = cmar;  //DMAڴַ
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;  //ݴ䷽򣬴ڴȡ͵
	DMA_InitStructure.DMA_BufferSize = cndtr;  //DMAͨDMAĴС
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  //ַĴ
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;  //ڴַĴ
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;  //ݿΪ8λ
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //ݿΪ8λ
	DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;  //ģʽ
	DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //DMAͨ xӵȼ 
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;  //DMAͨxûΪڴ浽ڴ洫
	DMA_Init(DMA_CHx, &DMA_InitStructure);  //DMA_InitStructָĲʼDMAͨUSART1_Tx_DMA_ChannelʶļĴ
	  	
} 

void MYDMA_Config1(DMA_Channel_TypeDef* DMA_CHx,u32 cpar,u32 cmar,u16 cndtr)
{
 	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);	//ʹDMA
	
  DMA_DeInit(DMA_CHx);   //DMAͨ1ĴΪȱʡֵ
	DMA1_MEM_LEN=cndtr;
	DMA_InitStructure.DMA_PeripheralBaseAddr = cpar;  //DMAADCַ
	DMA_InitStructure.DMA_MemoryBaseAddr = cmar;  //DMAڴַ
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;  //ݴ䷽򣬴ڴȡ͵
	DMA_InitStructure.DMA_BufferSize = cndtr;  //DMAͨDMAĴС
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  //ַĴ
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;  //ڴַĴ
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  //ݿΪ16λ
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //ݿΪ16λ
	DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;  //ģʽ
	DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //DMAͨ xӵȼ 
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;  //DMAͨxûΪڴ浽ڴ洫
	DMA_Init(DMA_CHx, &DMA_InitStructure);  //DMA_InitStructָĲʼDMAͨUSART1_Tx_DMA_ChannelʶļĴ
} 

//һDMA
void MYDMA_Enable(DMA_Channel_TypeDef*DMA_CHx)
{ 
	DMA_Cmd(DMA_CHx, DISABLE );
 	DMA_SetCurrDataCounter(DMA1_Channel3,DMA1_MEM_LEN);
 	DMA_Cmd(DMA_CHx, ENABLE);
}	  

 

























