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.

Hwi Hook to a specific Timer Interrupt?

Other Parts Discussed in Thread: TMS320F28069, DRV8312, SYSBIOS

Hi there, 

I have the following setup:

I'm using two independent timers for a cascaded control system (CPU Timer0 for fast control loop and CPU Timer1 for slow control loop) and I'm using a Begin Hook function ('myBeginFxn') for the Hwi module. Out of my investigations, it follows that 'myBeginFxn' will be called just before both timer interrupt service routines. 

My question now is: Is it possible to assign the 'myBeginFxn' Hook function only to the fast timer ISR? If not, is it possible inside the 'myBeginFxn Hook function to find out which timer interrupt has invoked the Hook function? 

Thanks 

Simon

  • Hi Simon,

    What version of SYS/BIOS are you using? Also what device are you using.

    Todd

  • Hi Todd, 

    I'm using SYS/BIOS 6.34.2.18 and the TMS320F28069 device on a ControlSTICK and on a ControlCARD with the DRV8312 Development Kit. 

    Simon

  • Hi Simon,

    I'm working on an example.

    Todd

  • Sorry for the delay. I'll have the example on Friday.

  • Hi Todd,

    Thank you for the information.

    I'm looking forward to the example.

    Simon

  • Hi Simon,

    I got this to work on a LM4F board.

    1. I created two timers in the .cfg file. Note that I used the family.arm.lm4 module instead of the top-level hal/Timer module (you'll need to use ti.sysbios.family.c28 one)

    var Timer = xdc.useModule('ti.sysbios.family.arm.lm4.Timer');

    var timer0Params = new Timer.Params();
    timer0Params.instance.name = "timer0";
    timer0Params.period = 1000;
    Program.global.timer0 = Timer.create(-1, "&timer0Fxn", timer0Params);

    var timer1Params = new Timer.Params();
    timer1Params.instance.name = "timer1";
    timer1Params.period = 2000;
    Program.global.timer1 = Timer.create(-1, "&timer1Fxn", timer1Params);

    2. In my app, I was able to have the following in the begin hook. This works because the timer handle is stored in the Hwi's arg field. Note I'm using the family modules instead of the ti\sysbios\hal modules. (again, you'll need to use ti.sysbios.family.c28 ones)

    #include <ti/sysbios/family/arm/m3/Hwi.h>
    #include <ti/sysbios/family/arm/lm4/Timer.h>

    #include <xdc/cfg/global.h>

    Void myBegin(Hwi_Handle hwi)
    {
        UArg arg;
        Hwi_getFunc(hwi, &arg);

        if (arg == (UArg)(timer0)) {
            System_printf("timer0\n");
        }
        else if (arg == (UArg)(timer1)) {
            System_printf("timer1\n");
        }
        else {
            System_printf("neither timer\n");
        }
    }

    Todd

  • Hi Todd,

    Thank you for the well structured and easy example.

    I'll try this as soon as possible with my configuration and will let you know about the results.

    Simon

     

     

  • Hi Todd

    Thank you for the hint of using the Hwi_Handle. Unfortunately, I was not able to get it running with the argument (UArg arg) of the Hwi_getFunc() with my setup. Instead, I got it running with the Hwi_FuncPtr:

    1. The two timers configured in the config-file:

    var Timer = xdc.useModule('ti.sysbios.family.c28.Timer'); 

    var timerParams = new Timer.Params();

    timerParams.instance.name = "myTimer";

    timerParams.startMode = Timer.StartMode_AUTO;

    timerParams.runMode = Timer.RunMode_CONTINUOUS;

    timerParams.period = 100;

    timerParams.periodType = Timer.PeriodType_MICROSECS;

    var myTimer = Timer.create(0, '&myTickFxn', timerParams);

    Program.global.myTimer = myTimer;

     

    var timer1Params = new Timer.Params();

    timer1Params.instance.name = "myTimerSpeed";

    timer1Params.startMode = Timer.StartMode_AUTO;

    timer1Params.runMode = Timer.RunMode_CONTINUOUS;

    timer1Params.period = 1000;

    timerParams.periodType = Timer.PeriodType_MICROSECS;

    var myTimerSpeed = Timer.create(1, "&myTickFxnSpeed", timer1Params);

    Program.global.myTimerSpeed = myTimerSpeed;

     

    2. In the application code:

     

    #include <ti/sysbios/family/c28/Hwi.h>

    #include <ti/sysbios/family/c28/Timer.h>

     

    #include <xdc/cfg/global.h>

     

    /* =========== myBegin1 Hook =============

     * invoked before Timer Hwi func

     */

    Void myBegin1(Hwi_Handle hwi) {

           UArg arg;

           Hwi_FuncPtr hwiPtr;

           hwiPtr = Hwi_getFunc(hwi, &arg);

     

           if ( (UArg)(hwiPtr) == (UArg)(myTickFxn) ) {

                  Log_info0("Start myBegin1 from Timer0");              

           } else if ( (UArg)(hwiPtr) == (UArg)(myTickFxnSpeed) ) {

                 Log_info0("Start myBegin1 from Timer1");

           } else {

                 Log_info0("Start myBegin1 from neither timer");

           }

     }

     

    Simon