Difference between revisions of "TS-4700 Interrupts example code"

From Technologic Systems Manuals
(Created page with "This example below will work with any of our TS-Socket boards running Linux. This opens the IRQ number specified in the first argument and prints when it detects an IRQ. <so...")
 
(Make a little more generic)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This example below will work with any of our TS-Socket boards running Linux. This opens the IRQ number specified in the first argument and prints when it detects an IRQ.
+
This example below will work with any of our products that support userspace IRQs. It opens the IRQ number specified in the first argument, and prints when it detects an IRQ.
  
 
<source lang=c>
 
<source lang=c>
Line 49: Line 49:
 
}
 
}
 
</source>
 
</source>
 
The IRQ numbers 67-69 are muxed IRQs which are only enabled when using the [[#MUXBUS]].  You can enable these by running these commands:
 
<source lang=bash>
 
# If you're in Debian you need this next line
 
# source /initrd/ts4700.subr
 
pc104on
 
</source>
 
This will repurpose other DIO for the [[#MUXBUS]] data, address, and bus control lines as well.
 

Latest revision as of 10:11, 2 July 2020

This example below will work with any of our products that support userspace IRQs. It opens the IRQ number specified in the first argument, and prints when it detects an IRQ.

#include <stdio.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	char proc_irq[32];
	int ret, irqfd = 0;
	int buf; // Holds irq junk data
	fd_set fds;

	if(argc < 2) {
		printf("Usage: %s <irq number>\n", argv[0]);
		return 1;
	}

	snprintf(proc_irq, sizeof(proc_irq), "/proc/irq/%d/irq", atoi(argv[1]));
	irqfd = open(proc_irq, O_RDONLY| O_NONBLOCK, S_IREAD);

	if(irqfd == -1) {
		printf("Could not open IRQ %s\n", argv[1]);
		return 1;
	}
	
	while(1) {
		FD_SET(irqfd, &fds); //add the fd to the set
		// See if the IRQ has any data available to read
		ret = select(irqfd + 1, &fds, NULL, NULL, NULL);
		
		if(FD_ISSET(irqfd, &fds))
		{
			FD_CLR(irqfd, &fds);  //Remove the filedes from set
			printf("IRQ detected\n");
			
			// Clear the junk data in the IRQ file
			read(irqfd, &buf, sizeof(buf));
		}
		
		//Sleep, or do any other processing here
		usleep(10000);
	}
	
	return 0;
}