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.
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 ===
<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.
>
>
Good luck,
Darlia
>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
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
> // 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
In article <8kckfa$klk$1...@nnrp1.deja.com>, Pete Kockritz <pet...@my-deja.com>
wrote:
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
>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