⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad_dma.c

📁 rt 7520采集卡 linux驱动源代码
💻 C
字号:
/*	FILE NAME: ad_dma.c	FILE DESCRIPTION:		AD conversion with pacer clock in DMA mode.  Samples are read		into a buffer and then shown on the screen	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 "dm7520_library.h"#define BUFSIZE 20480#define RATE 1000000    	//Pacer clock frequency in Hzint main(int argc, char * argv[]){ FILE * infile; int16_t buffer [BUFSIZE]; int cnt,i; uint16_t fifostat; int err;
 int devno;		//device handler float actualPacerRate; int channel; int useDMA  = 0; cg_entry_t cgl; uint16_t *z=(uint16_t*)&cgl;
 int errorCode=0; uint8_t	bus_master; if (argc<2) {fprintf(stderr,"Usage: %s <device> [channel]\n",argv[0]);exit(1);} if (NULL==(infile=fopen(argv[1],"r")))   {    fprintf(stderr,"Cannot open file, errno=%d\n",errno);    perror("Error is");    exit(2);   } if (argc==3)   {    channel=atoi(argv[2])-1;   } else channel=0; if (channel<0 || channel>15)   {    fprintf(stderr,"%s: Channel number not in valid range (1..16).\n",argv[0]);    exit(1);   }
   devno = fileno(infile);		// get device handler IsBusMaster7520(devno, &bus_master); if (bus_master != 0) {    printf("Busmaster card\n");    useDMA=1; } else {    printf("Non-busmaster card\n"); } InitBoard7520(devno);     // init the board GetFifoStatus7520(devno, &fifostat); printf("\nFIFO status: %04X.\n",fifostat); EnableCGT7520(devno,0); SetupCgtRow7520(&cgl,channel,0,0,0,0,0,0,0,0); WriteCGTLatch7520(devno,(uint16_t)*z); SetPacerStart7520(devno, PCLK_START_SOFTWARE); SetPacerStop7520(devno, PCLK_STOP_SOFTWARE); SetPacerRateF7520(devno, RATE,1,&actualPacerRate); printf("Pacer clock rate: %8.2f\n", actualPacerRate); SetConversionSelect7520(devno, ADC_START_PCLK); if (useDMA) {     err = SetAD_DMAMode7520(devno,0);    if (err < 0) printf("ERROR: could not set DMA mode \n");    else printf("DMA started \n"); } ClearADFifo7520(devno); StartPacer7520(devno); cnt=ReadData7520(devno, buffer,BUFSIZE); printf("got data\n"); if (cnt !=BUFSIZE) {
	 GetErrorCode7520(devno, &errorCode);
	 printf("ERROR while reading data read byte = %d\nError code=%d\n", cnt, errorCode);
	 ClearErrorCode7520(devno);
 } StopPacer7520(devno); if (useDMA) {    err = UnSetDMAMode7520(devno, 0);    if (err<0) printf("ERROR: could not unset DMA mode \n"); } printf("read %d samples\n", cnt); printf("Raw samples:"); for (i=0;i<(cnt);i++)   {    if (0==i%8) printf("\n");    printf("%5d ", buffer[i]>>3); // to delere data markers   } printf("\n"); fclose(infile); return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -