LinuxQuestions.org
Review your favorite Linux distribution.
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 07-15-2003, 03:15 AM   #1
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 30
Interrupt handling in gcc?


Good morning everyone.
From what I know, gcc does not support the keyword like "interrupt" or "_interrupt". The only way to handle the interrupt is to write a small assembler to "call" the interrupt routin. But how to integrate this small piece of assembler into the final file? (to generate executable file) Thank you very much
 
Old 07-15-2003, 04:41 AM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
im not quite sure what you want to do?

do you want to write an interupt handler then have the kernel call it when necessery in this case just write your handler then call request_irq

or do you want to generate an interupt, dont know why youd want to do this because no bios interupts are accessable and all the syscalls have wrappers but you would just do some inline assembly or write an assembly file and link it to your executable. theres lots of info about this if you look up operating system development.
 
Old 07-15-2003, 07:38 AM   #3
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
Sorry for the obscure words. I have written a small program to test the serial port under windows some time before. Now I want to migrate it to Linux. From my understanding, there are two ways to do it: 1. to use the POSIX programming interface. 2. to directly access to the register and handle the interrupt.

I have read the relevant document about serial port programming by POSIX. While there is no informaition there about using interrupt to handle the "read" problem. (otherwise you have to use polling to system delay, which I am using in POSIX). So I am thinking of control directly the serial port register under Linux as well as the interrupt. But soon I realized that gcc does not have the structure to handle interrupt. The only way is to write a small piece of assembler and call the interrupt routin from it.
My problem is I don't know whether I need to write the interrupt vector for serial port interrupt, and I have no idea how to integrate the assembler to C.
Do you any ideas or suggestions? I'll appreciate any of them
Thank you very much
 
Old 07-15-2003, 08:01 AM   #4
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Could you not simply open the serial port device and deal with it that way, instead of using interrupts? I mean, that's what the devices are for. (=
 
Old 07-15-2003, 08:20 AM   #5
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
Yeah. Actually, POSIX provides a reletive ready-to-use interface on the serial port(some knows POSIX on parallel?). It is user-frendly. I have built a small testing program around this and it works. However, as I posted earlier, there is no interrupt handling for the "reading" from the port, which usually is time-critical. It indeed utilizes a function "select", but you have to block the whole program before reading a byte, though there is timeout.
Under turbo C you could just "bind" the interrupt routin vector to the interrupt, using "interrupt" keyword, which is easiler. But gcc does not have this structure. That's what I am looking for.
Thank you.
 
Old 07-15-2003, 09:10 AM   #6
mad_ady
Member
 
Registered: Jan 2003
Location: I'm all in your mind!
Distribution: Debian
Posts: 248

Rep: Reputation: 30
IMHO, this is how you get asm code in C (if this is what you need):
Code:
void myFunction()
{
printf("Before asm\n");
asm{
xor ax, ax
}
printf("After asm");
}
However, I'm not sure it works! (never tried it!)
Question: Where can I find a list of the interrupts linux generates/uses? (something like a list of dos interrupts).
Thanks
 
Old 07-15-2003, 10:06 AM   #7
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
I can't remember clearly but I think it is in /proc/interrupts (or interrupt). I think you might want to have a try.

I'll try your method and post the result here.
 
Old 07-15-2003, 10:16 AM   #8
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
Oh, in that way, I'll have to build the interrupt vector myself. I did that 3 years ago. (and I remember that was a project using 8259) ooooooo
 
Old 07-15-2003, 11:20 AM   #9
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
Quote:
2. to directly access to the register and handle the interrupt
in the days of turbo C the operating system was dos which in fact is nothing more than a set of api calls, when you ran a program in dos control of the computer(and all hardware) was transferred to that program. this is NOT the case in linux. programs do not have direct access to hardware and must go through the kernel syscalls. i dont know if any of the ioctls provided by the serial driver are adequate for your need but if not you will have to write your own serial port driver(this is what i think you are referring to with interrupt vector) and then call free_irq/request_irq to bind your driver to to the serial port but this can only be done in kernel mode and will have to be implemented as a kernel module.
 
Old 07-15-2003, 11:50 AM   #10
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
captain:

I'm also remembering some dealings I had with select some time ago, and IIR, select also could be given a zero length, and it would return immediately if the item/device status has not changed. yep.. according to the man page:
Code:
 timeout  is  an  upper bound on the amount of time elapsed
 before select returns. It may be zero, causing  select  to
 return  immediately.
Instead of having select wait, your code could simply poll the serial port every second or two looking for data.

That is assuming your program will run somewhat like a daemon.
 
Old 07-16-2003, 02:43 AM   #11
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by TheLinuxDuck
That is assuming your program will run somewhat like a daemon. [/B]
Really. Even using read(2) could result a immediate return, if you set the open(2) parameters to "NDELAY". And indeed I am using this method, but not polling. I simply send a byte to the Zilog microcontroller via RS232 and it will return a string. So usleep(4000) and then read(2) will get everything.
Anyhow this is a rather simple protocol to implement. But I have done something under windows, using the "interrupt" keyword and I am wondering whether gcc is also capable of it.
 
Old 07-16-2003, 02:45 AM   #12
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
And also thank you kev82 I also realized a way to do this is to write the program in Kernel mode, for which I need to read something. Would you recommend some materials on the internet, including the "free_irq/request_irq" information? Many thanks.
 
Old 07-16-2003, 05:16 AM   #13
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
Quote:
But I have done something under windows, using the "interrupt" keyword and I am wondering whether gcc is also capable of it.
as i explained in my earlier post you can ONLY handle irq requests in kernel mode not a normal program. so its got nothing to with whether gcc or any other compiler supports it the fact is the kernel will not allow you to handle an irq in userspace.

for free_irq request_irq i suggest the man pages from section 9, for module programming the module programmers guide is somewhere in www.tldp.org and i guess you know enough about the serial port already but heres a good link for serial/parallel port programming. http://www.nondot.org/sabre/os/artic...cationDevices/
you could also have a look at the current serial driver in the kernel. i however recommend a userspace solution if its possible.
 
Old 07-16-2003, 05:57 AM   #14
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 30
Thanks again Dev82
 
  


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
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
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare Suse/Novell 3 11-29-2004 02:13 PM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM


All times are GMT -5. The time now is 08:30 AM.

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