In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
RT-Thread $Sub$main and $Super$main extension main function example analysis, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The _ _ main function of MDK5 is automatically generated, and the source code cannot be modified. Meanwhile, MDK5 provides a pair of symbols $Sub$$ and $Super$$ to extend the function. This pair of symbols acts on the connector, and when the connector connects to the func, if it finds that there is a $Sub$$func function, it will connect the $Sub$$func function first until $Super$$func appears, and $Super$$func is the new entry for the func function.
The example given on Keil's official website:
Extern void ExtraFunc (void); extern void $Super$$foo (void): / * this function is called instead of the original foo () * / void $Sub$$foo (void) {ExtraFunc (); / * does some extra setup work * / $Super$$foo (); / * calls the original foo () function * / / * To avoid calling the original foo () function * omit the $Super$$foo (); function call. * /}
The $Sub$$ and $Super$$ symbols can add new functionality without modifying the original program, and rtt uses these symbols to extend the main function.
Make a simple example to test this extension:
Int I = 0: void $Super$$main (void); void $Sub$$main (void) {ifolds; $Super$$main ();} int main (void) {ifolds; while (1) {}}
Looking at the disassembly (assembly mode), the original jump to the main function becomes the jump to the $Sub$$main function:
_ _ rt_entry_main:0x08000172 F000F867 BL.W $Sub$$main (0x08000244) 0x08000176 F000F84F BL.W exit (0x08000218)
$Sub$$main function:
$Sub$$main:0x08000244 B510 PUSH {r4jue LR} 0x08000246 4804 LDR R0, [pc,#16]; @ 0x080002580x08000248 6800 LDR R0, [R0GOME 0x00] 0x0800024A 1C40 ADDS R0J r0MIT 10x0800024C 4902 LDR R1, [pc,#8] @ 0x080002580x0800024E 6008 STR R0, [R1 DCW 0x00000x0800025A 0x00] 0x08000250 F000F8A8 BL.W main (0x080003A4) 0x08000254 BD10 POP {r4 mentions PC} 0x08000256 0000 DCW 0x00000x08000258 0000 DCW 0x00000x0800025A 2000 DCW 0x2000
By doing so, you can keep the startup code unchanged while implementing an extension to the main function. This is what rtt's scheduler does.
After reading the above, have you mastered the method of analyzing the examples of the $Sub$main and $Super$main extended main functions in RT-Thread? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.