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

📄 interrupt.c

📁 安装comedi板卡驱动之后的测试程序
💻 C
字号:
//*************************************************************************//				//	         Copyright (c) 2001 IAG Software Team, ////		           Beijing R&D Center //	//		           Advantech Co., Ltd.////	      User program for Linux comedi device driver//// This is An Unpublished Work Containing Confidential  And Proprietary//    Information Which Is The Property Of Advantech  Automation Corp.//// Any Disclosure, Use, Or Reproduction, Without Written Authorization From//           Advantech Automation Corp., Is Strictly Prohibit.//////*************************************************************************// Program :    interrupt.c// Revision:    1.0                                        // Author  :    Edwin                                             // Date    :    3/15/03                                              //// Description:  write the interrupt control register.//		 For pci1784, the control register is 4 bytes,  //		 they would be the value of insn.data[0],//		 while data[1] determines the interrupt rigester writting//		 operation, which defined to be 0 here.//		 the objective subdevice would be the fake subdevice, //		 subdev = 15.//                                                  //-------------------------------------------------------------------------#include <stdio.h>#include <stdlib.h>#include <comedilib.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>#include <errno.h>#include <getopt.h>#include <ctype.h>#include <math.h>#include <sys/time.h>#include <string.h>#define N_SAMPLE 2 char *filename="/dev/comedi0";int verbose_flag;comedi_t *device;int channel =1;int range = 0;int subdev = 15;int main(void){        lsampl_t data[N_SAMPLE];        int save_errno;        int ret, compare;	int UserInput, TimerInterrupt = 0;	long InterReg = 0, TimerReg = 0;	comedi_insn insn;		printf("************** intctrl.c****************\n");        printf("\n     Comedi driver test program\n\n");        printf("****************************************\n");	printf("Please select interrupt sources:\n\n"); 	printf("Counter overflow interrupt:(multiple)\n");		printf("1. Counter 0 Overflow\n2. Counter 1 Overflow\n");        printf("3. Counter 2 Overflow\n4. Counter 3 Overflow\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 1;			break;		case 2:			InterReg |= 2;			break;		case 3:			InterReg |= 4;			break;		case 4:			InterReg |= 8;			break;		default:			break;		}	}		printf("Counter underflow interrupt:(multiple, Enter for none)\n");		printf("1. Counter 0 Underflow\n2. Counter 1 Underflow\n");        printf("3. Counter 2 Underflow\n4. Counter 3 Underflow\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 0x10;			break;		case 2:			InterReg |= 0x20;			break;		case 3:			InterReg |= 0x40;			break;		case 4:			InterReg |= 0x80;			break;		default:			break;		}	}	printf("Counter index interrupt:(multiple, Enter for none)\n");		printf("1. Counter 0 Index in\n2. Counter 1 Index in\n");        printf("3. Counter 2 Index in\n4. Counter 3 Index in\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 0x100;			break;		case 2:			InterReg |= 0x200;			break;		case 3:			InterReg |= 0x400;			break;		case 4:			InterReg |= 0x800;			break;		default:			break;		}	}		printf("Counter DI interrupt:(multiple, Enter for none)\n");		printf("1. DI 0 Input\n2. DI 1 Input\n");        printf("3. DI 2 Input\n4. DI 3 Input\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 0x1000;			break;		case 2:			InterReg |= 0x2000;			break;		case 3:			InterReg |= 0x4000;			break;		case 4:			InterReg |= 0x8000;			break;		default:			break;		}	}	printf("Counter over compare interrupt:(multiple, Enter for none)\n");		printf("1. Counter 0 over-compare\n2. Counter 1 over-compare\n");        printf("3. Counter 2 over-compare\n4. Counter 3 over-compare\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 0x10000;			break;		case 2:			InterReg |= 0x20000;			break;		case 3:			InterReg |= 0x40000;			break;		case 4:			InterReg |= 0x80000;			break;		default:			break;		}	}		printf("Counter under compare interrupt:(multiple, Enter for none)\n");		printf("1. Counter 0 under-compare\n2. Counter 1 under-compare\n");        printf("3. Counter 2 under-compare\n4. Counter 3 under-compare\n");	while((UserInput = getchar()) != '\n')	{		switch (UserInput-'0')		{		case 1:			InterReg |= 0x100000;			break;		case 2:			InterReg |= 0x200000;			break;		case 3:			InterReg |= 0x400000;			break;		case 4:			InterReg |= 0x800000;			break;		default:			break;		}	}	device = comedi_open(filename);        if(!device){                printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno));		return 1;        }        memset(&insn,0,sizeof(insn));	printf("\nSet counter compare value?(y/N)\n");        if ((UserInput = getchar()) != '\n')		while(!getchar());      // read '\n'        if (UserInput == 'Y' || UserInput == 'y')	{		// Get Channel number;	        while (1)	        {	                printf("Counter channel: (0--3)\t");	                if ((UserInput = getchar()) != '\n')	                        while(!getchar());      // read '\n'	                if (UserInput >= 0x30 && UserInput <=0x33)	                {	                        channel = UserInput - '0';	                        break;	                }else{	                        printf("\nInvalid Channel, please reinput!\n\n");	                }	        }		// Get Channel compare value:		printf("Please input Counter compare value:\n");		scanf("%d", &compare);		while(!getchar());		data[0] = compare;		insn.subdev = 7;	// counter compare subdevice		insn.insn = INSN_WRITE;		insn.n = N_SAMPLE;		insn.data = data;		insn.chanspec = CR_PACK(channel, range, 0);		ret = comedi_do_insn(device, &insn);	// set counter compare value	} 	while(1)	{ 		printf("\nEnable Timer pulse interrupt?(y/N)\n");                if ((UserInput = getchar()) != '\n')			while(!getchar());      // read '\n'                if (UserInput == 'Y' || UserInput == 'y')               {			TimerInterrupt = 1;                        InterReg |= 0x10000000;                        break;		}else			break;	}	insn.subdev = subdev;        insn.insn = INSN_WRITE;        insn.n = N_SAMPLE;        insn.data = data;		if (TimerInterrupt)		// select timer	{		printf("\n\nTimer Select:Sampling clock select:\n");			printf("1. 8 MHz\n2. 4 MHz\n");        	printf("3. 2 MHz\n4. 1 MHz\n");		if((UserInput = getchar()) != '\n')		{			switch (UserInput)			{			case 1:				TimerReg |= 0x0;				break;			case 2:				TimerReg |= 0x1;				break;			case 3:				TimerReg |= 0x2;				break;			case 4:				TimerReg |= 0x3;				break;			default:				break;			}		}			printf("\nTimer Select:Please input the timer divider:(0-255)\n");		scanf("%d",&UserInput);		TimerReg |= (UserInput << 16);		printf("\nTimer Select:timer base:\n");		printf("1. 50KHz\n2. 5KHz\n3. 500Hz\n4. 50Hz\n5. 5Hz\n");		scanf("%d",&UserInput);		if (UserInput != '\n')		{			switch (UserInput)			{			case 1:				TimerReg |= 0x0;				break;			case 2:				TimerReg |= 0x1000000;				break;			case 3:				TimerReg |= 0x2000000;				break;			case 4:				TimerReg |= 0x3000000;				break;			case 5:				TimerReg |= 0x4000000;			default:	// 50KHz				break;			}		}		data[0] = TimerReg;		insn.subdev = 8;		// timer subdevice		ret = comedi_do_insn(device, &insn);	// set timer	}		InterReg |= 0x80000000;	insn.subdev = subdev;	data[0] = InterReg;	ret = comedi_do_insn(device,&insn);     //write interrupt control register		ret = 1;	save_errno = errno;	if(ret<0){	  comedi_perror(filename);	  exit(0);	}       	printf("complete output!\n");		comedi_close(device);		return 1;}

⌨️ 快捷键说明

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