不要给我推荐例程,例程里面只有读的,没有写的,我这里写没成功,配置如下
#include "drv_xintf.h"
Uint16 *z0startaddr = (Uint16 *)0x4000;
Uint16 *z6startaddr = (Uint16 *)0x100000;
Uint16 *z7startaddr = (Uint16 *)0x200000;
static void peripherals_xintf_init(void)
{
SysCtrlRegs.PCLKCR3.bit.XINTFENCLK = 1;
InitXintf16Gpio();
EALLOW;
XintfRegs.XINTCNF2.bit.XTIMCLK = 1;
XintfRegs.XINTCNF2.bit.WRBUFF = 0;
XintfRegs.XINTCNF2.bit.CLKOFF = 0;
XintfRegs.XINTCNF2.bit.CLKMODE = 1;
XintfRegs.XINTCNF2.bit.HOLD = 1;
XintfRegs.XTIMING6.bit.XWRLEAD = 1;
XintfRegs.XTIMING6.bit.XWRACTIVE = 2;
XintfRegs.XTIMING6.bit.XWRTRAIL = 1;
XintfRegs.XTIMING6.bit.XRDLEAD = 1;
XintfRegs.XTIMING6.bit.XRDACTIVE = 3;
XintfRegs.XTIMING6.bit.XRDTRAIL = 0;
XintfRegs.XTIMING6.bit.X2TIMING = 0;
XintfRegs.XTIMING6.bit.USEREADY = 0;
XintfRegs.XTIMING6.bit.READYMODE = 0;
XintfRegs.XTIMING6.bit.XSIZE = 3;
EDIS;
__asm(" RPT #7 || NOP");
}
/**
* @brief: DMA寄存器初始化
* @details:
* @param[in] : none.
* @param[out] : none.
* @return: none.
* @par modification:
*/
void peripherals_xintf_dmaread(Uint16 *start_addr, Uint16 *data, Uint16 len)
{
volatile unsigned int *dmadest;
volatile unsigned int *dmasource;
CpuTimer0Regs.TCR.bit.TSS = 1; //Stop Timer0 for now
dmadest = data;
dmasource = start_addr; //Point DMA source to ADC result register base
DMACH2AddrConfig(dmadest, dmasource);
/*
* 一次传输32个字,实际上为半字,
* 1.bsize = 31:表示一帧传输31+1=32个字(WORD),
* 2.srcbstep = 1:表示每个WORD传输完成后源地址的偏移+2,
* 3.desbstep = 1:表示每个WORD传输完成后目的地址的偏移+2
* */
DMACH2BurstConfig(31, 2, 2);
/* 1.tsize = len/32-1:表示每 len / 32 帧传输后中断一次。
* 2.srctstep = 2:表示每一帧后,在前一帧的源地址上偏移+2。
* 3.deststep = 2:表示每一帧后,在前一帧的目的地址上偏移+2。
* */
DMACH2TransferConfig(len / 32 - 1, 2, 2);
/*
* 里面的四个参数分别是SRC_WRAP_SIZE,SRC_WRAP_STEP,DST_WRAP_SIZE和DST_WRAP_STEP。
* 每进行完2次burst以后,源地址回到初始位置(两次Burst正好对应4个通道每个都转换2次),
* 每进行完1次burst,目的地址变为起始地址+1(指向DMABuf1的下一个单元)。
* */
DMACH2WrapConfig(0xFFFF, 0, 0xFFFF, 0);
DMACH2ModeConfig(DMA_TINT0, PERINT_ENABLE,
ONESHOT_ENABLE, CONT_DISABLE,
SYNC_DISABLE, SYNC_SRC,
OVRFLOW_DISABLE, THIRTYTWO_BIT,
CHINT_END, CHINT_ENABLE);
StartDMACH2();
CpuTimer0Regs.TIM.half.LSW = 512; //load low value so we can start the DMA quickly
CpuTimer0Regs.TCR.bit.SOFT = 1; //Allow to free run even if halted
CpuTimer0Regs.TCR.bit.FREE = 1;
CpuTimer0Regs.TCR.bit.TIE = 1; //Enable the timer0 interrupt signal
CpuTimer0Regs.TCR.bit.TSS = 0; //restart the timer 0
}
/**
* @brief: DMA寄存器初始化
* @details:
* @param[in] : none.
* @param[out] : none.
* @return: none.
* @par modification:
*/
void peripherals_xintf_dmawrite(Uint16 *start_addr, const Uint16 *data, Uint16 len)
{
volatile unsigned int *dmadest;
volatile unsigned int *dmasource;
CpuTimer1Regs.TCR.bit.TSS = 1; //Stop Timer0 for now
dmadest = start_addr;
dmasource = data; //Point DMA source to ADC result register base
DMACH3AddrConfig(dmadest, dmasource);
/*
* 一次传输32个字,实际上为半字,
* 1.bsize = 31:表示一帧传输31+1=32个字(WORD),
* 2.srcbstep = 1:表示每个WORD传输完成后源地址的偏移+2,
* 3.desbstep = 1:表示每个WORD传输完成后目的地址的偏移+2
* */
DMACH3BurstConfig(31, 2, 2);
/* 1.tsize = len/32-1:表示每 len / 32 帧传输后中断一次。
* 2.srctstep = 2:表示每一帧后,在前一帧的源地址上偏移+2。
* 3.deststep = 2:表示每一帧后,在前一帧的目的地址上偏移+2。
* */
DMACH3TransferConfig(len / 32 - 1, 2, 2);
/*
* 里面的四个参数分别是SRC_WRAP_SIZE,SRC_WRAP_STEP,DST_WRAP_SIZE和DST_WRAP_STEP。
* 每进行完2次burst以后,源地址回到初始位置(两次Burst正好对应4个通道每个都转换2次),
* 每进行完1次burst,目的地址变为起始地址+1(指向DMABuf1的下一个单元)。
* */
DMACH3WrapConfig(0xFFFF, 0, 0xFFFF, 0);
DMACH3ModeConfig(DMA_TINT0, PERINT_ENABLE,
ONESHOT_ENABLE, CONT_DISABLE,
SYNC_DISABLE, SYNC_SRC,
OVRFLOW_DISABLE, THIRTYTWO_BIT,
CHINT_END, CHINT_ENABLE);
StartDMACH3();
CpuTimer1Regs.TIM.half.LSW = 512; //load low value so we can start the DMA quickly
CpuTimer1Regs.TCR.bit.SOFT = 1; //Allow to free run even if halted
CpuTimer1Regs.TCR.bit.FREE = 1;
CpuTimer1Regs.TCR.bit.TIE = 1; //Enable the timer0 interrupt signal
CpuTimer1Regs.TCR.bit.TSS = 0; //restart the timer 0
}
__interrupt void local_dintch2_isr(void)
{
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
}
__interrupt void local_dintch3_isr(void)
{
PieCtrlRegs.PIEACK.bit.ACK7 = 1;
}
/**
*@ Description:初始化ADC中包含的所有配置
* @param 无.
* @return 无
*/
void drv_xintf_init(void)
{
EALLOW; // Allow access to EALLOW protected registers
PieVectTable.DINTCH2= &local_dintch2_isr;
PieVectTable.DINTCH3= &local_dintch3_isr;
EDIS; // Disable access to EALLOW protected registers
IER = M_INT7 ;
EnableInterrupts();
EINT;
DMAInitialize();
peripherals_xintf_init();
}