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

📄 hd_dma.c

📁 rt 7520采集卡 linux驱动源代码
💻 C
字号:
/*	FILE NAME: hd_dma.c	FILE DESCRIPTION:		Demonstrates how to use on demand DMA with high speed digital		input.		Samples are read into a buffer and then displayed on the		screen.		User Timer Counter 0 is used to initiate sampling.		Please note that high speed digital input DMA internally uses		User Timer Counter 1 so you cannot use it for anything else.	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 50000	//input rate 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 int useDMA  = 0; int errorCode=0; uint8_t	bus_master; if (argc<2) {fprintf(stderr,"Usage: %s <device> \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);   }    devno = fileno(infile);		// get device handler IsBusMaster7520(devno, &bus_master); if (bus_master) {    printf("Busmaster card\n");    useDMA=1; } else {    printf("Non-busmaster card\n"); } InitBoard7520(devno);     // init the board

 SetUtc0Clock7520 (devno, CUTC0_8MHZ);
 Set8254Mode7520(devno, TC_UTC0, M8254_RATE_GENERATOR ) ;
 SetUtc0Gate7520 (devno, GUTC0_NOT_GATED );  
 SetHdinStart7520 ( devno, 2) ;	//get samples on HSDIO on user TC0

 GetFifoStatus7520(devno, &fifostat); printf("\nFIFO status: %04X.\n",fifostat); if (useDMA) {     err = SetHD_DMAMode7520(devno,0);    if (err < 0) printf("ERROR: could not set DMA mode \n");    else printf("DMA started \n"); } ClearDinFifo7520(devno); Set8254Divisor7520 (devno, TC_UTC0,(uint16_t)(8000000L/RATE) ); //set TC0 rate 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);
 }  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%16) printf("\n");    printf("%2X  ", (buffer[i]) & 0xFF);   } printf("\n"); fclose(infile); return(0);}

⌨️ 快捷键说明

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