Page 1 of 1

OSTimeSly parameter

Posted: Mon Jan 30, 2012 8:58 am
by waguila
Hello all,

Something I cant understand when using the OSTimeDly, my issue is if I pass the value 0 ticks, the thread will go from the running state to a ready state (where in my understanding is OSTimeDly(0), will make the thread to sleep for 0 tick).

Can someone explain to me when I am not understanding right.

Thank you in advance

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 9:19 am
by seulater
(where in my understanding is OSTimeDly(0), will make the thread to sleep for 0 tick
you cannot sleep for 0 ticks. minimum is 1.

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 9:26 am
by waguila
Yeah I found that in the documentation, but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.

this is what happened when i slept to 0 ticks , the thread changed the state to ready. is this what it says in the doc cuz i could not find such a thing.

Thanks

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 9:32 am
by seulater
but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.
If you need to sleep for 0 ticks, it sounds like you might want to consider changing you code to perform the same task but in a different way to avoid this.

Maybe if you explain what you are doing, we can help you get around this.

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 9:37 am
by waguila
seulater wrote:
but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.
If you need to sleep for 0 ticks, it sounds like you might want to consider changing you code to perform the same task but in a different way to avoid this.

Maybe if you explain what you are doing, we can help you get around this.

I was just trying to understand why this happens when i sleep for 0 ticks, thanks for your help.

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 9:40 am
by seulater
I was just trying to understand why this happens when i sleep for 0 ticks, thanks for your help.
Maybe someone else can explain it. But be aware to use OSTimeDly(0) is not recommended.

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 10:03 am
by pbreed
In all the other OS calls, semaphore, fifo, mbox etc... 0 is the flag to wait forever.....

So OSTimeDly(0); is wait forever.....

The time tick timeouts for all RTOS waits are all handled with exactly the same code....
If the timeout value is 0, do nothing, if it decrements from 1 to 0 then wake the task.....

Actual code that does this is in nburn\system\ucos.c in Function

OSTimeTick()
.
.
.
if ( ptcb->OSTCBDly != 0 )
{
if ( --ptcb->OSTCBDly == 0 )
{
/* then release the task control block... */
}
}

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 10:10 am
by Chris Ruff
Paul

so does OSTimeDly(0) do:

1. release the task immediately (context release)
2. absolutely nothing
or
3. lock up the task forever

?

Chris

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 10:32 am
by pbreed
OSTimeDly(0)

->>>> lock up the task forever

Now if you call

void OSChangeTaskDly( WORD task_prio, WORD newticks );

You can wake it up again....

So if you need a pool of worker tasks one might do that, but semaphore is probably cleaner...

Re: OSTimeSly parameter

Posted: Mon Jan 30, 2012 12:53 pm
by waguila
thank you guys i really understand it better now :) . thanks again