This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX51 full: os_wait() returns too early

Hello!

Assuming an OS timer tick interval of 5ms, os_wait() returns exactly after 5ms with the code as follows:

while (1) {
    os_wait(K_TMO, 1, 0);
}

However, with the code like that:

while (1) {
    os_wait(K_SIG, 255, 0);
    os_wait(K_TMO, 1, 0);
}

the second call to os_wait returns after something beetween 0 and 5ms.

I have read somewhere that os_wait(K_TMO, 1, 0) only waits until the next timer tick but why only in the second case?

Regards,
Markus

  • If you are going to wait one tick, then the problem is how much time is left until that tick. If you are going to wait 20 ticks, then you may get 19+eps .. 20 ticks which isn't as noticeable as when you wait for just one tick.

    You have a similar problem with normal timer interrupts. If you set the timer to produce one intrrupt every 1ms and ask your code to wait for one second (one interrupt) then you may get a zero delay.

    Your first example does not consume any time, so there will always be a full tick period. Your second example consume an unknown amount of time.

  • Per,
    You wrote
    ...ask your code to wait for one second (one interrupt)...

    I suppose you meant "for one millisecond", or did I get it totally wrong...?

  • Yes, I meant one ms. If the timer isn't synchronized, a one ms delay may end immediately just as well as after one ms.

    Many OS runs their system clock at a higher resolution than the task time-slice frequency, so that a thread that forces a task switch after 95% of the slice time will not result in the following task only getting the remaining 5% of the task slice.

  • but why only in the second case?

    Oh, but it does that in the first case, too! You just can't tell the difference without any influence to make the time you start that os_wait() different from "immediately after a tick".