This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Sleep in microseconds in SYSBIOS

Other Parts Discussed in Thread: SYSBIOS

Hi all,

Currently in my application, I am using Task_sleep() which does sleep in milliseconds on BIOS? But I need to use the sleep on microsecs scale. Is it possible? Can someone help?

Like in Linux, where we have functions like sleep(), usleep() and nanosleep() to faciliate sleep functionality in secs, millisecs and microsecs are there analogous functions in SYSBIOS? 

Thanking you in advance.

Regards,

Mahi

  • By default, the Task_sleep timing mechanism is based on the Clock module. The default granularity of the kernel's Clock tick is 1 ms (1000 microseconds). So unless you change the Clock tick, you only get millisecond granularity on Task_sleep.

    To change the Clock tick period, in your .cfg file, set it as needed.

    var Clock = xdc.useModule('ti.sysbios.knl.Clock');

    Clock.tickPeriod = 750;  //750 microseconds

    The downside is that a timer interrupt will be running every 750 microseconds now.

    If you are needing microsecond granularity infrequently and are somewhat CPIU bound, I'd recommend using a dedicated timer in a one-shot mode. Start the timer and have the task block on a semaphore. When the timer runs, have it post the semaphore.

    Please note, SYS/BIOS allows you to not have a dedicated timer be used for the tick. The application can drive it also (by calling Clock_tick at the desired rate).

    Todd

  • Hi Todd,

    Thanks for your quick response.

    I want to use sleep in microseconds for a task which runs frequently is time bound on CPU. Is there a way out for this without changing the existing clock period. You were suggesting application driving a clock. How can I do that? Is it possible to use two clocks on bios 1) the default 2) the other based on the user need for some specific tasks.  

    Regards,

    Mahi

  • You can leave the Clock period as is and simply create a Timer on the desired interval. Have the Task block on a semaphore that you've created (instead of calling Task_sleep). Have the Timer function call Semaphore_post on the same semaphore.

    You can create the Timer to be a one-shot or periodic. It really depends on how you want to structure your program. For example with a one-shot you would do this in your task. The timer function calls Semaphore_post(semHandle).

    Task()
    {
        Timer_create()

        while(1) {
            //do application stuff
            //Start one-shot timer
            Semaphore_pend(semHandle, BIOS_WAIT_FORERVER);
        }
     


    Todd