如今的rt thread是3.1.2版,先看一下rt thread是怎麼用$Sub$$main來擴展main函數。app
$Sub$$main函數的源碼定義在\src\components.c裏。ide
#if defined(__CC_ARM) || defined(__CLANG_ARM) extern int $Super$$main(void); /* re-define main function */ int $Sub$$main(void) { rt_hw_interrupt_disable(); rtthread_startup(); return 0; } #elif defined(__ICCARM__) // for IAR... #elif defined(__GNUC__) extern int main(void); // for gcc.. #endif
有兩個子函數:函數
一、rt_hw_interrupt_disable,關全局總中斷,定義在彙編文件\libcpu\arm\cortex-m3\context_rvds.S裏。code
;/* ; * rt_base_t rt_hw_interrupt_disable(); ; */ rt_hw_interrupt_disable PROC EXPORT rt_hw_interrupt_disable MRS r0, PRIMASK CPSID I BX LR ENDP
就是__set_primask(1),關中斷,只有FAULT和NMI中斷能夠響應。component
二、rtthread_startup,啓動rtt,也在\src\components.c裏。源碼
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 /* 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; }
老同窗聚會+回老家走親戚,忙到如今纔有點時間來碼字。今天寫不完了,明天繼續。。。it