LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-28-2010, 08:19 AM   #1
santiagocasti
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: Disabled
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,
 
Old 04-28-2010, 08:39 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by santiagocasti View Post
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 ?
 
Old 04-28-2010, 09:19 AM   #3
santiagocasti
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Sergei Steshenko View Post
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!
 
Old 04-28-2010, 09:27 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by santiagocasti View Post
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 ?
 
Old 04-28-2010, 05:28 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 05-06-2010, 05:34 AM   #6
santiagocasti
LQ Newbie
 
Registered: Apr 2010
Posts: 3

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


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
Programming serial ports on Linux cgabs8 Programming 3 09-24-2008 03:49 AM
Real-time close loop control needs serial port communication areftaidi Linux - Software 6 01-25-2006 07:30 PM
programming to 'real' serial port in C++ microsoft/linux Programming 3 03-15-2005 09:12 AM


All times are GMT -5. The time now is 07:58 AM.

Main Menu
Advertisement
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