主题中讨论的其他器件:TM4C123
尊敬的 TI:
我在实现带有中断的计时器时遇到问题,当我分配计时器 ISR 时,我的代码崩溃,即 BIOS()函数崩溃。 请帮助我解决问题。
我已附加项目。
TI RTOS:- Tiva 2.16.1.14
编译器:-GNU v7.2.1 (linaro)
此致
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:
我在实现带有中断的计时器时遇到问题,当我分配计时器 ISR 时,我的代码崩溃,即 BIOS()函数崩溃。 请帮助我解决问题。
我已附加项目。
TI RTOS:- Tiva 2.16.1.14
编译器:-GNU v7.2.1 (linaro)
此致
使用 SYS/BIOS 时 、应使用 SYS/BIOS Hwi 模块来插入中断、而不是使用 TivaWare IntRegister 函数。 请参阅 [常见问题解答]使用 TI-RTOS 时、能否使用 IntRegister 更新矢量表?
您好!
您可以在代码中自行插入中断矢量。 这样做会破坏由 BIOS 管理的矢量表。 这就是切斯特发布后提到的解释。 您需要让 BIOS 处理所有 HWI。
//
//设置计时器超时的中断。
//
TimerIntRegister (TIMER0_BASE、TIMER_A、Timer0IntHandler);
IntRegister (INT_TIMER0A、Timer0IntHandler);
IntEnable (INT_TIMER0A);
TimerIntEnable (TIMER0_BASE、TIMER_TINA_TIMEOUT);
IntMasterEnable();
下面是 TM4C123设置计时器的示例 2. BIOS 使用 Timer_create ()来注册定时器矢量 ledToggle。 不能使用 intRegister()。 请再次阅读 Chester 的参考帖子。 我认为这说明了一切。
Timer_create (2、(Timer_FuncPtr) ledToggle、&Timer2、NULL);
//----------------------------------------
// 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);
// 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
}