RTThread中的启动分析

RTThread中的启动分析—$Sub$$main()和$Super$$main()

@(RTThread源码学习)

main入口的重新定义$Super$$main()和$Sub$$main()
  • 这里写图片描述
这是一种特殊模式:用于有一个已经存在且不能被改变的函数 的情况。使用这两个模式可以帮原函数打补丁。如存在一个函数foo();
$Sub$$foo() :定义的新功能函数,原先foo()函数的入口变为$Sub$$foo(),可以在此函数添加一些新的程序代码。
$Super$$foo() :就是原始的未修补的foo函数,使用这个$Super$$foo函数将直接跳转到foo()函数。
以下例子:
extern  void $Super$$hellow(void);
void hellow(void)
{
    printf("hellow\n");
}
void $Sub$$hellow(void)
{
    printf("Sub hellow first\n");
    $Super$$hellow();
    printf("Sub hellow second\n");
}
void main()
{
    $Sub$$hellow();
}   
打印结果
Sub hellow first
hellow
Sub hellow second

  • 以上使用的好处是可以系统启动后,跳转到系统编写的$Sub$$main()中,在这里做一些系统启动是的初始化等,使得移植和使用更加方便。
启动过程
  • Alt text这里进入main
  • Alt text跳转到$Sub$$main()
  • Alt text跳转到rtthread_startup()
  • Alt text
  • Alt text调用$Super$$main()相当于调用main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值