Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to extend the main function with $Sub$$main in RT-Threadrt

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use $Sub$main to expand the main function in RT-Threadrt. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Now that rt thread is version 3.1.2, let's take a look at how rt thread extends the main function with $Sub$$main.

The source code for the $Sub$$main function is defined in\ 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

There are two subfunctions:

1. Rt_hw_interrupt_disable, which turns off the global total interrupt, which is defined in the assembly file\ 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

That is, _ _ set_primask (1), turn off interrupts, and only FAULT and NMI interrupts can respond.

2. Rtthread_startup, start rtt, which is also in\ 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 } on how to use $Sub$main in RT-Threadrt to expand the main function is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report