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

Keil的两个符号$Sub$ $与 $Super$ $是其做的打“补丁”功能
具体调用方法就是程序中包含有main函数,和 $Sub$ $main 、 $Super$ $main 两个符号
源码先放出来

/* re-define main function */
int $Sub$$main(void)
{
    rtthread_startup();
    return 0;
}
/**
 * @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);
}
/**
 * @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 */
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手册查看相关细节。