Ralf Ramrath wrote:
> 
> Hi folks,
> 
> I have the following problem:
> 
> I have a "main thread" that has to read data from the serial port only if
> any data is available. On the other hand, the thread must not wait longer
> than let's say one second.
> 
> The one thing ( reading only if data is available ) I implemented using a
> mutex variable between the main thread and the isr from the corresponding
> COM-Port. That works fine.
> 
> The timer, I implemented as follows:
> When the thread starts, it makes himself periodic. For the period I
> intentionally used one second. After the thread is periodic, I suspend the
> thread until the next period. After the thread is waked up by the
> scheduler, I know, that one second has past and I unlock my main thread,
> if it is still blocked.
> The problem is, that the system hangs, when I load my module into the
> kernel.
> 
> Has anybody an idea howto implement a timer ( or whether there are
> predefined functions ) that can be used in conjunction with mutex
> variables ?
> 

There are many solutions, including the cond_timedwait suggested by
Stuart and Victor, and the Pierre's proxy scheme. RTAI-24.1.2 uses real
time timers, both from user and kernel space, to solve your problem.

However the simpler way, and the one I often use in RTAI to do what you
want, is to use a sem_wait_timed with a time out of one second in my
task and a sem signal from the COM-port isr.

The time out on the semaphore makes the calling task periodic. From the
value returned by the timed sem call you can know if it was timed out or
not. 

However your solution is also OK. Did I get it right if I think that you
are just signalling-posting a binary semaphore from two different
sources? If so it must work, the first that happens must resume your
task.

Ciao, Paolo.
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to