Real Time
Real Time
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 237
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 238
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 239
Homework
• Study the examples related to monitors from the reference
manual
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 240
221
Inter-Task Communication, Message Passing
• How do we communicate information to other tasks?
• Ways to resolve inter-task communication:
1. Global data … here we need to ensure exclusive access…
2. Sending messages – messages can be sent to an intermediate
object called a message queue or directly to a tasks since uC/OS-
III implements built in task message queue
• What is a message?
• A message consists of a pointer to data, a variable containing the
size of the data pointed to, and a timestamp
• The message contents must always remain in scope since the data
is actually sent by reference instead of by value.
Week 5 - Real Time Operating Systems (III) 241
Message Queue
A message queue is a kernel object allocated by the
application
• A message queue must be created first
• Multiple tasks can wait on a message queue
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 243
224
Task Message Queue
• A message queue is built into each task and a user can send messages
directly to a task
• This feature can be more efficient than using a separate message queue
object
• Setting OS_CFG_TASK_Q_EN to DEF_ENABLED in os_cfg.h enables task
message queue services
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 244
225
Example of Bilateral Rendez-Vous Using
Message Queue
• Two tasks can synchronize
their activities by using two
message queues
• Each message queue holds a
maximum of one message i n
this process
• Each task has its rendez-vou s
point:
• Where it sends a message to
the other task and waits for a
message to come from that
task
• Notice the utilization of two
queues
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 246
227
Flow Control
• Task-to-task communication can
involve data transfers such that
one task produces data while the
other consumes it.
• Due to time differences in
producing and processing times
it is possible for the producer to
overflow the message queue
• Specifically, if a higher-priority task
preempts the consumer.
• Solutions: add flow control in the
process as shown …?
• Message queue and counting
semaphore Message queue and counting semaphore solution
• Built in task objects
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 248
229
Flow Control with
Built in Task Objects
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 249
230
Keeping the Data
in Scope
• In the case of inter-task communications using message
queues, the messages are in form of pointer so,
• the data must remain static until the receiver of the data
completes its processing
• The sender must not touch the sent data
• Solution: use the fixed-size memory partition manager
provided with OS to dynamically allocate and free memory
blocks used to pass the data
• Example: UART device sends messages in packet format
• (1) … a UART generates an interrupt … UART ISR analyzes
the character for start-of-packet, end-of-packet or packet
body character
• (2): … start-of-packet … a new buffer is obtained …
• (3) … packet character… place the byte in the buffer …
• (4) … end-of-packet … post the address of the buffer …
• (5) … when the Rx task is HPT, retrieve the packet …
• (6) … after Rx task finished, return the buffer …
Week 5 - Real Time Operating Systems (III) 250
231
UART_ISR
pseudo-
code
ENGG4420: Developed
Week 5 - Real by RaduSystems
Time Operating Muresan,
(III)F22 261
242
Using Memory Partitions