Other Parts Discussed in Thread: TM4C1294NCPDT
I am using TI-RTOS in my project, I am Posting a Swi using Swi_post() in the Hwi function of I2C peripheral , the swi is posted but the function is never executed.
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.
I am using TI-RTOS in my project, I am Posting a Swi using Swi_post() in the Hwi function of I2C peripheral , the swi is posted but the function is never executed.
Hi,
Do you have BIOS_start() called at the end of your main()? Without BIOS_start(), the OS kernel will not schedule for the SWI to run. Look at this below example. It is an example for TM4C123 but has the same concept of usage for TM4C129. A HWI is created to handle the Timer interrupt. When there is an timer interrupt, it calls Swi_post to run the LED function.
//---------------------------------------- // 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> //------------------------------------------ // 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); void Timer_ISR(void); //--------------------------------------- // Globals //--------------------------------------- volatile int16_t i16ToggleCount = 0; //--------------------------------------------------------------------------- // main() //--------------------------------------------------------------------------- void main(void) { Hwi_Params hwiParams; Hwi_Handle myHwi; Error_Block eb; /* Initialize error block and hwiParams to default values */ Error_init(&eb); Hwi_Params_init(&hwiParams); hwiParams.enableInt = FALSE; /* Create Hwi on vector 51 which is the TIMER3A */ myHwi = Hwi_create(51, (Hwi_FuncPtr)Timer_ISR, &hwiParams, &eb); if (myHwi == NULL) { System_abort("Hwi create failed"); } Hwi_enableInterrupt(51); Swi_Params swiParams; Swi_Handle LEDSwi; Error_Block eb2; /* Initialize error block and hwiParams to default values */ Error_init(&eb2); Swi_Params_init(&swiParams); LEDSwi = Swi_create((Swi_FuncPtr)ledToggle, &swiParams, &eb2); if (LEDSwi == NULL) { System_abort("Swi create failed"); } 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_TIMER3); // enable Timer 3 periph clks TimerConfigure(TIMER3_BASE, TIMER_CFG_PERIODIC); // cfg Timer 3 mode - periodic ui32Period = (SysCtlClockGet() /2); // period = CPU clk div 2 (500ms) TimerLoadSet(TIMER3_BASE, TIMER_A, ui32Period); // set Timer 3 period TimerIntEnable(TIMER3_BASE, TIMER_TIMA_TIMEOUT); // enables Timer 3 to interrupt CPU TimerEnable(TIMER3_BASE, TIMER_A); // enable Timer 3 } //--------------------------------------------------------------------------- // ledToggle() // // toggles LED on Tiva-C LaunchPad //--------------------------------------------------------------------------- void ledToggle(void) { // 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 } //--------------------------------------------------------------------------- // Timer ISR - called by BIOS Hwi (see app.cfg) // // Posts Swi (or later a Semaphore) to toggle the LED //--------------------------------------------------------------------------- void Timer_ISR(void) { TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT); // must clear timer flag FROM timer Swi_post(LEDSwi); // post LEDSwi }
First of all thank you for the reply I did figure out earlier today that the issue was me unclearing the the RIS register as well as for the IMR being still set so the interrupt is just triggered always without letting the swi to execute, so the solution was to clear the RIS flag before posting swi so the I2c interrupt is not triggered again from this context.