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.

SYSBIOS: Cannot change timer function with Timer_setFunc()

Part Number: SYSBIOS
Other Parts Discussed in Thread: AM3358,

Dear all,

I would like to use a timer to call a function periodically on an AM3358. When I do the following in runtime, it works like a charm:

Timer_Params timerParams;
Error_Block eb;
Error_init(&eb);
Timer_Params_init(&timerParams);
timerParams.period = p->pixelTime_us;
timerParams.periodType = Timer_PeriodType_MICROSECS;
timerParams.arg = (UArg)p;
timerParams.startMode = Timer_StartMode_USER;
timerParams.runMode = Timer_RunMode_CONTINUOUS;
iterTimer = Timer_create(Timer_ANY, &doIteration_LaserRunTime, &timerParams, &eb);

Timer_start(iterTimer);

Eventually, I want to create one global timer and use it to call different functions periodically. I Also want to reconfigure the period each time. Changing the period with the provided function works:

UInt key = Hwi_disable();
Timer_setPeriodMicroSecs(iterTimer, p->pixelTime_us + 5); // for example
Hwi_restore(key);

But changing the function that is set as the hwi handler does not work. Even after doing the following, which should in fact not have any effect, starting the timer results is no response whatsoever:

Timer_setFunc(iterTimer, &doIteration_LaserRunTime, (UArg)p); // same same
Timer_start(iterTimer);
// (...)
// nothing happens, function is never called
// (...)

I'm getting the same behaviour with the hal timer header and when using the dmtimer header.

Am I doing something wrong? Are extra steps needed? I'm using sysbios version 6_50_00_10.

Looking forward to your replies
Fabian

  • Hi Fabian,

    I'm sorry, the best person to reply to this is out for a few days. They will respond as soon as they return early next week.

    Thanks and sorry for the delay.

  • Hi Fabian,

    I reviewed the Timer API documentation in <BIOS>/docs/cdoc/ti/sysbios/hal/Timer.html, and I didn't find anything indicating you're using the API functions incorrectly, or that additional steps are required.

    I checked the release notes for any mention of a bug Timer_setFunc() for all SYSBIOS releases after the version you're using, and didn't find anything.

    I couldn't find any other e2e threads which mention this issue.

    I wrote a simple test program which uses Timer_setFunc() immediately after Timer_create(), and DMTimer interrupts occur properly:

    Error_init(&eb);
    Timer_Params_init(&timerParams);
    timerParams.extFreq.hi = 0;
    timerParams.extFreq.lo = 24000000; // BBB xtal freq
    timerParams.period = p->pixelTime_us;
    timerParams.periodType = Timer_PeriodType_MICROSECS;
    timerParams.arg = (UArg)p;
    timerParams.startMode = Timer_StartMode_USER;
    timerParams.runMode = Timer_RunMode_CONTINUOUS;
    iterTimer = Timer_create(Timer_ANY, &doIteration_LaserRunTime, &timerParams, &eb);
    //Timer_start(iterTimer); // this works
    
    Timer_setFunc(iterTimer, &doIteration_LaserRunTime, (UArg)p);
    Timer_start(iterTimer); // this also works
    
    

    I used SYSBIOS 6.76.03.01 & ARM GCC compiler 7-2018-q2 (these are packaged w/ AM335x PRSDK 6.3).

    I've looped in a colleague who may be able to provide more insight.

    Regards,
    Frank

  • Which Timer module are you using?

    Alan

  • Hi Alan,

    I am using the timer with ID 1.

    I have solved the problem for now by using Timer_reconfig(), which only exists in <ti/sysbios/timers/dmtimer/Timer.h> but not in <ti/sysbios/hal/Timer.h>. This one works for me.

    I initialize the timer in the same way as I reconfigure it:

    Error_init(&eb);
    Timer_Params_init(&timerParams);
    timerParams.period = 50; // dummy period
    timerParams.periodType = Timer_PeriodType_MICROSECS;
    timerParams.startMode = Timer_StartMode_USER;
    timerParams.runMode = Timer_RunMode_CONTINUOUS;
    // The below behaves weirdly when passing NULL as timer function. Need to pass non-zero somehow idk
    hTimerIteration = Timer_create(1, (Timer_FuncPtr)1, &timerParams, &eb); // timerId = 1, dummyFunc = 1
    if (Error_check(&eb))
        System_abort("hTimerIteration create failed");
    void startIterationTimer(unsigned int period_us, Timer_FuncPtr func, UArg p)
    {
        Error_Block eb;
        Error_init(&eb);
        timerParams.arg = p;
        timerParams.period = period_us;
        Timer_reconfig(hTimerIteration, func, &timerParams, &eb);
        if (Error_check(&eb))
            System_abort("hTimerIteration reconfigure failed");
    
        Timer_start(hTimerIteration);
    }
    
    
    void stopIterationTimer(void)
    {
        Timer_stop(hTimerIteration);
    }

    This solves my application problem, but not the general problem that I could not reconfigure the timer function with the provided API call.

    Thank you

    Fabian

  • I guess I should also update my SDK at some point...