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/CC2640R2F: How to make the timer ISR work?

Part Number: CC2640R2F

Tool/software: TI-RTOS

Hi greetings! I tried the following code and made it work (no more crashes). However, it seems that the callback function TimerISR() was never called. Which part am I missing? Any hints? Thanks in advance. 

//Timer ISR
void TimerISR(UArg a0)
{
    //clear interrupt flag
    TimerIntClear(GPT1_BASE, TIMER_TIMB_TIMEOUT);
    // Allow STANDBY mode again
    //Power_releaseConstraint(Power_SB_DISALLOW); 
}
  //timer init function
void TimerInit(uint32_t usec)
{
    PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
    PRCMLoadSet();
    PRCMPeripheralRunEnable(PRCM_PERIPH_TIMER1);
    PRCMLoadSet();

    Hwi_Params hwiParams;
    Hwi_Params_init(&hwiParams);
    hwiParams.enableInt = true;
    //construct an HWI
    Hwi_construct(&hwi, INT_TIMER1B, TimerISR, &hwiParams, NULL);

    unsigned long TIMER_LOADSET = 48 * usec - 1;
    
    // Disallow STANDBY mode while using the timer.
    Power_setConstraint(Power_SB_DISALLOW);
    // set Timer-A as periodic count mode
    TimerConfigure(GPT1_BASE, TIMER_CFG_B_PERIODIC);
    // set the load value of timer
    TimerLoadSet(GPT1_BASE, TIMER_B, TIMER_LOADSET);
    // Enable interrupt
    TimerIntEnable(GPT1_BASE, TIMER_TIMB_TIMEOUT); 
    // Enable timer
    TimerEnable(GPT1_BASE, TIMER_B);
}

  • Hi young,

    How are you determining that the ISR is not called? Can you try toggling a GPIO in the ISR?
  • Thanks Rachel.

    I put a line in the callback function TimerISR() but didn't see anything.

    void TimerISR(UArg a0)
    {
        //clear interrupt flag
        TimerIntClear(GPT1_BASE, TIMER_TIMB_TIMEOUT);
        // count on OLED
        Board_writeStringValue("C=", count++, 10, LCD_PAGE2);
    }
    Another thing though, I do use another pwm timer for beeping:

    void board_pwm_init()
    {

    Power_setDependency(PERIPH_GPT0);
    hPinBuzzer = PIN_open(&pinState, timerPinTable);
    PINCC26XX_setMux(hPinBuzzer, PWM0_IOID, IOC_PORT_MCU_PORT_EVENT0);
    TimerConfigure(GPT0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_CAP_COUNT);

    }


    void board_pwm_start(unsigned long freq_Hz, uint8 duration)
    {
    unsigned long PWM_FREQ = freq_Hz;
    unsigned long PWM_DIV_FACTOR = 48000000/PWM_FREQ;
    unsigned long TIMER_LOADSET = (PWM_DIV_FACTOR-1);
    unsigned long TIMER_MATCH;

    if(duration > 100) duration = 100;

    TIMER_MATCH = (PWM_DIV_FACTOR*(100-duration)/100-1);

    Power_setConstraint (Power_SB_DISALLOW);

    TimerLoadSet(GPT0_BASE, TIMER_A, TIMER_LOADSET);

    TimerMatchSet(GPT0_BASE, TIMER_A, TIMER_MATCH);

    TimerEventControl(GPT0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);


    TimerEnable(GPT0_BASE,TIMER_A);
    }

    void board_pwm_stop()
    {
    TimerDisable(GPT0_BASE,TIMER_A);
    //Power_setConstraint (Power_STANDBY);
    }

  • Rachel,

    The pwm timer and callback timer are never used at the same time, so I guess pwm should not affect the callback.

    Best regards, Young
  • PS
    I need a callback function to handle the periodic work. And I could blink a hardware output pin if necessary.
  • Hi young,

    Have you reviewed the TI-RTOS GPTimer module to see if it would work better for you instead of using Driverlib APIs directly? There is also a PWM module. These files can be found in the source->ti->drivers folder of your SDK installation.

    If you must use Driverlib calls, here is the link to the Timer APIs: dev.ti.com/.../group__timer__api.html

    Maybe TimerIntRegister will give you better results than the Hwi register but it might conflict with TI-RTOS if you are are creating any timers using the Timer module.
  • Hi Rachel,

    The documentation is ambiguous to me and loses me easily. I don't really care which timer module as long as it generates periodic callback with high precision. All I need is these four functions:

    #include "xxxxxx.h"

    void ClockCallBack(arg a)
    {
    }

    void ClockInit()
    {
    }

    void ClockStart(uint32 usec)
    {
    }

    void ClockStop()
    {
    }

    So just to simplify the work load for me and benefit all others struggling with the timer issue, could you just fill the sample code in the brackets to make it work? Then we don't need to communicate like this going nowhere.

    Best regards, Young
  • PS
    I am using SimpleBLEPeripheral
  • Dear TI Gurus,

    Can anybody help solve this puzzle for me? Thanks.

    Best regards, Young