📄 da_dma_cycle.c
字号:
/* FILE NAME: da_dma_cycle.c FILE DESCRIPTION: D/A conversion with fixed waveform generation. Waveform generation data is copied via DMA from buffer of up to 64 kilobytes in size. Samples are loaded directly into the DAC1 and DAC2 FIFO. This program is similar to da_dma but here DMA buffers are not updated once they are loaded. Therefore, the control buffer is is not used. PROJECT NAME: Linux DM7520 Driver, Library, and Example Programs PROJECT VERSION: (Defined in README.TXT) Copyright 2004 RTD Embedded Technologies, Inc. All Rights Reserved.*/#include <stdio.h> //printf#include <stdlib.h> //exit#include <errno.h> //errno#include <slang/slang.h> //for anykey
#include "dm7520_library.h"#define DABUFFERSIZE (12288) // number od samples of waveform generatorint16_t *dabuffer1; //pointer to the wave form buffer 1int16_t *dabuffer2; //pointer to the wave form buffer 2
// load the sqare wave to the buffervoid setBufSq(int16_t *buffer) { int i; int sample; for (i=0; i<DABUFFERSIZE/2;i++){ sample=2047; buffer[i]=sample<<3; } for (i=DABUFFERSIZE/2;i<DABUFFERSIZE;i++) { sample = -2047; buffer[i]=sample<<3; }}// load the ramp wave to the buffervoid setBufRamp(int16_t *buffer) { int i; int sample; for (i=0; i<DABUFFERSIZE;i++){
sample= 2047-(int)(4095.*i/DABUFFERSIZE); buffer[i]=sample<<3; }}
// wait for any key to be pressed
int anykey(void) {
int x;
SLang_init_tty(-1, 1, 1);
x = SLang_getkey();
SLang_reset_tty();
return x;
}//=====================================================================int main(int argc, char * argv[]){ FILE * infile; int ret; // return code int devno; // device handler
if (argc<2) {fprintf(stderr,"Usage: %s <device>\n",argv[0]);exit(1);} if (NULL==(infile=fopen(argv[1],"r+"))) //open device. { fprintf(stderr,"Cannot open file, errno=%d\n",errno); perror("Error is"); exit(2); } devno = fileno(infile); // get device handler InitBoard7520(devno); //Initialize the deviceDACClockFreeRun7520(devno, 1); //set to start/stop mode
DACClockStopSelect7520 (devno, 7); //Software D/A clock stop//Set DMA to DA1 and obtain the buffer for wave form 1 ret = setDA_DMA7520(devno, DM7520_WRITE_DA1,0, &dabuffer1, DABUFFERSIZE*2); // size in bytes, not samples if (ret) { printf("setDA1=%X\n", ret); goto label1; }//Set DMA to DA2 and obtain the buffer for wave form 2 ret = setDA_DMA7520(devno, DM7520_WRITE_DA2, 1, &dabuffer2, DABUFFERSIZE*2); // size in bytes, not samples if (ret) { printf("setDA2=%X\n", ret); goto label1; }// Initialize the buffers setBufSq(dabuffer1); setBufRamp(dabuffer2);// load the buffers to the FIFO setWriteBuffer7520(devno, DM7520_WRITE_DA1,0,DABUFFERSIZE*2); // size in bytes, not samples setWriteBuffer7520(devno, DM7520_WRITE_DA2,1,DABUFFERSIZE*2); // size in bytes, not samplesDACClockStartSelect7520 (devno, 7); //Software D/A clock start
if (SetupDAC7520(devno,DM7520_WRITE_DA1,AOUT_BIP5,DAC_CYCLE_SINGLE,DAC_START_DAC_CLK)) goto label1; // set up DAC1if (SetupDAC7520(devno,DM7520_WRITE_DA2,AOUT_BIP5,DAC_CYCLE_SINGLE,DAC_START_DAC_CLK))goto label1; //set up DAC2SetDACRate7520(devno, 100000);DACClockStop7520(devno); //need to have it here because of the bug in D/A clock/* printf("Press any key to start conversion\n");
anykey();
*/ DACClockStart7520(devno);
/* printf("\nCONVERSION STARTED\n\nPress any key to stop conversion\n");
anykey();
DACClockStop7520(devno);*/printf("press any key to stop conversion\n");anykey();//DACClockStop7520 (devno); //Software D/A clock start
label1: ret = UnSetDMAMode7520(devno, 1); // unset DMA1// if (ret) printf("dma1 unset with code=%X\n", ret); ret = UnSetDMAMode7520(devno, 0); // unset DMA0// if (ret) printf("dma0 unset with code=%X\n", ret); fclose(infile); // close device return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -