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.

RTOS: How to wake-up a sleeping task

Tool/software: TI-RTOS

Hi guys.

I have a task that does some stuff and then goes to sleep for some time

// by default is set to 30'
int32_t  timeInterv = 1800000;


void Task1( void *pvParameters ){
.
.
.
  while(1){
    .
    .
    .
    // goes to sleep
    osi_Sleep(timeInterv);
  }
}

The other task is running and may alter the "timeInterv" variable.

void Task2( void *pvParameters ){
.
.
.
  while(1){
    .
    if(...){
timeInterv = 60000;
} . // goes to sleep for 5ms osi_Sleep(5); } }

The problem is that Task1 is sleeping and will update "timeInterv" only when it wakes-up after the first 30'.

I want it to wake-up and refresh the sleeping time when it is updated.

I also thought about killing the task and create it again, so the sleeping time would be the new one...any suggestions?

Thanks in advance.

  • Hi Rui,

    What RTOS are you using underneath OSI: TI-RTOS or FreeRTOS?

    Instead of osi_sleep, you could sleep on a Semphore with timeInterv. If timeInterv is never updated, the semaphore would timeout. If you update timeInterv, you could immediately post the semaphore and have the blocked task handle the updated timeInterv accordingly. This would be valid for either RTOS.

    Todd
  • Hi Todd,

    I'm using TI-RTOS.

    Can you point me some example code so I can start adapting to my problem.

    Thanks for your reply.

    Rui
  • Hi Rui,

    I have not really used the osi wrapper, so I'll just give the pseudo-code in native TI-RTOS.

    // by default is set to 30'

    volatile int32_t  timeInterv = 30000; // assuming the Clock module's tick is 1ms (which is the default)

    Semphore_Handle sleepingSem;

    void Task1( void *pvParameters ){

    ...

     while(1){

       .   .   .

       // goes to sleep or until a new timeInterv is set.

       rc = Semaphore_pend(sleepingSem, timeInterv);

       if (rc == FALSE) { timeout...just go back to the top }

       else { someone updated timeInterv...call pend with the new value? }

     }

     

    void Task2( void *pvParameters ){

    ...

        timeInterv = NEW_VALUE;

        Semaphore_post(sleepingSem);

     

    You can create the semaphore multiple ways. This page talks about the pros/cons of each way: 

    Todd

  • Hi Todd,

    I'm using IAR Embeded Workbench for ARM to compile the code, but I get this error:

    Fatal Error[Pe035]: #error directive: xdc_target_types__ must be defined to name a target-specific header containing definitions of xdc_Int8, xdc_Int16, ...

    Can you help me solving this issue?

    Thanks for your answer.

    Rui

  • Rui.

    Were you able to get any of the TI-RTOS out of the box examples to build?

    Todd

  • Yes Todd, I did.

    I'm using "getting_started_with_wlan_station" and it was compiling perfectly before I tried to use the" semaphores".
    Previously I also compiled successfuly "httpserver" and "provisioning_ap".

    Thanks.
    Rui
  • I'd just stick with the osi calls then instead of the TI-RTOS native calls. So use osi_SyncObjCreate, osi_SyncObjSignal (or osi_SyncObjSignalFromISR) and osi_SyncObjWait instead of Semaphore_create, Semaphore_post and Semaphore_pend.

    Todd