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

RL-RTX - use of os_tmr_create, kill & call

Could some kind person give me a code snippet showing a typical use of os_tmr_create, _kill and _call.

I can't get my head around as to how these should be used and what they can be used for. I have them sort of working but seem to get multiple instances of timers which seems wrong. Right now I just want to be able to periodically run a function, and os_tmr looks like what I should be using.

As a more general are there any larger code examples of using the RTX, I mean more complex than the Keil examples, ie. perhaps a teaching book or something. To help me move forward with more confidence.

  • No code snippet but some of the gotcha's the way the os_timers are implemented.

    1) You may not call os_tmr_create in the "callback" routine of a timer. This will manipulate the timer_queue in the middle of manipulating the timer queue.

    2) Timer_ID's are reused almost immediately if you are killing and creating (or timers timing out). If you ever use os_tmr_kill you must be sure that the timer did not time out on its own before you call kill. If this is the case you may delete a newly created timer.

  • Thanks for the guideline, I was guilty of your gotcha #1).

    It seems it's not possible to use os_tmr_create inside a __task's while(1) { ..etc.. }. I tried testing for tmr1 == NULL before using os_tmr_create too, but that doesn't work. Perhaps I need to use a semaphore?

    I did try putting the os_tmr_create in the os_tmr_call function (to restart a timer when it timed out). This seems to work, but there is a note. That seems to indicate that I cannot do it this way.

    quote
    You can call any of the isr_ system functions from the os_tmr_call function, but you cannot call any of the os_ system functions.
    unquote

    I would really appreciate a code fragment as guidance.