RT-Thread物联网操作系统介绍:5、串口打印

 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);             /* 启动线程,开启调度 */
                   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值