LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Interrupt handling in C (https://www.linuxquestions.org/questions/programming-9/interrupt-handling-in-c-420023/)

vkmgeek 02-27-2006 07:40 AM

Interrupt handling in C
 
hi
I have a board in which ARM micro controller is there. There are also few switches. When one presses a switch, external interrupt is given to controller.
NOw i know the routine can be executed by changing code in IRQ. but that is done writing code in assembely. How do i do the same writing code in C?


Thnx in advance.

paulsm4 02-27-2006 11:55 AM

The answer depends entirely on your OS, and whether the vendor (or someone else) happened to provide a driver for that OS.

In DOS, for example, you could write your own ISR and call dos_setvect() on the device's IRQ. All in 'C' - no assembly needed.

In Windows or Linux, on the other hand, you'll need to have - or find - a device driver. Or write your own.

Please try this:
1. See if your vendor provides some kind of driver

2. Check out the open-source "comedi" library: they might have exactly what you're looking for:
http://www.comedi.org

3. These are two excellent books (both O'Reilly books) of interest to you:
Linux Device Drivers, 3rd Ed; Rubini et al
http://www.bookpool.com/sm/0596005903

Building Embedded Systems, Yaghmour
http://www.bookpool.com/sm/059600222X

4. If you're on Windows (win2k/XP/Vista) you'll want this one:
Programming the MS Windows Driver Model, Oney
http://www.bookpool.com/sm/0735618038

'Hope that helps .. PSM

vkmgeek 02-28-2006 12:38 AM

ya sorry
i should have mentioned about OS..
I will have embedded linux on my board..
I hope now u can help me better.

airswit 02-28-2006 01:07 AM

can you do inline assembly? depends on your tools, but i believe, at least with codewarrior, you can do something like:

asm
{
move.l #100,R0 ;or something like this
}

paulsm4 02-28-2006 01:42 AM

Hi -

The choice of "assembly" vs "C" isn't anywhere near as important under Linux as it used to be under DOS (or under non-Linux embedded systems). 99% of the code you'll need to write - even code that interacts more or less directly with the hardware, can (and usually should) be written in C.

The real issue (as you asked in a separate post) is to understand the "device driver" model: to understand why you can't (shouldn't) talk directly to the h/w, but instead follow the OS's rules, and let the OS "virtualize" the h/w for the benefit of the application.

All of the books I recommended do a fair job of this (although obviously the Windows book will probably be less than useful to you ;-)).

Here's a link that might also help:

http://www.networkcomputing.com/unix...0/010.txt.html


All times are GMT -5. The time now is 09:42 AM.