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 realize static instantiation of Kernel object by vxworks

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

Share

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

Editor to share with you how vxworks to achieve static instantiation of kernel objects, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Kernel objects for VxWorks can be created dynamically or instantiated statically.

Static instantiation means that a macro using VxWorks declares variables at compile time (compile-time) so that the compiler allocates space for it instead of dynamically requesting space at run time (run-time). So during system startup, the object can be initialized.

For dynamic application, you need to call the runtime memory allocation mechanism after the system starts; for the corresponding dynamic deletion, you need to call the memory release mechanism, which is usually the malloc () and free () functions. This dynamic behavior has the risk of running out of memory, and will slow down or even block the execution of callers, so it has a certain impact on system performance.

Take a look at the comparison of dynamic and static pseudocode

The object declared at compile time, if not assigned an initial value, will not consume the space of the system image. The compiler will just put it in the mirror BSS section.

Executable programs include code segments (also known as text segments), data segments, and BSS segments. BSS (Block Started by Symbol) is an area of memory used to store uninitialized global and static variables in a program. The feature is that it is readable and writable, and the BSS segment is automatically cleared 0 before the program is executed. Therefore, the non-initial global variables are initialized to 0 before the program executes.

Advantages of static instantiation:

Performance and certainty

Simplify application logic without considering dynamic application failure

The static declaration will not fail unless the entire program is outside the scope of system memory

The VxWorks system can cut out the relevant functions of the dynamic application and reduce the system size.

Therefore, static instantiation is more suitable for the requirements of real-time systems. And in most embedded systems (OS is not limited to VxWorks), system objects need to exist all the time, so there is no need for dynamic deletion, and even some systems (such as CERT OS) do not support the dynamic use of memory.

VxWorks specifically provides some macros to instantiate objects, including tasks, semaphores, message queues, and watchdogs.

Task

The macro VX _ TASK (name,stackSz) is used to declare the task object at compile time. The two parameters are the task name (which cannot be NULL) and the stack size (constant greater than 0).

The macro VX _ TASK_INITIALIZE () is used to initialize the task declared by VX_TASK () and place it in the suspend state with the same parameters and return values as taskSpawn ()

The macro VX _ TASK_INSTANTIATE () is used to initialize the task declared by VX_TASK () and place it in the ready state with the same parameters and return values as taskSpawn ()

Note that when wrapping lines in a macro, "\" is used to ensure the normal expansion of the macro.

Semaphore

Macros VX _ BINARY_SEMAPHORE (name), VX_COUNTING_SEMAPHORE (name), VX_MUTEX_SEMAPHORE (name), and VX_READ_WRITE_SEMAPHORE (name,numReaders) are used to declare four semaphores at compile time, respectively, and then fully instantiated using the corresponding semXInitialize (). The first parameter of semXInitialize () is name, and the following parameters are the same as those of semXCreate (). Therefore, the instantiation process is as follows

Message queue

The macro VX _ MSG_Q (name, max_msgs, max_msg_len) is used to declare message queues at compile time, and then fully instantiated using msgQInitialize (). The first parameter of msgQInitialize () is name, and the following parameters are the same as those of msgQCreate (). Therefore, the instantiation process is as follows

Watchdog

The macro VX _ WDOG (name) is used to declare the watchdog at compile time, and then fully instantiated using wdInitialize (). The argument to wdInitialize () is name. Therefore, the instantiation process is as follows

These are all the contents of the article "how vxworks implements static instantiation of kernel objects". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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