Pumpkin, Inc.

Pumpkin User Forums

Stopping waiting tasks

If you can't make Salvo do what you want it to do, post it here.

Stopping waiting tasks

Postby JOwsley » Thu Dec 05, 2002 7:50 am

This question is not MSP430 specific, but happens to be the target I am working on.

I would like to have a task wait on a particular event for a considerable about of time (2 seconds in this case) for an external input. When the expected input happens, the wait is re-triggered. When the task times out, special handling happens. Additionally, another 'super-task' may halt this waiting task when some other condition is satified. The problem I have is stopping the waiting phase.

MyWaitingTask()
{
for( ; ; )
{
OS_WaitBinSem(MY_BINSEM_P, MY_TIMEOUT, MyTask1);

if(OSTimedOut())
{
handleTimeout();
}
}
}

Since OSStopTask(MyWatingTask) will mostly likely fail, one solution is to allow the timeout, and the handler looks whether this task should stop.

The other idea I have is to use event flags: one bit is the expected external event, another bit is the STOP_TASK. Thus,

for ( ; ; )
{
OS_WaitEFlag(MY_WAIT_FLAGS_P, MY_MASK, OSANY_BITS, OSNO_TIMEOUT, MyTask1);

eflag = OSReadEFlag(MY_WAIT_FLAGS);

if(eflag & STOP_TASK)
OS_Stop(MyTask2);
}

An outside task MUST be responsible (OSNO_TIMEOUT) for 'knowing' about the running task, then executes

MyOutsideTask()
{
// stop the waiting task
OSSetEFlag(MY_WAIT_FLAGS, STOP_TASK);
...
}

rather than the task itself (not very OOP). But it does effectively stop the task relatively quickly, without waiting the 2 seconds.

Anyone out there with a similar idea, or solution?

Jake Owsley, PE
JOwsley
 
Posts: 4
Joined: Thu Dec 05, 2002 12:00 am
Location: Louisville, CO, USA

Re: Stopping waiting tasks

Postby DHenry » Thu Dec 05, 2002 8:00 am

For what it's worth ($.02), I have used the event signalling method with Salvo as well as other kernels for the purpose you mention. One benefit to signalling a task to stop itself as I see it, is that the task can "clean itself up", if necessary, in a manner specific to the particular task and its current state.
DHenry
 
Posts: 18
Joined: Sat Aug 04, 2001 11:00 pm
Location: Boulder, CO, U.S.A.


Return to Coding

Who is online

Users browsing this forum: No registered users and 3 guests

cron