LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Serial Programming - Multiple interruptions for serial devices on real-time Linux. (https://www.linuxquestions.org/questions/programming-9/serial-programming-multiple-interruptions-for-serial-devices-on-real-time-linux-804741/)

santiagocasti 04-28-2010 07:19 AM

Serial Programming - Multiple interruptions for serial devices on real-time Linux.
 
Hi,

I'm working on a C program in a real-time Linux (BlueCat) for processing information from two different serial devices, a GPS and an inertial. I know how to configure and get information from one device, I have code working on it.

My problem comes when I tried to add a second device, I mean, for getting information from one I just set an interruption for SIGIO signal. So, when new data arrives it just interrupts and collects data. But, I don't know how to add a second interruption for the second device, because the SIGIO signal will be triggered when ANY of the devices has data. The two options that I thought about are:

A) When SIGIO signal is triggered check wich of the devices has data and store it accordingly. But, that doesn't seem to be a good solution, because what will happen if BOTH devices send data nearly at the same time? The SIGIO will be triggered two times.
B) Setting different signals for each device. That sounds better, but I really don't know how to do it. I've been looking around but I couldn't find anything relevant.

If someone could just help me see wich is the best way of solving it. Or what could I read or wich keywords could help me find something.

Thanks in advance,

Sergei Steshenko 04-28-2010 07:39 AM

Quote:

Originally Posted by santiagocasti (Post 3950504)
Hi,

I'm working on a C program in a real-time Linux (BlueCat) for processing information from two different serial devices, a GPS and an inertial. I know how to configure and get information from one device, I have code working on it.

My problem comes when I tried to add a second device, I mean, for getting information from one I just set an interruption for SIGIO signal. So, when new data arrives it just interrupts and collects data. But, I don't know how to add a second interruption for the second device, because the SIGIO signal will be triggered when ANY of the devices has data. The two options that I thought about are:

A) When SIGIO signal is triggered check wich of the devices has data and store it accordingly. But, that doesn't seem to be a good solution, because what will happen if BOTH devices send data nearly at the same time? The SIGIO will be triggered two times.
B) Setting different signals for each device. That sounds better, but I really don't know how to do it. I've been looking around but I couldn't find anything relevant.

If someone could just help me see wich is the best way of solving it. Or what could I read or wich keywords could help me find something.

Thanks in advance,


And what is the problem with item in bold ?

santiagocasti 04-28-2010 08:19 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3950532)
And what is the problem with item in bold ?

Well, the problem with SIGIO being triggered two times is that the system is checking more than necessary. Because when the signal of new data available is triggered, the programm will check both serial interfaces, and as a consequence waste of processing time.
The software is supposed to be as efficient as posible, so that's why it doesn't look like a good solution. If there is no other solution, well, but if there is any other more efficient I will implement it.

Thanks for you reply!

Sergei Steshenko 04-28-2010 08:27 AM

Quote:

Originally Posted by santiagocasti (Post 3950571)
Well, the problem with SIGIO being triggered two times is that the system is checking more than necessary. Because when the signal of new data available is triggered, the programm will check both serial interfaces, and as a consequence waste of processing time.
The software is supposed to be as efficient as posible, so that's why it doesn't look like a good solution. If there is no other solution, well, but if there is any other more efficient I will implement it.

Thanks for you reply!

How much resources are needed to check that new data is indeed available ? I.e. what exactly indicates new data is available in the device ?

theNbomr 04-28-2010 04:28 PM

Have you considered the use of select() and its kin to read from multiple asynchronous sources? As I understand it, this would be one of the standard approaches to solving such problems, although I'm not sure what constraints are imposed by your real-time requirements.
--- rod.

santiagocasti 05-06-2010 04:34 AM

Thank you for the replies. The best way of solving it is allowing SIGIO interruptions from the serial ports of the devices (in my case, 2 serial devices, but there could be more). So, once a device triggers the signal, we check in wich of the devices there is new data.

In this website there is a good explanation about how to do it. It's not difficult at all and works perfectly.

Thank you very much for the replies.


All times are GMT -5. The time now is 04:01 AM.