TS-4800 Interrupts: Difference between revisions

From embeddedTS Manuals
(Created page with "The TS-4800 has several IRQs that can be used by external devices. See chapter 3 of the [http://cache.freescale.com/files/dsp/doc/ref_manual/MCIMX51RM.pdf?fpsp=1 CPU manual] ...")
 
No edit summary
Line 1: Line 1:
The TS-4800 has several IRQs that can be used by external devices.  See chapter 3 of the [http://cache.freescale.com/files/dsp/doc/ref_manual/MCIMX51RM.pdf?fpsp=1 CPU manual] for a complete listing of all of the available IRQs.   
The TS-4800 has several IRQs that can be used by external devices.  See chapter 3 of the [http://cache.freescale.com/files/dsp/doc/ref_manual/MCIMX51RM.pdf?fpsp=1 CPU manual] for a complete listing of all of the available IRQs.   
{| class="wikitable"
|-
! IRQ #
! Name
! Socket Location
|-
| 50
| Combined Interrupt GPIO1_0 - GPIO1_15
| CN2_56, CN2_58, CN2_60, CN2_72, CN1_57, CN1_4
|-
| 56
| Combined Interrupt GPIO4_0 - GPIO4_15
| CN2_13, CN2_14
|-
| 275
| IRQ5/DIO_00
| CN1-93
|-
| 276
| IRQ6/DIO_01
| CN1-91
|-
| 277
| IRQ7/DIO_02
| CN1-89
|}
{{:Userspace IRQ}}
{{:Userspace IRQ}}

Revision as of 22:23, 16 June 2013

The TS-4800 has several IRQs that can be used by external devices. See chapter 3 of the CPU manual for a complete listing of all of the available IRQs. We include a userspace IRQ patch in our kernels. This allows you to receive interrupts from your applications where you would normally have to write a kernel driver. This works by creating a file for each interrupt in '/proc/irq/<irqnum>/irq'. The new irq file allows you to block on a read on the file until an interrupt fires.

The original patch is documented here.

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.

#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;
}