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.

[参考译文] TI-RTOS-MCU:HWI 函数中的 SWI_Post ()调用会导致 SWI 的过帐、但不会执行该函数

Guru**** 2527400 points
Other Parts Discussed in Thread: TI-RTOS-MCU, TM4C1294NCPDT

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1048069/ti-rtos-mcu-swi_post-call-in-hwi-function-results-in-posting-of-the-swi-but-not-executing-the-function

器件型号:TI-RTOS-MCU
主题中讨论的其他器件: TM4C1294NCPDTTM4C123

我在我的项目中使用 TI-RTOS,我在 I2C 外设的 Hwi 函数中使用 Swi_post ()发布 Swi,Swi 被发布,但该函数从未执行。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Ahmed、

    您在什么 TI 器件上使用 TI-RTOS-MCU?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    TivaC tm4c1294ncpdt

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

     您是否在 main()末尾调用了 BIOS_start()? 如果没有 BIOS_start(),操作系统内核将不会安排 SWI 运行。 请看 下面的示例。 它是 TM4C123的示例、但具有与 TM4C129相同的使用概念。 一个 HWI 被创建用来处理定时器中断。 当有一个定时器中断时、它调用 Swi_post 来运行 LED 函数。  

    //----------------------------------------
    // 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
    }
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    首先、感谢您今天早些时候的回复、我发现问题是我未清除 RIS 寄存器以及 IMR 仍然被设置、因此中断始终被触发、而不让 Swi 执行、 因此、解决方案是在布置 swi 之前清除 RIS 标志、这样 I2C 中断就不会再次从这种环境中触发。