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/TM4C1294NCPDT: Hwi Working Principle Problem?

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hello;

I have been working on hwi , I tried the basic SYS/BIOS (TI-RTOS) Kernel document example as same as shown;

This code example is at the page 172-173 of spruex3t.pdf file ( SYS/BIOS TI-RTOS Kernel) Documentation. When I tried this simple example I cannot see and result , I also look at the Hwi5 and Hwi6 values from expression tool. But it shows nothing working.

I wonder that I am doing something wrong. 

while I am creating project I choose the fallowing options as you see below,

Do I creating project wrong way ? Could you help me about this issue? I literally stuck on that Hwi problem.Thank you.

Best Regards.

  • You cannot use the example as is as you don't know which device the example is written for. It maybe even a psuedo example that is not targeted to any specific TI device.  The Hwi_enableinterrupt(5) and Hwi_enableinterrupt(6) are for the bus fault and usage fault in the TM4C device. Please look at the Exception and Interrupt tables in the datasheet for details. For example, if you want to enable interrupt for Timer2A then it is mapped to vector number 39 and you will call Hwi_enableinterrupt(39) to enable it. You need to find out which peripheral you want to generate interrupt and enable it accordingly. 

  • Hi Charles;

    I tried timer vector numbers too, but it is not working. Also I create timer interrupt. For both timer1B and timer2A, then enabled Hwi interrupt that function.So I tried both way but nothing happend result is same as before.

  • Hi Charles;

    I also created statically from sysbios XGCONF. In this, I used the timer3. If I dont give any function name for the timer instance, even if the Hwi is created with the relative timer vector number, the Hwi does not working. I need to give function name for the Timer3 instance (Which function is created for the Hwi. ) In that way the system is working. I wonder that , creating the Hwi is for giving highest pre-emption features to function or ISR in that example?

    Best Regards,
  • Hi,
    Are you trying to use the example you took from the User's guide which you pasted above and simply change the vector number to 39? Did you configure the timer module such as timer's period, enable timer module and etc?
  • Hi Charles;

    Yes I have done all you said, also I configured the Timer ;

    *  ======== empty.c ========
     */
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/hal/Timer.h>
    
    /* TI-RTOS Header files */
    // #include <ti/drivers/EMAC.h>
    #include <ti/drivers/GPIO.h>
    // #include <ti/drivers/I2C.h>
    // #include <ti/drivers/SDSPI.h>
    // #include <ti/drivers/SPI.h>
    // #include <ti/drivers/UART.h>
    // #include <ti/drivers/USBMSCHFatFs.h>
    // #include <ti/drivers/Watchdog.h>
    // #include <ti/drivers/WiFi.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/hal/Hwi.h>
    
    Bool Hwi6 = FALSE;
    Timer_Handle tmrH;
    /* Board Header file */
    #include "Board.h"
    Void myIsr6(UArg arg);
    
    /* Runs when interrupt 6 occurs */
    
    main(Void) {
        Timer_Params tmrP;
        Hwi_Params hwiParams;
        Hwi_Handle myHwi;
        Error_Block eb;
    /* Initialize error block and hwiParams to default values */
        Error_init(&eb);
        Hwi_Params_init(&hwiParams);
    /* Set myIsr6 parameters */
        hwiParams.arg = 12;
        hwiParams.enableInt = FALSE;
    /* Create a Hwi object for interrupt number 6
    * that invokes myIsr6() with argument 12 */
    
        myHwi = Hwi_create(51, myIsr6, &hwiParams, &eb);
        if (myHwi == NULL) {
                System_abort("Hwi create failed");
        }
        Hwi_enableInterrupt(51);
    
        Timer_Params_init(&tmrP);
        tmrP.arg=0;
        tmrP.period=1000000;
        tmrP.periodType=Timer_PeriodType_MICROSECS;
        tmrH=Timer_create(51,NULL,&tmrP,NULL);
        Timer_start(tmrH);
    
    /* start BIOS */
        BIOS_start();
    }
    Void myIsr6(UArg arg){
        System_printf("Hello Hwi");
        if(arg == 12){
           Hwi6 = TRUE;
        }
    }
    /* The Idle thread checks for completion of interrupts 5 & 6
    * and exits when they have both completed. */
    Void myIdleFunc()
    {
        if(Hwi6){
            System_printf("Both interrupts have occurred!");
            System_exit(0);
        }
    }


    But the result is the same no change , no console log and when I stop the program and run step by step it stuck on SysMin_putch function;
  • This is same for Timer 2A ( vector num: 39) , Timer 3A ( Vector num: 51) and Timer 3B( vector num: 52) . All results are same. I dont understand, it should work.

  • You might find this post helpful. e2e.ti.com/.../512202
  • Hi,

     Not sure if your problem is resolved. Looking at your code again, the Timer_create call is wrong. You pass 51 as the first parameter to the Tiemr_create. The argument to pass is the timer instance number, not the interrupt vector number. If you want to use Timer3A then you need to pass 3 instead of 51. You cannot use Timer_create and the Hwi_create on the same Timer3A at the same time. The Timer_create is built in to take care of the interrupt (vector 51) already. You don't need to use Hwi_create in this case. Below is an example code for Timer2A using Timer_create I created and it is working for me.

    
    
    //----------------------------------------
    // BIOS header files
    //----------------------------------------
    #include <xdc/std.h>  						//mandatory - have to include first, for BIOS types
    #include <ti/sysbios/BIOS.h> 				//mandatory - if you call APIs like BIOS_start()
    #include <xdc/runtime/Log.h>				//needed for any Log_info() call
    #include <xdc/cfg/global.h> 				//header file for statically defined objects/handles
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/hal/Hwi.h>
    #include <ti/sysbios/hal/Timer.h>
    
    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>
    
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    
    
    //----------------------------------------
    // Prototypes
    //----------------------------------------
    void hardware_init(void);
    void ledToggle(void);
    
    
    //---------------------------------------
    // Globals
    //---------------------------------------
    volatile int16_t i16ToggleCount = 0;
    
    
    //---------------------------------------------------------------------------
    // main()
    //---------------------------------------------------------------------------
    void main(void)
    {
    
        Timer_Params Timer2;
        Timer_Handle myTimer;
    
       hardware_init();							// init hardware via Xware
    
       Timer_Params_init(&Timer2);
       Timer2.arg=0;
       Timer2.period=100000;
       Timer2.periodType=Timer_PeriodType_MICROSECS;
       myTimer=Timer_create(2,(Timer_FuncPtr)ledToggle,&Timer2,NULL);
       Timer_start(myTimer);
    
       BIOS_start();
    
    }
    
    
    //---------------------------------------------------------------------------
    // hardware_init()
    //
    // inits GPIO pins for toggling the LED
    //---------------------------------------------------------------------------
    void hardware_init(void)
    {
    //	uint32_t ui32Period;
    
    	//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
    	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    	// ADD Tiva-C GPIO setup - enables port, sets pins 1-3 (RGB) pins for output
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    
    }
    
    
    //---------------------------------------------------------------------------
    // ledToggle()
    //
    // toggles LED on Tiva-C LaunchPad
    //---------------------------------------------------------------------------
    void ledToggle(void)
    {
        TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);			// must clear timer flag FROM timer
    
    	// LED values - 2=RED, 4=BLUE, 8=GREEN
    	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    	}
    	else
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
    	}
    
    	i16ToggleCount += 1;									// keep track of #toggles
    
    	Log_info1("LED TOGGLED [%u] TIMES",i16ToggleCount);		// send toggle count to UIA
    
    }
    
    
    

  • Hwi_Handle hwi0Hand;
    Hwi_Params hwi0Params;
    
    Timer_Handle timer2Handle;
    Timer_Params timer2Params;
    
    Hwi_Params_init(&hwi0Params);
    hwi0Params.enableInt=TRUE;
    
    
    Void hwi0Fxn(){
    
       some code.....
       .......
       .......
    
    }
    
    
    int main(void){
        hwi0Hand=Hwi_create(39,hwi0Fxn,&hwi0Params,NULL);
    
        /* In here timer param init, argument and etc setting*/
        ....
        ....
        ....
        timer2Handle=Timer_create(2,NULL,&timer2Params,NULL);
    
        /*In here the Timer is set for Hwi Interrupt*/
    
        System_printf("Starting the example\nSystem provider is set to SysMin. "
                      "Halt the target to view any SysMin contents in ROV.\n");
        /* SysMin will only print to the console when you call flush or exit */
        System_flush();
    
        /* Start BIOS */
        BIOS_start();
    
    }
    

    Hi Charles;

    Thank you , it is good example for Timer usage and very enlightening information.I used it and timer interrupt is worked. Can we implement for Hwi like Timer İnterrupt. All I want to know is about use Hwi by setting Timer interrupt like you did before. For example can we do something like that code above ? Thank you again.

    Best Regards

  • No, I don't think so. Like I said before, the Timer_create will already take care of the Hwi interrupt for you. When you call Timer_create(2,...) it knows that you are creating a timer using the TIMER2A module and that interrupt is mapped to 39 already. The Hwi_create(39,...) is redundant and i think you will just confuse the OS. Wouldn't you have the same callback function for the Hwi_create() and the Timer_create(). In the example I show, both will be calling the ledToggle(). You need to use either the Hwi for the Timer interrupt or just the build-in TI-RTOS Timer module, not both of them at the same time.
  • Thank you Charles,

    Right now, it is much more clear for me.

    Best Regards
  • glad it is clear to you now.