-
RT-Thread 运行在STM32F429IG(硬件情况)
-
代码情况
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-015 xp 今天日本投降74周年
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
/* defined the LED0 pin: PB1 */
#define LED0_PIN GET_PIN(H, 10)
/**
* 多线程测试************
* 1.线程1 打印 这个是现场1
* 2.线程2 打印 这个是现场2
*/
/*线程1是静态线程*/
#define THREAD_PRIORITY 25
#define THREAD_STACK_SIZE 512
#define THREAD_TIMESLICE 5
static rt_thread_t tid1 = RT_NULL;
/*线程1 入口函数*/
static void thread1_entry(void *hhh)
{
rt_uint32_t count =6;
while(count--)
{
rt_kprintf("thread1 >>>>>>>>count:%d\n",count);
rt_thread_mdelay(500);
}
rt_kprintf("thread 1 die\n");
}
ALIGN(RT_ALIGN_SIZE)
static char thread2_stack[1024];
static struct rt_thread thread2;
static void thread2_entry(void *hhh)
{
rt_uint32_t count = 0 ;
for(count=0;count<3;count++)
{
rt_kprintf("thread2 >>>>>>>>:count%d\n",count);
}
rt_kprintf("thread2 die\n");
}
int main(void)
{
int count = 0;
/* set LED0 pin mode to output */
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
rt_pin_write(LED0_PIN,PIN_HIGH);
//创建线程1 静态线程使用create
tid1 = rt_thread_create("thread1",thread1_entry,RT_NULL,THREAD_STACK_SIZE,
THREAD_PRIORITY,THREAD_TIMESLICE);
if( tid1 != RT_NULL)
rt_thread_startup(tid1);
//创建线程2 动态创建线程 使用init
rt_thread_init(&thread2,
"thread2",
thread2_entry,
RT_NULL,
&thread2_stack,
sizeof(thread2_stack),
THREAD_PRIORITY-1,
THREAD_TIMESLICE);
rt_thread_startup(&thread2);
return RT_EOK;
}
-
运行效果: