|
基于STM32系统调度钩子函数具体实例: - static rt_thread_t led1_thread = RT_NULL;
- static rt_thread_t led2_thread = RT_NULL;
- // 入口函数
- void led1_task(void *parameter)
- {
- while(1)
- {
- LED1_TURN;
- rt_thread_mdelay(1000);
- }
- }
- void led2_task(void *parameter)
- {
- while(1)
- {
- LED2_TURN;
- rt_thread_mdelay(500);
- }
- }
- // 系统调度钩子函数
- static void hook_of_scheduler(struct rt_thread *from, struct rt_thread *to)
- {
- rt_kprintf("form %s---> to %s\n",from->name,to->name);
- }
- // 添加系统调度钩子函数,创建线程并开启
- rt_scheduler_sethook(hook_of_scheduler);
- led1_thread = rt_thread_create("led1",led1_task,RT_NULL,256,3,10);
- led2_thread = rt_thread_create("led2",led2_task,RT_NULL,256,3,5);
-
- if(led1_thread != RT_NULL)
- rt_thread_startup(led1_thread);
- else
- return -1;
- if(led2_thread != RT_NULL)
- rt_thread_startup(led2_thread);
- else
- return -1;
|