Книга: Real-Time Concepts for Embedded Systems
15.7.1 Data Transfer with Flow Control
15.7.1 Data Transfer with Flow Control
Task-to-task communication commonly involves data transfer. One task is a producer, and the other is a data consumer. Data processing takes time, and the consumer task might not be able to consume the data as fast as the producer can produce it. The producer can potentially overflow the communication channel if a higher priority task preempts the consumer task. Therefore, the consumer task might need to control the rate at which the producer task generates the data. This process is accomplished through a counting semaphore, as shown in Figure 15.17. In this case, the counting semaphore is a permission to produce data.
Figure 15.17: Using counting semaphores for flow control.
The data buffer in this design pattern is different from an RTOS-supplied message queue. Typically, a message queue has a built-in flow control mechanism. Assume that this message buffer is a custom data transfer mechanism that is not supplied by the RTOS.
As shown in Figure 15.17, task #1 is the data producer, while task #2 is the consumer. Task #1 can introduce data into the buffer as long as the task can successfully acquire the counting semaphore. The counting semaphore may be initialized to a value less than the maximum allowable token value. Task #2 can increase the token value with the give operation and may decrease the token value by the take operation depending on how fast the task can consume data. Listing 15.2 shows the pseudo code for this design pattern.
Listing 15.2: Pseudo code for data transfer with flow control.
data producing task
Acquire(Counting_Semaphore)
Produce data into msgQueue
data consuming task
Consume data from MsgQueue
Give(Counting_Semaphore)
- 15.7.1 Data Transfer with Flow Control
- 15.7.2 Asynchronous Data Reception from Multiple Data Communication Channels
- 15.7.3 Multiple Input Communication Channels
- 15.7.4 Using Condition Variables to Synchronize between Readers and Writers
- 15.7.5 Sending High Priority Data between Tasks
- 15.7.6 Implementing Reader-Writer Locks Using Condition Variables
- 8.3.2 Data Flow Types
- Flow Control
- Информация заголовочной страницы (Database header)
- Database dialect
- DATABASE CACHE SIZE
- Introduction to Microprocessors and Microcontrollers
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Data sending and control session
- SCTP DATA chunk
- Drawbacks with restore
- 7. AGGREGATION WITH INDEPENDENT WORKS
- Data Binding Using the GridView Control