Paolo Mantegazza wrote:
> 
> Richard Teltz wrote:
> 
> > On Thu, 22 Oct 1998, Tommy Thorn wrote:
> >
> > > Hi all,
> > >
> > > while looking for a solution to controlling a servo directly under
> > > Linux, I came across RT Linux.  While at first I thought it looked
> > > ideal, I was truly surprised to discover that there seems to be no
> > > wait to let threads sleep for an arbitrary period, as opposed to a
> > > fixed like with the make_periodic call.
> 
> > An easy way to do this is with semaphores.  Have a periodic task
> > keep time and release semaphores to the waiting task.  Have the
> > target task wait on the semaphore to sleep.  A simple API can set
> > wake up times, etc.  The overhead for the semaphores is usually very
> > low.
> 
> Too many task switches for nothing. A lot of jitter can be added and
> that's not good for the PWMing Tommy wants to implement.

For this I'd use two tasks.  One is a very simple "state machine" that
runs at say, 8Khz and is hung off the timmer chip interrupt.  The
task simply checks the state on entry and sets the state on exit.  States
are "line high" and "line low" when in "low" it decrements "low_counter",
if zero we set state to high. and load a value into "high_counter".

task two waits on a FIFO and accepts commands to change the constants
use by task one.  

Nither of these takes much CPU time nor much code to write it is also
stable as there is not much jitter inthe 8Khz interrupts.  If you had
10 servooes to drive then you would put 10 state and count variables
in task 1. and add "servo number" to the command string sent to task two.

Now you can control a handfull of seroes simply by doing "fputs" to /dev/rtfifo
Or you could even try echo -n "3 80" > /dev/rtfifo if you made task two
accept ASCII commands. 


> 
> > There is a semaphore module for RTL at the following URL:
> >
> > http://stereotaxis.wustl.edu/~jerry/
> 
> It is in the official RTL distribution now.
> 
> I suggest that the friends at NMT include the following, untested, in
> rtl_sched.c
> 
> void  rt_task_sleep_until(RTIME time)
> {
>   int flags;
>   r_save_flags(flags);
>   r_cli();
>   rtl_current->state = RT_TASK_DELAYED;
>   rtl_current->resume_time = time;
>   rt_schedule();
>   r_restore_flags(flags);
> }
> 
> void  rt_task_sleep(RTIME delay)
> {
>   int flags;
>   r_save_flags(flags);
>   r_cli();
>   rtl_current->state = RT_TASK_DELAYED;
>   rtl_current->resume_time = rt_get_time() + delay;
>   rt_schedule();
>   r_restore_flags(flags);
> }
> 
> That should work immediately as it does just what is already done for
> waiting for a period.
> 
> 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/

-- 
--Chris Albertson

  [EMAIL PROTECTED]                Voice:  626-351-0089  X127
  Logicon RDA, Pasadena California          Fax:  626-351-0699
--- [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