最近刚刚学习了RTT,一边看野火的教程一边输入代码,在线程管理这一块出现了一些问题:
我用的是RTT Nano最新的包,将例程输入好编译的时候发现rt_thread_create函数未定义,发现是RT_USING_HEAP未定义,我在reconfig.h中恢复了对RT_USING_HEAP的定义后编译无误,烧入野火的
开发板后按下按钮,串口总是输出“挂起LED1线程失败”或是“恢复LED1线程失败”,想来请问一下各位大家这是啥问题,谢谢!
下面附上main函数代码:`
#include "board.h"
#include "rtthread.h"
/*定义线程栈*/
//ALIGN(RT_ALIGN_SIZE)//字节对齐
//sta
tic rt_uint8_t rt_led1_thread_stack[1024];
/*定义线程控制块*/
static rt_thread_t led1_thread = RT_NULL;
static rt_thread_t key_thread = RT_NULL;
/*定义函数*/
static void led1_thread_entry(void *parameter);
static void key_thread_entry(void *parameter);
int main(void)
{
rt_kprintf("线程管理实验n");
rt_kprintf("按下 K1 挂起线程,按下 K2 恢复线程n");
led1_thread = rt_thread_create(
"led1",
led1_thread_entry,
RT_NULL,
512,
3,
20
);
if(led1_thread != RT_NULL)
rt_thread_startup (led1_thread);
else
return -1;
key_thread = rt_thread_create(
"key",
key_thread_entry,
RT_NULL,
512,
3,
20
);
if(key_thread != RT_NULL)
rt_thread_startup (key_thread);
else
return -1;
}
static void led1_thread_entry(void *parameter)
{
while(1)
{
LED1_ON;
rt_thread_delay(500);
rt_kprintf("led1_thread running,LED1_ONrn");
LED1_OFF;
rt_thread_delay(500);
rt_kprintf("led1_thread running,LED2_ONrn");
}
}
static void key_thread_entry(void *parameter)
{
rt_err_t uwRet=RT_EOK;
while(1)
{
if(Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)
{
rt_kprintf("挂起 LED1 线程n");
uwRet = rt_thread_suspend(led1_thread);
if(RT_EOK == uwRet)
{
rt_kprintf("挂起 LED1 线程成功!n");
}
else
{
rt_kprintf("挂起 LED1 线程失败!n");
}
}
if(Key_Scan(KEY2_GPIO_PORT,KEY2_GPIO_PIN)==KEY_ON)
{
rt_kprintf("恢复 LED1 线程n");
uwRet = rt_thread_suspend(led1_thread);
if(RT_EOK == uwRet)
{
rt_kprintf("恢复 LED1 线程成功!n");
}
else
{
rt_kprintf("恢复 LED1 线程失败!n");
}
}
rt_thread_delay(20);
}
}
/*********************************************END OF FILE**********************/