ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
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.
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
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.
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.
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:
timeout is an upper bound on the amount of time elapsed
before select returns. It may be zero, causing select to
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.
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.
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.
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.