LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-27-2006, 07:40 AM   #1
vkmgeek
Member
 
Registered: Feb 2006
Location: Ahmedabad
Distribution: rhel5
Posts: 185
Blog Entries: 2

Rep: Reputation: 31
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.
 
Old 02-27-2006, 11:55 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 02-28-2006, 12:38 AM   #3
vkmgeek
Member
 
Registered: Feb 2006
Location: Ahmedabad
Distribution: rhel5
Posts: 185
Blog Entries: 2

Original Poster
Rep: Reputation: 31
ya sorry
i should have mentioned about OS..
I will have embedded linux on my board..
I hope now u can help me better.
 
Old 02-28-2006, 01:07 AM   #4
airswit
Member
 
Registered: Dec 2005
Distribution: Fedora 4
Posts: 89

Rep: Reputation: 15
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
}
 
Old 02-28-2006, 01:42 AM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 02-28-2006 at 01:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception Handling vipinsharma Programming 2 09-25-2005 11:05 AM
interrupt handling mp4-10 Programming 5 02-14-2005 06:13 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
Interrupt handling in gcc? captainstorm Programming 13 07-16-2003 05:57 AM
handling devices sajanjohn Linux - General 1 04-20-2002 02:18 PM


All times are GMT -5. The time now is 07:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration