#1 What is a kernel application?
#2 Developing kernel application considerations
What is a kernel application?
The kernel application differs from the RTP program, which allows the same address space to be used in the kernel state as the operating system. As a result, it interferes with the operating system. It can be compiled into a kernel application module, or it can generate an image with a static connection to the operating system image. The application module can be dynamically loaded, so it is useful during the development and debugging phases, it does not have to recompile the operating system image, and can be stored in any kernel-supported file system, such as NFS, using the Romfs file system in Flash or ROM, or on disk. However, static links with the operating system are clearly more suitable for production use.
Because the kernel application runs in the kernel state, the hardware can be accessed directly, unlike RTP, which runs in the user state and cannot communicate directly with the hardware. The kernel application cannot be started directly, it must be started by another program or operating system (can be started by Shell or Workbench), or it can be started automatically at boot time by configuration.
Development considerations for use with C or C + + class libraries
|
Application Type |
C language |
C + + language |
|
Kernel applications |
VxWorks Local Library |
Dinkum C + + and embedded (abridged) C + + libraries |
|
RTP Application |
Dinkum C Library |
Dinkum C + + and embedded (abridged) C + + libraries |
Kernel Application Architecture
A content application is similar to a normal C + + application, but it does not require a traditional main function (unlike RTP, which requires main). It can be any function that starts all the tasks that need to be run.
1 voidMyappstartup (void)2 {3 Runfoo ();4Tidthis = Taskspawn ("Tthis", $,0, Stack_size,5(funcptr) Thisroutine,0,0,0,0,0,0,0,0,0,0);6Tidthat = Taskspawn ("tthat", -,0, Stack_size,7(funcptr) Thatroutine,0,0,0,0,0,0,0,0,0,0); 8Tidanother = Taskspawn ("Tanother", the,0, Stack_size,9(funcptr) Anotherroutine,0,0,0,0,0,0,0,0,0,0);Ten return(OK); One}VxWorks's header file
To use the VxWorks tool class library, you must include the appropriate header file. The VxWorks header file supports only ANSI C function prototypes and follows the ANSI x3.159-1989 standard.
- First, you must first include the header file VxWorks.h-it contains the basic definitions and types
- Second, you can include other header files, such as lstLib.h, as needed
- ANSI header files, most of which are compiler-independent, but with a few parts related to compilation (such as Stdef.h and Stdarg.h), the toolchain will automatically find the internal header file without the user's designation.
- ANSI C + + header files, each compiler has its own C + + library and C + + header files (such as Iosream and new). C + + header files are stored in the installation directory instead of/target/h when the compiler is installed.
- The-I compilation option, which specifies the path to the compiler search header file.
- Some header files contain a lower-level header file, such as Tylib.h using Rnglib.h.
- Vxwork private header files, usually with/*hidden*/./*end hidden*/included.
Custom header File
Do not use extern "C" statements in the custom header file to protect the system header files. All VxWorks system header files have been configured to be used by C and C + +. Therefore, you cannot force the use of C to connect these header file contents. The following is an error:
#ifdef _cplusplus #include <stdio.h> ;
extern "C" {==========> #ifdef _cplusplus
#endif extern "C" {
#include <stdio.h> #endif
Also, do not use extern "C" {#include <stdio.h>} in C + + source code files, but should use #include <stdio.h>
Static instantiation of Kernel objects
VxWorks core objects-such as tasks or semaphores-can be statically instantiated or dynamically instantiated, and static instantiation improves performance. There is a specific C macro to statically instantiate the kernel object.
Static instantiation
Static instantiation refers to the object being declared at compile time (using a specific VxWorks macro), usually a global object. Therefore, the memory is allocated at compile time without the need to allocate at run time. Object can be obtained directly at startup initialization.
With relatively static instantiation, dynamic instantiation involves runtime allocation, initialization before use, deletion of objects when deleted, and freeing of system memory, usually using malloc and new. With dynamic instantiation, you must consider running out of memory and, in addition, performing worse.
Dynamic InstantiationstructMy_object *Pmyobj;...pmyobj= (structMy_object *) malloc (sizeof(structmy_object));if(Pmyobj! =NULL) {Fooobjectinit (PMYOJB);return(OK);}Else{/*Failure Path*/return(ERROR);} Static instantiationstructmy_object Myobj;...fooobjectinit (&MYOJB);/*MYOBJ now ready for use*/Kernel objects that can be statically instantiated
- Task
- Signal Volume
- Message Queuing
- Watchdog clock
Statically instantiated code size
Objects declared at compile time do not occupy any space in the executable file, VxWorks image, or storage media. If it is declared but not initialized, the compiler stores the data in the BSS segment.
The benefits of static instantiation
- Faster access, more certainty
- Application logic is simpler because there is no need to consider out-of-memory issues.
- Static instantiation of an object does not fail unless the application itself is too large to load into system memory.
- The dynamic memory allocation module can be removed, making the VxWorks core smaller.
Application and Static instantiation
Static initialization provides better performance and benefits. If the object is never deleted, use static instantiation whenever possible. static instantiation should be used only in kernel applications, not in RTP.
Static instantiation Scope
Kernel objects are typically global variables because object IDs are commonly used to communicate and synchronize between tasks. However, it is not necessary to be global or function-scoped.
Use of macros
How the code is too long requires a backslash to be connected, as
MyTask = Vx_task_instantiate (mytask,100,0,4096,pentry,\
0,1,2,3,4,5,6,7,8,9);
Macro vx_task_instantiate for static instantiation of tasks
VxWorks Kernel Application