Introduction to uCOS-II V2.6... Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6Course References • MicroC/OS-II The Real-Time Kernel, 2nd Edition, by Jean J... Message Mailboxes• A
Trang 1Introduction to uCOS-II V2.6
Trang 2About SwiftACT
• A Technology services startup company
o Under establishment
• Areas of specialties:
o Mobile telecommunication services development
o Embedded systems development
• Types of services:
o Consultation
o Managed services
o Sourcing
o Training
Trang 3Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
About Me
• Graduated 2004
o ECE, ASU: 5 yrs distinction
• 5+ years in embedded systems development
o SDLC, Apps, MW, DD, Porting,
• 3+ years in SW engineering
o PSP, CMMI, Systematic reuse,
• 3+ years in SW testing
o IBM certified, ISTQB certified,
Trang 4• Materials in this course is the property of Amr Ali Abdel-Naby
• Reproduction or transmission of the materials in any manner without the copyright owner permission is a law violation
Trang 5Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Course References
• MicroC/OS-II The Real-Time Kernel, 2nd Edition, by Jean J Labrosse
Trang 6• Introduction to µC/OS-II
• Kernel Structure
• Task Management
• Time Management
• Semaphore Management
• Mutual Exclusion Semaphores
• Event Flag Management
• Message Mailbox Management
• Message Queue Management
• Memory Management
Trang 7Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Outline
• Introduction to µC/OS-II
• Kernel Structure
• Task Management
• Time Management
• Semaphore Management
• Mutual Exclusion Semaphores
• Event Flag Management
• Message Mailbox Management
• Message Queue Management
• Memory Management
Trang 8Message Mailboxes
• A message mailbox is
a μC/OS-II object that allows a task or an ISR to send pointer-sized variable to another task.
OSMboxCreate()
Message OSMboxPost()
OSMboxAccept()
OSMboxPost()
OSMboxPend() OSMboxAccept() OSMboxQuery()
ISR Task
Task
Trang 9Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Creating a Mailbox, OSMboxCreate
OS_EVENT *OSMboxCreate (void *msg)
• msg: A pointer to a message to deposit in the mailbox
o If null, mailbox is empty & used to signal occurrence of events
o If ! null, mailbox is used to access shared resources
• Return value:
o Non-null for successful creation
o Null for failure
Trang 10Deleting a Mailbox, OSMboxDel
OS_EVENT *OSMboxDel (OS_EVENT *pevent, INT8U opt, INT8U
*err)
• pevent: A pointer to the mailbox to be deleted
• opt: Delete options
o Delete always
o Delete if no pending tasks
• err:
o No error
o Called from ISR
o Invalid option
o There are tasks pending.
o pevent is null.
o pevent is not a mailbox.
Trang 11Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Deleting a Mailbox, OSMboxDel cont’d
OS_EVENT *OSMboxDel (OS_EVENT *pevent, INT8U opt, INT8U
*err)
• Return value: Null if successful
Trang 12Waiting for a Message at a Mailbox, OSMboxPend
void *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U
*err)
• pevent: A pointer to the mailbox to pend to
• timeout:
o 0 wait for ever
o !0 wait with specific timeout
• err:
o No error
o Timeout
o pevent is not a mailbox.
o pevent is null.
o Called from ISR
Trang 13Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Sending a Message to a Mailbox, OSMboxPost
INT8U OSMboxPost (OS_EVENT *pevent, void *msg)
• pevent: A pointer to the mailbox to post to
• msg: A pointer to the message to send
• Return value:
o No error
o Mailbox is full.
o pevent is not a mailbox.
o pevent is null.
o Posting a null pointer
Trang 14Sending a Message to a Mailbox, OSMboxPostOpt
INT8U OSMboxPostOpt (OS_EVENT *pevent, void *msg, INT8U opt)
• OSMboxPostOpt = OSMboxPost + options
• opt:
o Post to a single waiting task
o Post to all tasks waiting
Trang 15Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Getting a Message without Waiting, OSMboxAccept
void *OSMboxAccept (OS_EVENT *pevent)
• pevent: A pointer to the mailbox to pend to
• Return value:
o !Null Message received
o Null Case of error or mailbox is empty
Trang 16Obtaining the Status of a Mailbox, OSMboxQuery
INT8U OSMboxQuery (OS_EVENT *pevent, OS_MBOX_DATA
*pdata)
• pevent: A pointer to the desired mailbox
• pdata: A pointer to the returned mailbox information
• Return value:
o No error
o pevent is not a mailbox.
o pevent is null.
Trang 17Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Using a Mailbox as a Binary Semaphore
OS_EVENT *MboxSem;
void Task (void *pdata){
INT8U err;
for (;;) { OSMboxPend(MboxSem, 0, &err); /* Obtain access to resource */ /* Task has semaphore, access resources */
OSMboxPost(MboxSem, (void*)1); /* Release access to resource */
} }
Trang 18Using a Mailbox Instead to Signal Occurrence of Events
OS_EVENT *MboxTimeDly;
void Task1(void *pdata){
INT8U err;
for (;;) { OSMboxPend(MboxTimeDly, timeout, &err); /* Wait for event */
/* Code after time delay */
} } void Task2(void *pdata){
INT8U err;
for (;;) { OSMboxPost(MboxTimeDly, (void *)1); /* Signal event */
} }