RTThread学习有关的Keil的两个符号 $Sub$ $main 与 $Super$ $main

Keil的两个符号Sub 与 Super 是其做的打"补丁"功能

具体调用方法就是程序中包含有main函数,和 Sub main 、 Super main 两个符号

源码先放出来

c 复制代码
/* re-define main function */
int $Sub$$main(void)
{
    rtthread_startup();
    return 0;
}
c 复制代码
/**
 * @brief  This function will create and start the main thread, but this thread
 *         will not run until the scheduler starts.
 */
void rt_application_init(void)
{
    rt_thread_t tid;

#ifdef RT_USING_HEAP
    tid = rt_thread_create("main", main_thread_entry, RT_NULL,
                           RT_MAIN_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 20);
    RT_ASSERT(tid != RT_NULL);
#else
    rt_err_t result;

    tid = &main_thread;
    result = rt_thread_init(tid, "main", main_thread_entry, RT_NULL,
                            main_thread_stack, sizeof(main_thread_stack), RT_MAIN_THREAD_PRIORITY, 20);
    RT_ASSERT(result == RT_EOK);

    /* if not define RT_USING_HEAP, using to eliminate the warning */
    (void)result;
#endif /* RT_USING_HEAP */

    rt_thread_startup(tid);
}
c 复制代码
/**
 * @brief  This function will call all levels of initialization functions to complete
 *         the initialization of the system, and finally start the scheduler.
 *
 * @return Normally never returns. If 0 is returned, the scheduler failed.
 */
int rtthread_startup(void)
{
    rt_hw_interrupt_disable();

    /* board level initialization
     * NOTE: please initialize heap inside board initialization.
     */
    rt_hw_board_init();

    /* show RT-Thread version */
    rt_show_version();

    /* timer system initialization */
    rt_system_timer_init();

    /* scheduler system initialization */
    rt_system_scheduler_init();

#ifdef RT_USING_SIGNALS
    /* signal system initialization */
    rt_system_signal_init();
#endif /* RT_USING_SIGNALS */

    /* create init_thread */
    rt_application_init();

    /* timer thread initialization */
    rt_system_timer_thread_init();

    /* idle thread initialization */
    rt_thread_idle_init();

#ifdef RT_USING_SMP
    rt_hw_spin_lock(&_cpus_lock);
#endif /* RT_USING_SMP */

    /* start scheduler */
    rt_system_scheduler_start();

    /* never reach here */
    return 0;
}
#endif /* RT_USING_USER_MAIN */
c 复制代码
void main_thread_entry(void *parameter)
{
    extern int main(void);

 */
#ifdef __ARMCC_VERSION
    {
        extern int $Super$$main(void);
        $Super$$main(); /* for ARMCC. */
    }
#elif defined(__ICCARM__) || defined(__GNUC__) || defined(__TASKING__) || defined(__TI_COMPILER_VERSION__)
    main();
#endif
}

理下顺序

我们驱动文件在跳转main函数时由于定义有int Sub\main(void) 所以先执行这个函数,在这个函数中主要是进行系统、板级初始化,在这里面穿件了一个主线程main_thread_entry,而主线程里面调用了 Super\\main()就回到main函数执行;所以我们就把main放在一个线程里面,而其他RTOS是在执行main后才进行相关的RTOS初始化,板级初始化等。
可能会引起迷惑的地方

1.为什么要调用 Super\main()而不调用main我觉得按照上面描述的逻辑如果调用main就会又去跳转到int Sub\\main(void) 这里无限循环调用下去,所以不会说在这里要调用main进行跳转;

2.为什么还要调用 Super\main()而不是结束了int Sub\\main(void)直接返回main去执行,这个我觉得主要是让人们知道最终main的去向,在BX __main 之后都不知道main去哪了,具体细节可以在Keil手册查看相关细节。

相关推荐
Code_Solitude1 小时前
开发板点灯实验源码
stm32·单片机·嵌入式硬件
Zw-awa11 小时前
编码器读到的到底是什么:从脉冲到速度
stm32
炸膛坦客12 小时前
单片机开发工具篇:(十四)配置输出 .map 文件及其本地路径
c语言·单片机·嵌入式硬件
笨笨饿13 小时前
140_AI新手村MCP与Skills是干嘛的
开发语言·人工智能·python·stm32·单片机·嵌入式硬件·物联网
我叫洋洋15 小时前
Cadence CIS 元器件库合并实战:3000+ 焊盘、156 个符号零冲突并入自有库
数据库·单片机·嵌入式硬件·oracle·电路
ebiobiz16 小时前
极海 APM32 使用 Nimmake 编译指南
c++·python·单片机·嵌入式硬件·mcu
小神兵17 小时前
对电压源与电流源的的简单理解
单片机·嵌入式硬件·物联网
comyccccc18 小时前
三极管与MOS管工作原理全解析学习笔记
单片机·嵌入式硬件
FPGA小徐19 小时前
运放电路:负载必须接地时,如何做电流采样(浮地负载 vs 接地负载)
单片机·嵌入式硬件
女神下凡1 天前
芯参谋(37):EEPROM_电路设计指南
arm开发·单片机·嵌入式硬件·fpga开发·设计规范