rt_kprintf("beep_thread running,toggle\r\n");
工程参考例程在:
RT-Thread物联网操作系统介绍
#include "MyIncludes.h"
/* 定义线程控制块 */
static struct rt_thread LED_Thread;
static struct rt_thread BEEP_Thread;
/* 定义线程控栈时要求RT_ALIGN_SIZE个字节对齐 */
ALIGN(RT_ALIGN_SIZE)
/* 定义线程栈 */
static rt_uint8_t rt_led_thread_stack[1024];
static rt_uint8_t rt_beep_thread_stack[1024];
/*******************************************************************************
* Function Name : LED_Thread_Process
* Description : LED线程函数
* Input : None
* Output : None
* Return : None
* Note : None
*******************************************************************************/
static void LED_Thread_Process(void* parameter)
{
while(1)
{
LED_Toggle(LED_R); //翻转LED
rt_kprintf("led_thread running,toggle\r\n");
rt_thread_delay(1000); /* 延时1000个tick,即1秒 */
}
}
/*******************************************************************************
* Function Name : BEEP_Thread_Process
* Description : 蜂鸣器线程函数
* Input : None
* Output : None
* Return : None
* Note : None
*******************************************************************************/
static void BEEP_Thread_Process(void* parameter)
{
while(1)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
rt_kprintf("beep_thread running,toggle\r\n");
rt_thread_mdelay(500); /* 延时500毫秒,即1秒 */
}
}
int main(void)
{
/*
* 开发板硬件初始化,RTT系统初始化已经在main函数之前完成,
* 即在component.c文件中的rtthread_startup()函数中完成了。
* 所以在main函数中,只需要创建线程和启动线程即可。
*/
//LED线程
rt_thread_init(&LED_Thread, /* 线程控制块 */
"LED", /* 线程名字 */
LED_Thread_Process, /* 线程入口函数 */
RT_NULL, /* 线程入口函数参数 */
&rt_led_thread_stack[0], /* 线程栈起始地址 */
sizeof(rt_led_thread_stack), /* 线程栈大小 */
3, /* 线程的优先级 */
20); /* 线程时间片 */
rt_thread_startup(&LED_Thread); /* 启动线程,开启调度 */
//BEEP线程
rt_thread_init(&BEEP_Thread, /* 线程控制块 */
"BEEP", /* 线程名字 */
BEEP_Thread_Process, /* 线程入口函数 */
RT_NULL, /* 线程入口函数参数 */
&rt_beep_thread_stack[0], /* 线程栈起始地址 */
sizeof(rt_beep_thread_stack), /* 线程栈大小 */
3, /* 线程的优先级 */
20); /* 线程时间片 */
rt_thread_startup(&BEEP_Thread); /* 启动线程,开启调度 */
}