Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Periodic task

1,055 views
Skip to first unread message

muk...@my-deja.com

unread,
Jul 7, 2000, 3:00:00 AM7/7/00
to
Hi,
I am writing an application on VxWorks platform.
I want to know how to create a task that periodically
wakes up and does it's job and goes to sleep after that.
For example:

I need a task that wakes up at every 1/20th of a second
and does its work.
Is there any option in taskSpawn() or any there is different
mechanism to acheive this functionality in VxWorks.


Thanks

Mukesh

Sent via Deja.com http://www.deja.com/
Before you buy.

johan.b...@peektraffic.nl

unread,
Jul 7, 2000, 3:00:00 AM7/7/00
to
muk...@my-deja.com wrote:
: I need a task that wakes up at every 1/20th of a second

: and does its work.
: Is there any option in taskSpawn() or any there is different
: mechanism to acheive this functionality in VxWorks.

Use taskDelay for this. See the manuals for a description.

Groeten,
Johan

--
o o o o o o o . . . ___________________________________
o _____ || Johan Borkhuis |
.][__n_n_|DD[ ====_____ | jo...@borksoft.xs4all.nl |
>(________|__|_[_________]_|________________________________|
_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
=== VxWorks page: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ===

Ranga Mc Donald

unread,
Jul 7, 2000, 3:00:00 AM7/7/00
to
I've not come across with any of in-built options provided by the Tornado in
the taskSpawn options. But you could do it effectively with the software.Say
write some loops or arrange some timers....etc.,
Good Luck
McDonalds


<muk...@my-deja.com> wrote in message news:8k4cnn$fjs$1...@nnrp1.deja.com...


> Hi,
> I am writing an application on VxWorks platform.
> I want to know how to create a task that periodically
> wakes up and does it's job and goes to sleep after that.
> For example:
>

> I need a task that wakes up at every 1/20th of a second
> and does its work.
> Is there any option in taskSpawn() or any there is different
> mechanism to acheive this functionality in VxWorks.
>
>

Darlia Williams

unread,
Jul 7, 2000, 3:00:00 AM7/7/00
to
Try using a watchdog timer and a semaphore. Create a function that just
gives a semaphore. Your main task can start a watchdog timer with that
function (supplying the semaphore as the parameter), set to go off in
1/20th of a second (sysClkRateGet()/20). Your main task can then pend
on taking the semaphore. Once the semaphore is taken, the main task can
restart the watchdog timer and then do its work and pend on the
semaphore again.

Good luck,

Darlia

Bruce

unread,
Jul 8, 2000, 3:00:00 AM7/8/00
to
In comp.os.vxworks
muk...@my-deja.com wrote:

>Hi,
> I am writing an application on VxWorks platform.
> I want to know how to create a task that periodically
> wakes up and does it's job and goes to sleep after that.
> For example:
>
> I need a task that wakes up at every 1/20th of a second
> and does its work.
> Is there any option in taskSpawn() or any there is different
> mechanism to acheive this functionality in VxWorks.

void MyTask(void)
{
while(1)
{
DoSomething();
taskDelay(sysClkRateGet()/20); // Delay 20th of second
}
}

Another poster mentioned using a watchdog timer and a sema4. That is also
a good way if you NEED your task to run on the period because it will be
executed at interrupt level. This task will still run based on its
priority.

Bruce


Paul Whicker

unread,
Jul 8, 2000, 3:00:00 AM7/8/00
to
This will roughly work. The method with watchdogs also works most of the time.
If timing is critical then both of these approaches can suffer from drift and
even missed events. If the system clock is fast in the following example then
it may slip a tick now and then. The watchdog method also relies on getting
processing time in task level to allow the watchdog to be reset. The clock
tick may also not be suitable for achieving your timing accurately, there are
methods to deal with this too (basically you keep a list of delay times that
averages out or you work out the nearest number of ticks each time).

Try this:-

SEM_ID taskReleaseSem;

void myTimedFunc(void)
{
semGive(taskReleaseSem);
}

void myTaskFunc(int tickParameter) // The clock tick passes a constant
{
for(;;) // Pick your favorite forever method
{
// Wait for the semaphore to be given
semTake(taskReleaseSem);
// Your periodic stuff
}
}

void initTimedFunc(void)
{
// Create a semaphore to release the timed task
taskReleaseSem = semBCreate(SEM_Q_PRIORITY,SEM_EMPTY);

// Set the aux xloxk to the desired rate
sysAuxClkRateSet(20);

// Spawn the task that does the work
taskSpawn(
"timed", /* name of new task (stored at pStackBase) */
100, /* priority of new task */
0, /* task option word */
4096, /* size (bytes) of stack needed plus name */
myTaskFunc, /* entry point of new task */
0, /* 1st of 10 req'd task args to pass to func */
0, 0, 0, 0, 0, 0, 0, 0, 0
)

// Now connect the timer function to the aux clock
sysAuxClkConnect(myTimedFunc,0);
// And switch it on
sysAuxClkEnable();
}

Now when the aux clock interrupt goes off the task is released, the timer is
free running so you don't depend on the sysClk rate or getting some time at
task level (not sure that's a fair criticism of the WD method but it is tied
to the sysClkRate, this is not).

HTH,
Paul


taskSpawn options are:-

VX_FP_TASK (0x0008)
execute with floating-point coprocessor support.

VX_PRIVATE_ENV (0x0080)
include private environment support (see envLib).

VX_NO_STACK_FILL (0x0100)
do not fill the stack for use by checkStack( ).

VX_UNBREAKABLE (0x0002)
do not allow breakpoint debugging.


In article <39668b38...@news.swbell.net>, snap...@southwesternbell.net

Pete Kockritz

unread,
Jul 10, 2000, 3:00:00 AM7/10/00
to
In article <aHC95.33093$i5.3...@news1.frmt1.sfba.home.com>,
pwhi...@home.com (Paul Whicker) wrote:

> // Now connect the timer function to the aux clock
> sysAuxClkConnect(myTimedFunc,0);


Why not eliminate the extra function call overhead:

sysAuxClkConnect(semGive, taskReleaseSem);


--
Regards,
Pete Kockritz

The views expressed are my own and not necessarily that of my employer's

Paul Whicker

unread,
Jul 11, 2000, 3:00:00 AM7/11/00
to
Yes, absolutely. I was minimising from a general timer implementation where I
keep a number of counters and release several tasks. Your way is better.

Paul

In article <8kckfa$klk$1...@nnrp1.deja.com>, Pete Kockritz <pet...@my-deja.com>
wrote:

djhy...@msn.com

unread,
Jul 17, 2000, 3:00:00 AM7/17/00
to
> In comp.os.vxworks
> muk...@my-deja.com wrote:
>
> >Hi,
> > I am writing an application on VxWorks platform.
> > I want to know how to create a task that periodically
> > wakes up and does it's job and goes to sleep after that.
> > For example:
> >
> > I need a task that wakes up at every 1/20th of a second
> > and does its work.
> > Is there any option in taskSpawn() or any there is different
> > mechanism to acheive this functionality in VxWorks.
>
> void MyTask(void)
> {
> while(1)
> {
> DoSomething();
> taskDelay(sysClkRateGet()/20); // Delay 20th of second
> }
> }
>
> Another poster mentioned using a watchdog timer and a sema4. That is
also
> a good way if you NEED your task to run on the period because it will
be
> executed at interrupt level. This task will still run based on its
> priority.
>
> Bruce
>
>
Your statement is incorrect. A semaphore does not somehow allow a task
to run at interrupt level. All it can do is prevent a task from
running. To get the task to run promptly as soon as the semaphore is
given, you must set up you task priorities accordingly.

Also, your code does not run a task at a periodic interval. It runs a
task with a minimum delay in it of some interval. If you used two
mechanisms, a watchdog with a semaphore and a task delay, and compared
them, you would see the task delay code slowly slipping behind the
watchdog. This could be significant if the time synchronization is
important over long periods.

For really fine control of the semaphore, you may want to write the
semGive code as an interrupt handler and attach it to a real hardware
clock.

Good Luck

Bruce

unread,
Jul 17, 2000, 3:00:00 AM7/17/00
to
djhy...@msn.com wrote:
>> Another poster mentioned using a watchdog timer and a sema4.
>> That is also a good way if you NEED your task to run on the
>> period because it will be executed at interrupt level. This
>> task will still run based on its priority.

>Your statement is incorrect. A semaphore does not somehow


> allow a task to run at interrupt level. All it can do is
> prevent a task from running.

I may have not been clear enough in my sentence. When a
watchdog expires, the callback function is executed at interrupt
level. Therefore, it can give a sema4 at interrupt level. As
my last sentence states, the receiving task will still run based
on its priority.

>To get the task to run promptly as soon as the semaphore is


>given, you must set up you task priorities accordingly.

Agreed.

> Also, your code does not run a task at a periodic interval. It
> runs a task with a minimum delay in it of some interval. If
> you used two mechanisms, a watchdog with a semaphore and a
> task delay, and compared them, you would see the task delay
> code slowly slipping behind the watchdog. This could be
> significant if the time synchronization is important over long
> periods.

Agreed. I don't know his requirements.

> For really fine control of the semaphore, you may want to
> write the semGive code as an interrupt handler and attach it
> to a real hardware clock.

This is no different functionally than using the watchdog timer
to give the sema4, unless the resolution requirements are
greater than provided by the system timer tic.

Bruce

-----------------------------------------------------------

Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com


0 new messages