2019独角兽企业重金招聘Python工程师标准>>>
现在的rt thread是3.1.2版,先看一下rt thread是怎么用$Sub$$main来扩展main函数。
$Sub$$main函数的源码定义在\src\components.c里。
#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
有两个子函数:
1、rt_hw_interrupt_disable,关全局总中断,定义在汇编文件\libcpu\arm\cortex-m3\context_rvds.S里。
;/*
; * 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中断可以响应。
2、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;
}
老同学聚会+回老家走亲戚,忙到现在才有点时间来码字。今天写不完了,明天继续。。。