VxWorksSupports various inter-task communication mechanisms and provides various inter-task communication methods, mainly including the following:
BytesShared Memory, mainly for data sharing;
BytesSemaphores are used for basic mutex and task synchronization;
BytesMessage Queue and MPs queue, singleCPUMessage transmission;
BytesSocketAnd remote process call, used for inter-network task messagesTransfer;
BytesBinary signal for exception handling.
You can also use shared memory objects for tasks between multiple processors to implement inter-task communication.,But the system configuration is different..
1.1.1.Shared storage Zone
The simplest way to communicate between tasks is to use a shared storage area, that is, the sharing of related tasks belongs to the same memory area of their address space. Because all tasks exist in a single linear address space, data is shared between tasks. Global variables, linear queues, circular queues, linked lists, and pointers can all run in different contexts.Code.
1.1.2.Mutual Exclusion
When an address space is used for data exchange, it is very important to lock the memory to avoid conflicts. When two or more tasks read and write shared data, the final result depends on the precise sequence of the task running, and the error value may be obtained, in this way, other tasks cannot perform the same operation when a task uses a shared variable or file.It mainly involves methods such as interruption, preemption prohibition, and resource locking with semaphores.. (The scheduling mechanism of the VxWorks task is to preemptible the interruption, and preemptible the priority (the trigger condition is required, and the trigger condition is the interruption). The task uses taskdelay to directly discard the CPU)In general, Guanzhong disconnection is the most effective solution to mutual exclusion. However, for real-time applications, it prevents the system from responding to external events and cannot meet real-time requirements. Likewise, interruption delay is unacceptable.
1.1.3.Semaphores
VxWorksSemaphores provide the fastest inter-task communication mechanism, which is mainly used to solve the mutex and synchronization between tasks. There are three semaphores for different types of problems:
BytesBinary semaphoresThe fastest and most widely used, mainly used for synchronization or mutex;
BytesMutex semaphores are mainly used for priority inheritance, secure deletion, and backtracking;
BytesCounter
VxWorksAlso providesPOSIXThe Application of semaphores on semaphores and multi-processor.
1.1.1.Message Queue
Real-time applications consist of a series of independent and collaborative tasks. Semaphores provide efficient methods for synchronization and locking between tasks. In a single processor, message queues are used for message transmission between tasks. The message mechanism uses a Message Queue shared by various related processes, through which tasks send and receive messages. Full-duplex information transfer between tasks
1.1.2. MPs queue
I/O system provides a flexible message transmission mechanism, which is a drive pipedrv (provided by VxWorks ) virtual I/O device. The task can call the Standard I/O function to open, read, and write pipelines. When a task attempts to read data from an empty pipeline or write data to a full pipeline, the task is blocked. Similar to message queue, ISR can write information to the pipeline, but cannot read it from it. Like a I/O device, the pipeline has an advantage that a message queue does not have ---- call select () , the task waits for a series of
1.1.3.System implementation
WindSemaphores provide the same standardized interface for control of various types of semaphores. Only the semaphores type must be specified when you create a function.
Sembcreate ()Create (generate and activate) a binary semaphore
Semmcreate ()Create (generate and activate) A mutex semaphore
Semccreate ()Create (generate and activate) a counting semaphore
Semdelete ()Abort and free semaphores
Semtake()Obtain semaphores
Semgive ()Semaphores
Semflush ()Unlock all tasks waiting for a semaphore
WindMessage Queue Management:
Msgqcreate ()Create (generate and activate) A Message Queue
Msgqdelete ()Abort and free semaphores
Msgqsend ()Send messages to message queues
Msgqreceive ()Receive messages from a message queue