1.1. Application Software Development Guide
The VXWORKS system is a modular real-time operating system designed for embedded real-time applications. For the user, a real-time application is composed of a board-level support package BSP, an operating system kernel and user selection component, and interrupt service program ISR. The operating system provides users with a large number of system calls, which is the interface of the user and the operating system. In response to the characteristics of current development work and real-time systems, you should pay more attention to the following questions in the preparation of real-time applications:
2.5.1
Task division should be reasonable
Feature cohesive
Each work that is more close to functionality can be run as a task. If you are all-in-one messaging messages, affecting system efficiency, it is better to accomplish a separate module in the task.
2. Time urgency
For tasks that are relatively high in real-time requirements, you should run with high priority to ensure real-time response of events.
3. Periodic implementation principles
For a periodic execution, it should be run as a task, and the task is activated at a certain time interval.
2.5.2
Prevent dead lock, hunger and priority flip
The deadlock refers to a number of tasks due to the end of the non-recoverable operation due to the critical area that enters the other party. In programming is to pay attention to the prevention of deadlocks, one is to use the mutual exclusion resource in the same priority task, and must pay attention to the unlocking process of deadlock when used in different priority tasks.
Hungry means that the priority task has not been able to run the system resources (mainly referring to the CPU resource). The main reason for hunger is that the high priority task schedule is too frequent or the occupancy time is too long. The priority of reasonable allocation tasks and reasonable scheduling for higher priority tasks is to solve the hunger of non-fracture.
The priority of the task is a hot topic of the real-time multi-task operating system. It refers to the lower priority of the high priority task because of the mutual exclusive resource occupied by low priority tasks (higher than low priority but below high priority) The task of the level continues to seize. Some real-time multitasking operating systems provide protection mechanisms to prevent priority. In the case where the operating system does not provide protection, it is necessary to program a person to avoid the case where the priority flip is to avoid priority (such as using a mutually exclusive resource within the same priority), or take the corresponding means for processing (such as dynamic). Perform priority increased).
Note: VRTX and VxWorks provide their own prevention priority flip mechanism, PSOS does not provide protection mechanism.
2.5.3
Reentration of functions (Reentrant)
In a multi-task environment, the reusability of functions is important. The re-enter function is a process that can be called by multiple tasks, and the task does not have to worry about whether the data will be wrong when calling. When you write a function, just take into account the use of local variables (such as registers, variables in the stack), to protect the global variables to be used (for example, the function, the signal, the amount, etc.), such a function, must be one Reprinted functions.
In addition, whether the compiler has a library that can be reproduced, related to the operating system it serves, such as Borland C and Microsoft C / C under DOS, does not have a reusable function library, because DOS is a Single user single task operating system. In order to ensure that each task controls its own private variable, in a reusable C function, such variables must be called a local variable. The C compiler stores such variables on the call stack or register.
In VxWorks, multiple tasks can call the same sub-function or function library. VxWorks System Dynamic Connection Tools make this quite easy, this shared code makes the system more efficient and easy to maintain.
The VxWorks system mainly adopts several reusable technologies:
Ÿ Dynamic stack variable
Many subunies are just pure code, except for dynamic stack variables, there is no other data. The parameter of the call is called as the data of the subunies. This seed function is completely reusable, multiple tasks use this sub-function at the same time, which will not affect each other because they have their own stack space. Ÿ Protected global and static variables
Some function libraries contain public data, while calling multiple tasks is likely to cause damage to public data, be careful. The system uses the signal amount mutex to prevent the task from operating the critical area of the code.
Ÿ Task variable
Some common functions require a clear global or static variable value for each call. To meet this, the task variable provided by VxWorks allows 4-byte variables to be added to the task context, and when the task switching is also switched.
Write a reusable function, you must follow the following rules:
1. Stop all local variables are Auto (default) or register type.
2. Try not to use Static or Extern variables. If necessary, use a mutex mechanism to protect.
2.5.4
Use the name to access resources
These resources are called through the task name, the message queue name, and the signal quantity is called to ensure the reliability of the application system, and it is also easy to read. For example, the system calls taskName (), tasknametoid (), taskisself (), etc., it is convenient for users to manage resources, more intuitive.
2.5.5
User task priority determination
Vxworks
Priority in the system is divided into
256
Level, from
0
Until
255
,among them
0
For the highest priority,
255
Minimum priority
.
The priority of the task is assigned when task is created
,
But in the task runtime, you can call through system.
TaskPrioritySet ()
Dynamically change its priority. When the operating system starts successfully on the target board, the system-level task is running, managing the communication between the host and the target, so the user task priority is lower than the system level task, which is generally the highest
150
. At the same time, for the determination of the user's task priority, how to make good cooperation between the tasks, it is also important to give the user according to the urgency of the task and the actual situation, the exploration process is also important.