RTOS conceptsII UnitVI Contents Mailboxes Message queues Pipes
![RTOS concepts-II Unit-VI RTOS concepts-II Unit-VI](https://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-1.jpg)
RTOS concepts-II Unit-VI
![Contents • • • Mailboxes Message queues Pipes Signals Event registers Contents • • • Mailboxes Message queues Pipes Signals Event registers](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-2.jpg)
Contents • • • Mailboxes Message queues Pipes Signals Event registers
![Inter-process communication • Tasks must be able to communicate with one another to coordinate Inter-process communication • Tasks must be able to communicate with one another to coordinate](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-3.jpg)
Inter-process communication • Tasks must be able to communicate with one another to coordinate their activities to share the data. • IPC means that a process (scheduler, task or ISR) generates some information by setting or resetting a flag or value, or generates an output so that it lets another process take note of it or use it. • IPCs in multiprocessor system are used to generate information about certain sets of computations finishing on one processor and let the other processors take note of it.
![Two ways for IPC 1. global data , 2. sending messages Global data: by Two ways for IPC 1. global data , 2. sending messages Global data: by](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-4.jpg)
Two ways for IPC 1. global data , 2. sending messages Global data: by setting global variables. Usage of global variables create two problems. (i) Shared data problem (ii) It cannot prevent a message from being accessed by other tasks
![Sending messages i) iii) iv) Semaphores and mutexes Queues, pipes and mailboxes Signals Event Sending messages i) iii) iv) Semaphores and mutexes Queues, pipes and mailboxes Signals Event](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-5.jpg)
Sending messages i) iii) iv) Semaphores and mutexes Queues, pipes and mailboxes Signals Event registers etc.
![Printer example for IPC • A task that runs a print function. • The Printer example for IPC • A task that runs a print function. • The](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-6.jpg)
Printer example for IPC • A task that runs a print function. • The scheduler should let the other tasks share this task. • When the printer becomes available, an IPC from the print task is generated and the scheduler takes note of it. • Other tasks take note of it through the scheduler.
![Multi-line display example for IPC • It is a task for a multi-line display Multi-line display example for IPC • It is a task for a multi-line display](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-7.jpg)
Multi-line display example for IPC • It is a task for a multi-line display of outputs and another task for displaying current time on the last line. • When the multi-line display task finishes the display of the last line, an IPC from the display task is generated and the scheduler takes note of it. • Another task continuously updating time-can take and generate an IPC output for the current time. • The need for IPC also arises in a client-server network.
![Mailboxes • Mailboxes are also called as message exchange, is typically a pointer size Mailboxes • Mailboxes are also called as message exchange, is typically a pointer size](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-8.jpg)
Mailboxes • Mailboxes are also called as message exchange, is typically a pointer size variable • A message mailbox is an IPC message-block that can be used only by a single destined task. • Through a service provided by the kernel, a task or an ISR can deposit a message into the mail box. • Similarly, one or more tasks can receive messages through a service provided by the kernel. • A waiting list is associated with each mailbox in case more than one task wants to receive messages through the mailbox.
![Mailboxes • Mailbox object is just like postal mailbox. Post a message Task 1 Mailboxes • Mailbox object is just like postal mailbox. Post a message Task 1](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-9.jpg)
Mailboxes • Mailbox object is just like postal mailbox. Post a message Task 1 mailbox Read the message Task 2
![Mailboxes types at the different RTOSs Mail Box type permitted by an RTOS Multiple Mailboxes types at the different RTOSs Mail Box type permitted by an RTOS Multiple](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-10.jpg)
Mailboxes types at the different RTOSs Mail Box type permitted by an RTOS Multiple unlimited Messages Queuing Up One message per Mail Box Multiple messages with a priority parameter for each message
![Mailbox services provided by the kernel • Initialize the contents of the mailbox. The Mailbox services provided by the kernel • Initialize the contents of the mailbox. The](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-11.jpg)
Mailbox services provided by the kernel • Initialize the contents of the mailbox. The mailbox may or may not contain a message. • Deposit a message into the mailbox (POST) • Wait for a message to be deposited into the mailbox (PEND) • Get a message from a mailbox if existing (ACCEPT) • A provision for one message-write per box and the next message to be accepted only if the previous one is read. • A mailbox with a provision for only one message per box becomes full with one message.
![A mobile phone LCD display example for mailbox • When the time message from A mobile phone LCD display example for mailbox • When the time message from](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-12.jpg)
A mobile phone LCD display example for mailbox • When the time message from a clock process arrives, the time is displayed at the right cornet of the last line. • When the message from another task is to display a phone number, it is displayed at the middle line.
![Mailbox management functions Create a mailbox -- RTOS_Box. Create Delete a mailbox -- RTOS_Box. Mailbox management functions Create a mailbox -- RTOS_Box. Create Delete a mailbox -- RTOS_Box.](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-13.jpg)
Mailbox management functions Create a mailbox -- RTOS_Box. Create Delete a mailbox -- RTOS_Box. Delete Query a mailbox – RTOS_Box. Query Wait for a mailbox – RTOS_Box. Wait Post a message into the mail box -RTOS_Box. Write • Read a message from the mailbox – RTOS_Box. Accept • • •
![Message queue • Message queue is used to send one or more messages to Message queue • Message queue is used to send one or more messages to](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-14.jpg)
Message queue • Message queue is used to send one or more messages to a task. • It is basically an array of mailboxes. • Waiting • Timeout option
![Features of message queues 1. Either one process (task) or a set of processes Features of message queues 1. Either one process (task) or a set of processes](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-15.jpg)
Features of message queues 1. Either one process (task) or a set of processes (tasks) can use the queue. 2. A read (deletion) operation from a queue is in a FIFO mode. 3. Generally the queue is a circular queue and the read is like a ring of bytes in a buffer. 4. For reading, one can assign priorities.
![Message queues Array of mailboxes Task 1 Task 2 Task 3 Sending Tasks Task Message queues Array of mailboxes Task 1 Task 2 Task 3 Sending Tasks Task](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-16.jpg)
Message queues Array of mailboxes Task 1 Task 2 Task 3 Sending Tasks Task 1 Task 2 Task 3 Receiving Tasks
![Continued. . • At the time of creating a queue, the queue is given Continued. . • At the time of creating a queue, the queue is given](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-17.jpg)
Continued. . • At the time of creating a queue, the queue is given a • Name or ID • Queue length • Sending task waiting list • Receiving task waiting list
![Common RTOS features of message queues • Most RTOSs require that you initialize your Common RTOS features of message queues • Most RTOSs require that you initialize your](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-18.jpg)
Common RTOS features of message queues • Most RTOSs require that you initialize your queues before you use them, by calling a function provided for this purpose. • An identification should be provided to which you want to write or read from the queue. • Each queue either has a user defined size or prefixed size assigned by the scheduler. • When the queue is full, error might occur • When the queue is empty, error might occur • Type and amount of data you can write into
![Applications of message queues • • Taking the input from a keyboard To display Applications of message queues • • Taking the input from a keyboard To display](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-19.jpg)
Applications of message queues • • Taking the input from a keyboard To display the output Reading voltages from sensors or transducers Data packet transmission in a network
![Types • One way comm. With Ack • Two-way comm. • Broadcasting Types • One way comm. With Ack • Two-way comm. • Broadcasting](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-20.jpg)
Types • One way comm. With Ack • Two-way comm. • Broadcasting
![One way communication with ack Message queue Task 1 Task 2 semaphore One way communication with ack Message queue Task 1 Task 2 semaphore](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-21.jpg)
One way communication with ack Message queue Task 1 Task 2 semaphore
![Two way communication Message queue Task 1 Task 2 Two way communication Message queue Task 1 Task 2](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-22.jpg)
Two way communication Message queue Task 1 Task 2
![Broadcasting Message queue Task Broadcasting Message queue Task](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-23.jpg)
Broadcasting Message queue Task
![Kernel message queue services • Initialize a queue. It is always assumed to be Kernel message queue services • Initialize a queue. It is always assumed to be](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-24.jpg)
Kernel message queue services • Initialize a queue. It is always assumed to be empty after initialization. • Deposit a message into the queue (POST) • Wait for a message to be deposited into the queue (PEND) • Get a message from a queue (ACCEPT)
![Message queue management functions • • • Create a queue -- RTOS_Qcreate Delete a Message queue management functions • • • Create a queue -- RTOS_Qcreate Delete a](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-25.jpg)
Message queue management functions • • • Create a queue -- RTOS_Qcreate Delete a queue Flush a queue --RTOS_Qflush Post a message in queue – RTOS_Qwrite Post a message in front of queue -- RTOS_Qpostfront Read message from queue -- RTOS_Qaccept Broadcast a message Show queue information Show queue waiting list – RTOS_Qwait
![Pipes • Pipes are like message-queue functions. • A message pipe or simply pipe Pipes • Pipes are like message-queue functions. • A message pipe or simply pipe](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-26.jpg)
Pipes • Pipes are like message-queue functions. • A message pipe or simply pipe in strict sense is an IPC queue between two given interconnected tasks or two sets of tasks. • Unlike queues and mailboxes, pipes have unlimited size. • In a pipe there may be no fixed number of bytes per message. • Example: client-server network.
![Pipes Task Write data to pipe Task Pipe Reads data from pipe • Task-to-task Pipes Task Write data to pipe Task Pipe Reads data from pipe • Task-to-task](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-27.jpg)
Pipes Task Write data to pipe Task Pipe Reads data from pipe • Task-to-task and ISR-to-task data transfer can take place using pipes.
![Pipes for inter-process communication Task • Pipes can be used for inter-process communication. • Pipes for inter-process communication Task • Pipes can be used for inter-process communication. •](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-28.jpg)
Pipes for inter-process communication Task • Pipes can be used for inter-process communication. • One task may send the data packets through one pipe and the other task may send acknowledgements through the other
![While using a pipe • 1. 2. 3. 4. You have to define Pipe While using a pipe • 1. 2. 3. 4. You have to define Pipe](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-29.jpg)
While using a pipe • 1. 2. 3. 4. You have to define Pipe ID Length Maximum length (not defined in some RTOS) Initial values
![Common RTOS features of pipes • Each pipe for a message may need initialization Common RTOS features of pipes • Each pipe for a message may need initialization](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-30.jpg)
Common RTOS features of pipes • Each pipe for a message may need initialization before using the functions in the scheduler for the message pipe. • There may be a provision for multiple connections of the pipes for the multiple destinations of the messages. A number of clients can thus connect to a server.
![Pipes • Pipes are used as shell commands in Unix/Linux systems • Symbol is Pipes • Pipes are used as shell commands in Unix/Linux systems • Symbol is](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-31.jpg)
Pipes • Pipes are used as shell commands in Unix/Linux systems • Symbol is | • Create a pipe • Open a pipe • Close a pipe • Read from a pipe • Write to the pipe
![Signals can be passed to indicate an event A ‘signal’ provides the shortest message. Signals can be passed to indicate an event A ‘signal’ provides the shortest message.](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-32.jpg)
Signals can be passed to indicate an event A ‘signal’ provides the shortest message. It is a one-bit output from a process for IPC. What are signals in IPC? Signals are the flags that are used for the IPC functions for synchronizing. It is the s/w equivalent of the flag at a register that sets on a h/w interrupt. • Many RTOS do not support signals • •
![Continued. . • A signal is just a flag that is shared and used Continued. . • A signal is just a flag that is shared and used](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-33.jpg)
Continued. . • A signal is just a flag that is shared and used by another interrupt servicing process for signal handling function. • A signal raised by one process forces another process to interrupt and catch that signal. • Hence, signals are handled only by very high priority processes as it may disrupt the usual schedule and priority inheritance.
![Exception handling by signals • An important use of signal is to handle exceptions. Exception handling by signals • An important use of signal is to handle exceptions.](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-34.jpg)
Exception handling by signals • An important use of signal is to handle exceptions. • A signal reports an error during running a task and then lets the scheduler initiate an errorhandling process or function. • The handling is through the use of the ISR handling functions. • Unix and Linux OSs have 31 different types of signals for handling various events.
![Signal management functions • • • Install a signal handler Remove an installed signal Signal management functions • • • Install a signal handler Remove an installed signal](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-35.jpg)
Signal management functions • • • Install a signal handler Remove an installed signal handler Send a signal to another task Block a signal from being delivered Unblock a blocked signal Ignore a signal
![Event Registers • A task can have an event register in which the bits Event Registers • A task can have an event register in which the bits](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-36.jpg)
Event Registers • A task can have an event register in which the bits correspond to different events • Each of the bits in the event register is an event flag.
![Event Register management function calls • • • Create an event register Delete an Event Register management function calls • • • Create an event register Delete an](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-37.jpg)
Event Register management function calls • • • Create an event register Delete an event register Query an event register Set an event flag Clear an event flag
![Summary • The RTOS handles inter process communication between multiple tasks. • The RTOS Summary • The RTOS handles inter process communication between multiple tasks. • The RTOS](http://slidetodoc.com/presentation_image_h2/40ea499385f9da578bdac6dc22aa6ec0/image-38.jpg)
Summary • The RTOS handles inter process communication between multiple tasks. • The RTOS provides the following IPCs: Signals, Semaphores, mutexes, queues, mailboxes, pipes, event registers etc. • A mailbox may either provide for only one message or multiple messages in an RTOS. • A queue is a collection or series of mailboxes. • A pipe is a queue or stream of messages that connects the two tasks. • Signal is one-bit output to indicate an event.
- Slides: 38