📄 async.c
字号:
/* FILE NAME: async.c FILE DESCRIPTION: Demonstrates asynchronous notification of interrupts. This program sets up a function to be called when interrupt notification occurs and the board is programmed to interrupt on every FIFO write. User output 0 signal (pin number 55) is toggled during every notification. 100 samples are initiated. When 20 samples have been started, notification is disabled. When 50 samples have been started, notification is enabled again. When 90 samples have been started, interrupts are disabled. A total of 60 events will happen in this scenario. When each sample is initiated, the number of samples, number of notifications, and interrupt status are printed. All acquired samples are printed 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 <unistd.h> //usleep#include <stdlib.h> //exit#include <errno.h> //errno#include "dm7520_library.h"int hb=0;FILE * infile;int counter = 0;uint16_t itStat = 0;int devno; //device handlervoid do_async_stuff(void){ WriteUserOutput7520(devno,hb); hb^=1; counter++; GetITStatus7520(devno, &itStat);}int main(int argc, char * argv[]){ int cnt,i; uint16_t fifostat; short sample; int channel; cg_entry_t cgl; uint16_t *z=(uint16_t*)&cgl; uint8_t bus_master; uint8_t fifo_empty; 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); IsBusMaster7520(devno, &bus_master); if (bus_master != 0) printf("Busmaster card\n"); else printf("Non-busmaster card\n"); InitBoard7520(devno); 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); SetUout0Source7520(devno,UOUT_SOFTWARE);
SetUout1Source7520(devno,UOUT_ADC); SetNotification7520(devno,(unsigned short) IRQS_ADC_FIFO_WRITE,do_async_stuff); cnt=100; for (i=0;i<cnt;i++) { StartConversion7520(devno);// usleep(100000); usleep(1000); printf("Sampling: %d counter=%d ITstatus=%X\n",i, counter,itStat);fflush(stdout); itStat = 0; if (20==counter) UnSetNotification7520(devno); if(50==i) SetNotification7520(devno,(unsigned short) IRQS_ADC_FIFO_WRITE,do_async_stuff); if (90==i) SetITMask7520(devno,0); // disable interrupts } printf("\n"); i=1; IsADFifoEmpty7520(devno, &fifo_empty); while(fifo_empty == 0) { ReadADDataWithMarker7520(devno, &sample); sample/=8; printf("%-5d ",sample); if (0==i%8) printf("\n"); i++; IsADFifoEmpty7520(devno, &fifo_empty); } GetFifoStatus7520(devno, &fifostat); printf("\nFIFO status: %04X.\n",fifostat); fclose(infile); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -