📄 extint.c
字号:
/* FILE NAME: extint.c FILE DESCRIPTION: Demonstrates usage of an external interrupt. Digital I/O port 1 bit 0 (pin number 46) is used to generate the external trigger. This pin must be connected to the External Interrupt Input pin ( pin number 51). This program sets up a notification function to be called when the external interrupt occurs. This function increments a counter which keeps track of the number of external interrupts that have occurred. A positive edge triggers an external interrupt unless 'n' is passed in as the second command argument, which means a negative edge triggers an external interrupt. 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 <slang/slang.h> //for anykey#include "dm7520_library.h"int counter = 0;
int anykey(void) {
int x;
SLang_init_tty(-1, 1, 1);
x = SLang_getkey();
SLang_reset_tty();
return x;
}
void do_async_stuff(void){ counter++;}int main(int argc, char * argv[]){ FILE * infile;
int devno; //device handler
char negative = 0;
if (argc<2) {fprintf(stderr,"Usage: %s <device> [n]\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) if (argv[2][0]=='n') negative = 1; //use negative edge of external trigger
devno = fileno(infile); // get device handler
InitBoard7520(devno);
SetDIO1Direction7520(devno, 1); //set port1 to output
WriteDIO17520(devno,0);
SetEintPolarity7520 ( devno, negative);
if (negative) printf ("Using external interrupt, negative edge\n");
else printf ("Using external interrupt, positive edge\n");
SetNotification7520(devno,(unsigned short) IRQS_EXTERNAL_IT,do_async_stuff);
printf("Press any key for positive edge of external Interrupt\n");
anykey();
WriteDIO17520(devno,1);
usleep(10);
if (counter==0){
printf("No Interrupt notification\n");
printf("Press any key for negative edge of external trigger\n");
anykey();
WriteDIO17520(devno,0);
usleep(10);
if (counter==0){
printf("No Interrupt notification\n");
}
else {
printf("Got Interrupt notification\n");
}
}
else {
printf("Got Interrupt notification\n");
}
printf("Press any key to exit the program\n");
anykey();
UnSetNotification7520(devno);
fclose(infile); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -