rt-thread源码分析篇十八:rt_system_scheduler_start函数分析

本文详细分析了实时操作系统(RTOS)的调度器启动源码,包括rt_thread_ready_priority_group的设置、优先级计算、线程列表插入、当前线程切换等关键步骤。讲解了如何确定最高优先级线程并进行上下文切换,以及rt_thread_priority_table的使用。同时,介绍了rt_list_entry宏用于获取线程结构体地址的方法。通过对rt_hw_context_switch_to函数的解析,展示了如何执行线程切换操作。

一、rt_system_scheduler_start源码

{
   
   
    register struct rt_thread *to_thread;
    register rt_ubase_t highest_ready_priority;

#if RT_THREAD_PRIORITY_MAX > 32
    register rt_ubase_t number;

    number = __rt_ffs(rt_thread_ready_priority_group) - 1;
    highest_ready_priority = (number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1;
#else
    highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1;
#endif

    /* get switch to thread */
    to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
                              struct rt_thread,
                              tlist);

    rt_current_thread = to_thread;

    /* switch to new thread */
    rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp);

    /* never come back */
}

二、rt_system_scheduler_start函数分析

1、rt_thread_ready_priority_group

typedef unsigned 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值