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.

CC1310: cc1310 exit from Sleep on pin interrupt

Part Number: CC1310
Other Parts Discussed in Thread: SYSBIOS

Hello,

I want to sleep and wake up from delay or button pin interrupt. I start the firmware from Simplelink SDK Pin interrupt example NoRTOS.

The test firmware works like this : The Red LED toggle every 5 Seconds and the Blue LED toggle when I press the button. 

But I expect the button interrupt to exit the MCU from the sleep function and works like this :

The Red LED toggle every 5 Seconds, the Blue LED toggle when I press the button then exit from sleep function, then toggle the Red LED and finally enter in the sleep(5) function.

At the end I want to replace the Red LED toggle by RxRf_300ms and The Blue LED Toggle by TxRf if fButtonInterrupt = 1

{

    initButtonsInterrupt();
    
    while(1)
    {
        sleep(5);
        RedLedToggle();
    }

}

void initButtonsInterrupt(void)
{
    /* Setup callback for button pins */
    if (PIN_registerIntCb(pinHandle, &buttonCb) != 0) {
        /* Error registering button callback function */
        while(1);
    }
}

void buttonCb(PIN_Handle handle, PIN_Id pinId)
{
    BlueLedToggle();
    fButtonInterrupt = 1 ;
}

  • Hi Martin,

    I think you would need to elaborate on both the code and use-case here. it sounds to me that what you look for it the functionality of the example but where you also trigger an event to do something else on the button press?

  • Hello M-W,

    in my past experience, when the MCU wake from the sleep it continue from where is sleep and execute the following instruction in the firmware.   Normally, I use callback interrupt function to raise a flag then execute the function  from the main loop, I do not put too much code/instruction in the call back function.

    In this case, the callback is execute but the sleep function did not return to the main loop, so the code inside the main loop is not executed when the PIN interrupt is triggered.  Perhaps the main loop instruction are executed after the 5 second sleep timeout.

    So it looks like the sleep() api function return only, to the main loop, when the timeout is past due and not from external interrupt.

    hope I provide you better explanation of my problem.

    main() // this is what I want to do.
    {
        initButtonsInterrupt();
        
        while(1)
        {
            fButtonInterrupt = 0 ;
            sleep(5);
            if(fButtonInterrupt)
                transmitData();  // transmit data if wake from the button press
            else
                receivedData300msTimeout(); // else receive data for 300ms, then go back to sleep for 5 seconds
                
            //RedLedToggle();
        }

    }


    void buttonCb(PIN_Handle handle, PIN_Id pinId)
    {
        //BlueLedToggle();
        fButtonInterrupt = 1 ;
    }

    regards,

    Martin



  • HI Martin,

    I think you need to keep in mind that you are working in an RTOS environment here. If your "mian code", in this case your application task, is performing a blocking operation for a given time, then the task will remained block even if the device wakes up to serve an interrupt.

    When all user tasks are blocked in TI-RTOS (in other words, when there is nothing to do), the Idle task is running which is the task that actually puts you into low-power mode. Thus when the callback ends, you will in this case return to this Idle task (as the RTOS do not see any need to run the main thread as you told it to sleep for 5 seconds) and put the device back into low-power mode.

    To trigger a wake-up of a task from a callback I would recommend you use for example a semaphore that your task can pend on. When you post it from the callback, this would make the task "unblocked" and allow the RTOS to resume the task again.

  • Thanks for clarification, I will look at it.

    Does it works the same, even if I'm running the noRTOS version of the SDK ?

    Martin

  • Hi Martin,

    More or less, but in NoRTOS you of course do not have the RTOS which means it would function more like you expected it to. In the NoRTOS case however, you are typically responsible for invoking the power policy yourself (as you would return from it when waking to serve and ISR).

  • Ok,

    So what function instead of sleep() should I call to get the PINinterrupt continues in the main tread ?

    Or should the sleep supposed to work as I want and did not configure the MCU correctly?

  • Hi Martin, 

    You are not doing any miss configuration, you would just need to use features such as semaphores to do what you want, I suggest you have a look on for example the sysbios/mutex example to see how semaphore can be used to block tasks until you signal it from for example a ISR.

  • Thanks for your reply,

    Can you confirm that the sleep did not return to the main loop when the PIN interrupt is triggered,  when use noRTOS ?

    And the solution is to use the semaphore and the RTOS.

    regards,

    Martin

     

     

  • Hi Martin,

    Sleep will only return once the sleep expires, not when the interrupt is triggered. The sleep will be woken internally, but go back into low-power mode until it is time to exit.

    Semaphores can be used to pend for a given time (timeout) or until you post the semaphore.