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 实现简单的 ledToggle 时出现问题

Guru**** 2482105 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/716262/rtos-ek-tm4c1294xl-problems-with-using-ti-rtos-for-a-simple-ledtoggle

器件型号:EK-TM4C1294XL

工具/软件:TI-RTOS

大家好、我在 TI-RTOS 方面遇到了一些问题。 我正在尝试通过在 UART5上接收字符来更改 LED (板载 LED)的状态,因此当某些字符到达 UART5 RX 时,LED 的状态将被切换(ON --> OFF --> ON)。 为了完成这一操作,我使用 TI-RTOS,想法基本上是使用 HWI 来检测 RX 中的字符并使用 Swi 来切换 LED,下面是代码:

/*Tivaware 驱动程序*/
#include 
#include 
#include "inc/hw_types.h"
#include "lib/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "baud /hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/uart.h"
#include "driverlib/uart.h"#include "#include

"baud /drivermap_#include #include 200_headers_trad_define #include #baud



/*XDC 标准*/
#include /*include BIOS_start*/
#include /*includes LogInfo()*/
#include /*UIA 函数*/
#include 
#include 
#include 

/*globals*/
uint32_t g_ui32SysClock;
swi_handle uartSwi;


/*函数原型*/
void system_start (void);
void uart5_isr (void);
void ledswi (void
);void create_swi (void);
void ws_init_serial (uint32_t system_clock、toggle) void (* pfnHandler)(void));



void main (void){
system_start();
BIOS_start();
}


void system_start (void){
/*将时钟设置为以120MHz 运行*/
G_ui32SysClock= SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480)、120000000);
/*启用和配置 GPIO 端口*/
SysCtlPeripheralEnable (SYSCTL_Periph_GPION);
GPIOPinTypeGPIOOutput (GPIO_PORTN_BASE、GPIO_PIN_1);

/*打开 LED */
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、0x00);

WS_init_serial (g_ui32SysClock、uart5_ISR);

//软件中断
create_swi();
}

void ws_init_serial (uint32_t system_clock、void (* pfnHandler)(void)){

/*启用外设*/
SysCtlPeripheralEnable (SYSCTL_Periph_UART5);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOC);

/*设置引脚*/
GPIOPinConfigure (GPIO_PC6_U5RX);
GPIOPinConfigure (GPIO_PC7_U5TX);
GPIOPinTypeUART (GPIO_PORTC_BASE、GPIO_PIN_6 | GPIO_PIN_7);

/*UART 配置*/
UARTConfigSetExpClk (UART5_BASE、SYSTEM_CLOCK、WS_UART_BAUD_RATE、
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);

/*设置 UART HWI*/
Hwi_handle myHwi;
ERROR_Block EB;
/*启动错误块*/
ERROR_INIT (&EB);
/*启动 HWI 对象*/
myHwi = Hwi_create (74、pfnHandler、NULL、&EB);
if (myHwi = NULL){
system_abort ("UART HWI 创建失败");
}
/*启用 UART 中断*/
IntEnable (INT_UART5);
UARTIntEnable (UART5_BASE,(UART_INT_RX | UART_INT_RT);


}

/*此函数用于触发 swi*/
void uart5_ISR (void){
uint32_t ui32Status;
/*获取中断状态。*/
ui32Status = UARTIntStatus (UART5_BASE、TRUE);
/*清除已发出的中断。*/
UARTIntClear (UART5_BASE、ui32Status);
/*布置 Swi*/
Swi_post (uartSwi);
}

void create_swi (void){
ERROR_Block EB;
ERROR_INIT (&EB);
uartSwi = Swi_create (ledToggle、NULL、&EB);
if (uartSwi = NULL){
system_abort ("UART SWI 创建失败");
}
}

void ledToggle (void){
if (GPIOPinRead (GPIO_PORTN_BASE、GPIO_PIN_1)/* if LED 亮起*/
{
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、0x00);/*关闭它*/
}
否则
{
GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、GPIO_PIN_1);/*Turn */
}



只有当我接收到第一个字符时、当我发送另一个字符时、LED 才会切换、代码才能正常工作。

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

    我打赌您必须先从 RX 寄存器中读取字符、然后才能获得另一个 RX 中断。 我认为您应该向 ISR 添加'data= UARTread()'调用。 当 RX 寄存器从空状态转换为满状态时、UART 会向您提供中断。  由于您从未阅读过它、它永远不会变空。