Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6Creating a Task, OSTaskCreate INT8U OSTaskCreate void *taskvoid *pd, void *pdata, OS_STK *ptos, INT8U prio • task: A pointer to the ta
Trang 1Introduction to uCOS-II V2.6
Trang 2Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
About SwiftACT
• A Technology services startup company
o Under establishment
• Areas of specialties:
o Mobile telecommunication services development
o Embedded systems development
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
Trang 4Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Copyright
• 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 6Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
• 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
• Mutual Exclusion Semaphores
• Event Flag Management
• Message Mailbox Management
• Message Queue Management
• Memory Management
Trang 8Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Task Management APIs
• Available task operations are:
o Task creation
o Stack checking
o Task deletion
o Requesting a task deletion
o Changing a task’s priority
o Task suspension
o Task resumption
o Getting task’s info
o Task name manipulation
Trang 9Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Creating a Task, OSTaskCreate
INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK
*ptos, INT8U prio)
• task: A pointer to the task's code
• pdata: A pointer to an optional data area which can be used to pass parameters to the task when the task first executes
• ptos: A pointer to the task's top of stack
• prio: The task's priority
• Return value:
o No error
o Priority exist
o Invalid priority
Trang 10Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Creating a Task, OSTaskCreateExt
INT8U OSTaskCreateExt (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt)
• OSTaskCreate +
• id: Task’s ID, not used currently
• pbos: A pointer to the task's bottom of stack
• stk_size: A pointer to the task's top of stack
• pext: A pointer to a user supplied memory location which is used as a TCB extension
• opt: Additional information (or options) about the behavior of the task
Trang 11Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Task Stacks
• Each task has its own stack
o It must be:
Declared as OS_STK
Consistent & contiguous memory
• It can be allocated static
• Or dynamic OS_STK MyTaskSTack[stack_size];
OS_STK *pstk;
pstk = (OS_STK*)malloc(stack_size);
Trang 12Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Task Stacks cont’d
• Dynamic allocation may suffer from fragmentation
• Your code should support stacks that grow in either direction
A (1KB)
C (1KB)
B (1KB)
#else OSTaskCreate(task, pdata, &TaskStack[stack_size-1], prior);
#endif
Trang 13Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Stack Checking
• Assume stack is cleared at the beginning
Trang 14Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Stack Checking, OSTaskStkChk
INT8U OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata)
• prio: The task priority
• pdata: A pointer to stack data
• Return value:
o No error
o Invalid priority
o Task does not exist.
o Task options does not support stack checking.
Trang 15Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Deleting a Task, OSTaskDel
INT8U OSTaskDel (INT8U prio)
• prio: Priority of the task to delete
• Return value:
o No error
o Invalid priority.
o Task does not exist.
o Deleting idle task
o Deleting a task from ISR
Trang 16Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Requesting to Delete a Task
• A deleted task should delete its resources as well
o To avoid leaks
• The OSTaskDelReq is the keyword
void RequestorTask(void * pdata){
} else{
/* Application code*/
}
}
Trang 17Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Requesting to Delete a Task, OSTaskDelReq
INT8U OSTaskDelReq (INT8U prio)
• prio: Priority of the task to be deleted
• Return value:
o No error
o Invalid priority
o Task does not exist.
o Deleting idle task
o Deleting a task from ISR
Trang 18Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Changing a Task’s Priority, OSTaskChangePrio
INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
• oldprio: The old priority
• newprio: The new priority
• Return value:
o No error
o Invalid priority
o Task to change priority does not exist.
o New priority already exists.
o Changing IDLE priority
Trang 19Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Resuming a Task, OSTaskResume
INT8U OSTaskResume (INT8U prio)
• prio: The priority of the task to resume
• Return value:
o No error
o Invalid priority
o Task is not suspended.
o Task does not exist.
Trang 20Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Suspending a Task, OSTaskSuspend
INT8U OSTaskSuspend (INT8U prio)
• prio: The priority of the task to suspend
• Return value:
o No error
o Invalid priority
o Suspending idle task
o Task does not exist
Trang 21Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Getting Info About a Task, OSTaskQuery
INT8U OSTaskQuery (INT8U prio, OS_TCB *pdata)
• prio: The priority of the task to obtain its information
• pdata: A pointer to returned task information
Trang 22Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Getting a Task’s Name, OSTaskNameGet
INT8U OSTaskNameGet (INT8U prio, char *pname, INT8U *err)
• prio: The priority of the task that you want to obtain its name
• pname: A pointer to an ASCII string that will receive the name of the task
• err:
o No error
o Task does not exist.
o A null pointer is passed for the name.
o Invalid priority
• Return value: Length of the string
Trang 23Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6
Naming a Task, OSTaskNameSet
void OSTaskNameSet (INT8U prio, char *pname, INT8U *err)
• prio: The priority of the task that you want to assign a name to
• pname: A pointer to an ASCII string that contains the name of the task
• err:
o No error
o Task does not exist.
o Name too long
o A null pointer is passed for the name.
o Invalid priority