Page 1 of 1

cannot stop a task?

PostPosted: Mon Feb 27, 2006 10:34 am
by kamyip
I have the following tasks:
TaskBeep() - priority 6
TaskTest() - priority 10

Inside TaskTest I tried to stop TaskBeep() ie

TaskTest(){
for(; {
OSStopTask(TASK_BEEP_P);
OS_Delay(....)
..do something here
OSStartTask(TASK_BEEP_P);
}

I could not stop the TaskBeep() as I wanted.
Where did I go wrong?


Kam


Re: cannot stop a task?

PostPosted: Mon Feb 27, 2006 10:53 am
by aek
What did OSStopTask() return?

Only tasks in certain states can be stopped ...

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


Re: cannot stop a task?

PostPosted: Tue Feb 28, 2006 4:18 am
by kamyip
Ok, is it clear now. Thanks for the prompt response.

Kam :-)


Re: cannot stop a task?

PostPosted: Tue Feb 28, 2006 8:43 am
by aek
From the Reference for OSStopTask():
quote:
OSStopTask() can stop any task that is not already destroyed or waiting an event.
So it sounds like when you call OSStopTask(), TaskBeep() is waiting ...

Why is it hard (from an OS viewpoint) to stop waiting tasks? Well, because there's a lot of cleanup required, and it's somewhat ambiguous as to how that cleanup should be done. Many RTOSes do not allow you to stop or kill/destroy a task if it is (also) waiting an event.

In your case, it might be better to signal the task, and then have it react to the signaling to control the on/off of beeping. For example, you could signal the task with messages that are const chars -- 'B' might mean "start beeping" and 'Q' might mean "be quiet".

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


Re: cannot stop a task?

PostPosted: Tue Feb 28, 2006 12:57 pm
by kamyip
It returns 0x01 aka OSERR.

The beep task as follow:

code:
void TaskBeep( void ){   

Tris_Beep =0; //init pin to output
Bit_Beep =0; //buzzer drive set low
for (;;) {
OS_WaitBinSem(BINSEM_UPDATE_BEEP_P, OSNO_TIMEOUT, TaskBeep1);
Bit_Beep = 1;
OS_Delay(5, TaskBeep2);
Bit_Beep = 0;
}

}


Question: How do I know under what state that I can stop the task?

[This message has been edited by aek (edited February 28, 2006).]