当前位置: 首页 > news >正文

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_HEAPtid = rt_thread_create("main", main_thread_entry, RT_NULL,RT_MAIN_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 20);RT_ASSERT(tid != RT_NULL);
#elsert_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_SMPrt_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手册查看相关细节。

http://www.lryc.cn/news/140193.html

相关文章:

  • Python实现企业微信群告警
  • python基础教程:re模块用法详解
  • 基于亚马逊云科技无服务器服务快速搭建电商平台——部署篇
  • git介绍+集成到IDEA中+使用gitee
  • 【java】【项目实战】[外卖四]分类管理业务开发
  • 【Go 基础篇】Go语言包详解:模块化开发与代码复用
  • 【业务功能篇82】微服务SpringCloud-ElasticSearch-Kibanan-docke安装-进阶实战
  • 【工具】XML和JSON互相转换
  • 前端面试:【浏览器与渲染引擎】Web APIs - DOM、XHR、Fetch、Canvas
  • 编码基础一:侵入式链表
  • 深圳IT行业供需:蓬勃发展的科技中心
  • LeetCode 面试题 02.01. 移除重复节点
  • 【Java8特性】——Stream API
  • grep命令的用法
  • 【无标题】jenkins消息模板(飞书)
  • 2023年国赛 高教社杯数学建模思路 - 案例:随机森林
  • element Collapse 折叠面板 绑定事件
  • CSS :mix-blend-mode、aspect-ratio
  • Module not found: Error: Can‘t resolve ‘less-loader‘解决办法
  • 量化QAT QLoRA GPTQ
  • CentOS下查看 ssd 寿命
  • Node基础--npm相关内容
  • Python图片爬虫工具
  • 制造执行系统(MES)在汽车行业中的应用
  • Spring与Mybatis集成且Aop整合
  • 【nonebot-plugin-mystool】快速安装使用nonebot-plugin-mystool
  • js实现数据关联查找更新。数据求和验证
  • 区块链上地址与银行账户有什么区别?
  • CF 148 D Bag of mice(概率dp求概率)
  • 引入本地 jar 包教程