Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15:...
-
Upload
nguyenhuong -
Category
Documents
-
view
244 -
download
4
Transcript of Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15:...
![Page 1: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/1.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 1
INTER-PROCESS COMMUNICATION AND SYNCHRONISATION OF
PROCESSES, THREADS and TASKS:
Lesson-16: Mailbox
![Page 2: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/2.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 2
1. IPC Mailbox functions
![Page 3: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/3.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 3
• Some OSes provide the mailbox and queue both IPC functions
• When the IPC functions for mailbox are not provided by an OS, then the OS employs queue for the same purpose.
Queue and MailboxQueue and Mailbox
![Page 4: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/4.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 4
MailboxMailbox
• Mailbox (for message) is an IPC through a message-block at an OS that can be used only by a single destined task.
![Page 5: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/5.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 5
Mailbox Mailbox ……
• A task on an OS function call puts (means post and also send) into the mailbox only a pointer to a mailbox message
• Mailbox message may also include a header to identify the message-type specification.]
![Page 6: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/6.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 6
Mailbox IPC featuresMailbox IPC features
• OS provides for inserting and deleting message into the mailbox message-pointer. Deleting means message-pointer pointing to Null.
• Each mailbox for a message need initialization (creation) before using the functions in the scheduler for the message queue and message pointer pointing to Null.
![Page 7: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/7.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 7
Mailbox IPC features…Mailbox IPC features…
• There may be a provision for multiple mailboxes for the multiple types or destinations of messages. Each mailbox has an ID.
• Each mailbox usually has one message pointer only, which can point to message.
![Page 8: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/8.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 8
Mailbox Types
![Page 9: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/9.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 9
Mailbox IPC features …Mailbox IPC features …
• When an OS call is to post into the mailbox, the message bytes are as per the pointed number of bytes by the mailbox message pointer.
![Page 10: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/10.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 10
2. Mailbox Related Functions at the OS2. Mailbox Related Functions at the OS
![Page 11: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/11.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 11
![Page 12: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/12.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 12
Tasks j sending a message-pointer into a mailbox and task k receiving that
Task jMailbox mb1
Post mb1, *mj
OS Mailbox functionsCreate, Query, Post,
Pend, Accept, Delete
Task CTask CTask kTask k
Pend mb1
*mb1*mb1
![Page 13: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/13.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 13
SectionSection of codes in the tasks B, C, and D waiting for messages of codes in the tasks B, C, and D waiting for messages mm1, 1, mm2 and 2 and mm3 into mailboxes3 into mailboxes
Task A Task B
Post m1
Pend m1
Task CTask C
Post m2
Pend m2
Post m3
Task DTask D
Pend m3
![Page 14: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/14.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 14
Task i sending message pointer *mi to initiate a task section waiting to take a message i before it could run
Task i
Task j
Send mi
Waitmi
OSOS
signal mask j
*mi Not Null
*mi = NULL
Start
*mi = NULL
![Page 15: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/15.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 15
Mailbox IPC functionsMailbox IPC functions1. OSMBoxCreate creates a box and
initializes the mailbox contents with a NULL pointer at *msg .
2. OSMBoxPost sends at *msg, which now does not point to Null.
• An ISR can also post into mailbox for a task
![Page 16: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/16.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 16
Mailbox IPC functions…Mailbox IPC functions…
3. OSMBoxWait (Pend) waits for *msg not Null, which is read when not Null and again *msg points to Null.
• The time out and error handling function can be provided with Pend function argument.
• ISR not permitted to wait for message into mailbox. Only the task can wait
![Page 17: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/17.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 17
Mailbox IPC functions…Mailbox IPC functions…4. OSMBoxAccept reads the message at
*msg after checking the presence yes or no [No wait.] Deletes (reads) the mailbox message when read and *msg again points to Null
• An ISR can also accept mailbox message for a task
5. OSMBoxQuery queries the mailbox *msg.
![Page 18: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/18.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 18
3. IPC Queue functions Application Example
![Page 19: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/19.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 19
int *m_j; A global variable integer pointer...; ...; ...; static void Task_j (void *taskPointer) {...while (1) {...; ...; ...; & m_i = 8; ...; ...; ...; OSMboxPost (m_j); /* after this instruction executes the next task section can operate on the m_j */...; ...; ...;}; }
Task_Task_jj sending an integer value sending an integer value mmjj
![Page 20: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/20.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 20
static void Task_k (void *taskPointer) {...while (1) {...; ...; ...;OSMboxPend (m_j); /* OSMboxPend waits for mailbox message m_i and when available m_i, reset *m_i = NULL and proceed to next statement */...; ...; ...;};}
Task_kTask_k waiting for the mwaiting for the mii
![Page 21: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/21.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 21
Task Task Read_AmountRead_Amount in ACVMin ACVM
static void Task Read-Amount (void *taskPointer) {
.while (1) {./* Codes for reading the coins inserted into
the machine */
![Page 22: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/22.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 22
Task Task Read_AmountRead_Amount posting amount posting amount information information in ACVMin ACVM
/* Codes for writing into the mailbox full amount message if cost of chocolate is received*/
OSMboxPost (mboxAmt, fullAmount) /* Post for the mailbox message and fullAmount, which equaled null now equals fullAmountmessage pointer*/
.};
![Page 23: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/23.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 23
Chocolate delivery task in ACVMChocolate delivery task in ACVM
static void Chocolate delivery task (void *taskPointer) {
.while (1) {.
![Page 24: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/24.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 24
Chocolate delivery task waiting for Chocolate delivery task waiting for message in ACVMmessage in ACVM
/* IPC for requesting full amount message */fullAmountMsg = OSMboxPend (mboxAmt,
20, *err) /* Wait for the mailbox mboxAmtmessage for 20 clock ticks and error if message not found. mboxAmt becomes null after message is read.
.};
![Page 25: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/25.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 25
Task_Task_User_Keypad_InputUser_Keypad_Input in ACVMin ACVM
static void Task_User_Keypad_Input (void *taskPointer) {
.while (1) {./* Codes for reading keys pressed by the user
before the enter key */
![Page 26: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/26.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 26
Task_Task_User_Keypad_InputUser_Keypad_Input posting amount posting amount information information in ACVMin ACVM
/* Codes for writing into the mailbox */ OSMboxPost (mboxUser, userInput) /* Post
for the mailbox message and userInput, which equaled null now equals userInputmessage pointer*/
.};
![Page 27: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/27.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 27
Task_DisplayTask_Display in ACVMin ACVM
static void Task_Display (void *taskPointer){
.while (1) {.
![Page 28: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/28.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 28
Task_DisplayTask_Display waiting for a message in waiting for a message in ACVMACVM
/* IPC for waiting for User input message */ UserInputMsg = OSMboxPend (mboxUser,
20, *err) /* Wait for the mailbox mboxUsermessage for 20 clock ticks and error if message not found. mboxUser becomes null after message is read.
./* Code for display of user Input */
![Page 29: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/29.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 29
Task_DisplayTask_Display waiting for another message waiting for another message in ACVMin ACVM
TimeDateMsg = OSMboxPend (timeDate, 20, err) /* Wait for the mailbox message timeDate.
/* Code for display TimeDateMsg Time: hr:mm Date: month:date */
.};
![Page 30: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/30.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 30
SummarySummary
![Page 31: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/31.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 31
• OS provides the IPC functions • Create, Post, PostFront, Pend, Accept, Flush
and Query for using message at mailbox. • The time out and error handling function
can be provided with Pend function argument.
We learntWe learnt
![Page 32: Chapter-8 L15: Embedded Systems - Architecture, Programming and · PDF fileChapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill,](https://reader035.fdocuments.us/reader035/viewer/2022081723/5a998c7a7f8b9a30358d98f7/html5/thumbnails/32.jpg)
2008 Chapter-8 L15: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 32
End of LLesson-16: Mailbox