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/EK-TM4C1294XL: TI-RTOS Hardware Interrupt

Part Number: EK-TM4C1294XL

Tool/software: TI-RTOS

Hello;

In TI-RTOS concept hardware interrupt in workshop series , the first lab about usage of hardware interrup by blinking a led.While I am trying this lab I faced with some problem. In code , the hwi will occur based on Tiva TM4c1294xl Timer 2A.But when I set the properties of hwi with dynamically nothing happens.The all code is below;

#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/knl/Clock.h>
#include <ti/sysbios/hal/Hwi.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>

/* Board Header file */
#include "Board.h"

#define TASKSTACKSIZE 512


Hwi_Handle hwi1;

Void hwiFxn(){
    
    GPIO_write(Board_LED1,Board_LED_ON);
}



int main(void)
{
    
    Hwi_Params hwiP;
    Task_Params taskParams;
    /* Call board init functions */
    Board_initGeneral();
    // Board_initEMAC();
    Board_initGPIO();
    // Board_initI2C();
    // Board_initSDSPI();
    // Board_initSPI();
    // Board_initUART();
    // Board_initUSB(Board_USBDEVICE);
    // Board_initUSBMSCHFatFs();
    // Board_initWatchdog();
    // Board_initWiFi();

    /* Construct heartBeat Task  thread */
    Task_Params_init(&taskParams);
    taskParams.arg0 = 1000;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);

    
    Hwi_Params_init(&hwiP);
    hwiP.arg=0;
    hwiP.eventId=39;
    hwiP.priority=0;
    hwi1=Hwi_create(39,hwiFxn,&hwiP,NULL);
    


     /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);
    GPIO_write(Board_LED1, Board_LED_OFF);

    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();

    return (0);
}

Also, in the workshop it says about Event id like for Tiva C Series;

I wonder that I am missing some point while setting Hardware Interrup? It would be very helpful to understand usage and settings for further use.

Best Regards,

  • Hi,
    I don't see you enabling the interrupt with the Hwi_enableInterrupt(39);
  • Hi Charles;

    I tried it but it didnt work. Do I need to define interrupt for timer. After I determine the timer interrupt I need to give a function address for this interrupt instance. Like I defined in hwi function :

    Void hwiFxn(){

    GPIO_write(Board_LED1,Board_LED_ON);
    }
    ( Example)

    The what I need to understand is , the hwi defined function (hwiFxn in that example)-- hwi1=Hwi_create(39,hwiFxn,&hwiP,NULL);-- will have higher priority even if we trigger this hardware interrupt function with timer or other type of interrupts( clock , adc etc...). Could you inform me about that issue. It would be very helpful.

    Best Regards,
  • HI,

     I will suggest you reference the Lab5 solution. The only difference is that in the Lab5 the Hwi for the Timer2 is statically created instead of dynamically created via the Hwi_create(). Look at the code, not only the Timer2 interrupt needs to be enabled, the Timer2 needs to be properly configured (i.e the period of the timer). I don't see that in your code. I 'm not too sure why you have the heartBeatFxn task here.  I will suggest you focus on getting the Hwi working first. 

    /---------------------------------------------------------------------------------
    // Project: Blink TM4C BIOS Using Hwi (SOLUTION)
    // Author: Eric Wilbur
    // Date: June 2014
    //
    // Note: The function call TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT) HAS
    //       to be in the ISR. This fxn clears the TIMER's interrupt flag coming
    //       from the peripheral - it does NOT clear the CPU interrupt flag - that
    //       is done by hardware. The author struggled figuring this part out - hence
    //       the note. And, in the Swi lab, this fxn must be placed in the
    //       Timer_ISR fxn because it will be the new ISR.
    //
    // Follow these steps to create this project in CCSv6.0:
    // 1. Project -> New CCS Project
    // 2. Select Template:
    //    - TI-RTOS for Tiva-C -> Driver Examples -> EK-TM4C123 LP -> Example Projects ->
    //      Empty Project
    //    - Empty Project contains full instrumentation (UIA, RTOS Analyzer) and
    //      paths set up for the TI-RTOS version of MSP430Ware
    // 3. Delete the following files:
    //    - Board.h, empty.c, EK_TM4C123GXL.c/h, empty_readme.txt
    // 4. Add main.c from TI-RTOS Workshop Solution file for this lab
    // 5. Edit empty.cfg as needed (to add/subtract) BIOS services, delete given Task
    // 6. Build, load, run...
    //----------------------------------------------------------------------------------
    
    
    //----------------------------------------
    // 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
    
    
    //------------------------------------------
    // 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)
    {
    
       hardware_init();							// init hardware via Xware
    
       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);
    
    	// Turn on the LED
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);
    
    	// Timer 2 setup code
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);			// enable Timer 2 periph clks
    	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);		// cfg Timer 2 mode - periodic
    
    	ui32Period = (SysCtlClockGet() /2);						// period = CPU clk div 2 (500ms)
    	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period);			// set Timer 2 period
    
    	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);		// enables Timer 2 to interrupt CPU
    
    	TimerEnable(TIMER2_BASE, TIMER_A);						// enable Timer 2
    
    }
    
    
    //---------------------------------------------------------------------------
    // 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
    
    }