|
菜鸟发问:
RT-Thread 创建的两个线程不能同时运行(CPU STM32)
#include <rtthread.h>
#include "led.h"
#include <stm32f10x.h>
void rt_thread_entry_led1(void* parameter)
{
while (1)
{
/* led1 on */
rt_hw_led_on(0);
rt_thread_delay(10); /* sleep 0.5 second and switch to other thread */
/* led1 off */
rt_hw_led_off(0);
rt_thread_delay(10);
}
}
void rt_thread_entry_led2(void* parameter)
{
while (1)
{
/* led1 on */
rt_hw_led_on(1);
rt_thread_delay(50); /* sleep 0.5 second and switch to other thread */
/* led1 off */
rt_hw_led_off(1);
rt_thread_delay(50);
}
}
int rt_application_init()
{
rt_thread_t thread;
rt_thread_t thread2_ptr;
/* create led1 thread */
thread = rt_thread_create("led1",
rt_thread_entry_led1, RT_NULL,
512,
20, 5);
if (thread != RT_NULL)
rt_thread_startup(thread);
thread2_ptr = rt_thread_create("led2",
rt_thread_entry_led2, RT_NULL,
512,
10, 10);
if (thread2_ptr != RT_NULL)
rt_thread_startup(thread2_ptr);
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|