Tải bản đầy đủ (.ppt) (29 trang)

Introduction to uCOS II v2 6 m2

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (430.22 KB, 29 trang )

Introduction to uCOS-II V2.6


About SwiftACT
• A Technology services startup company
o

Under establishment

• Areas of specialties:
o
o

Mobile telecommunication services development
Embedded systems development

• Types of services:
o
o
o
o

Consultation
Managed services
Sourcing
Training

Amr 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, ...

Amr 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.

Amr 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

Amr 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

Amr 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

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Kernel Architecture
Application SW
(Your Code)
µC/OS-II
(Processor Independent
code)

µC/OS-II Configuration
(Application Specific)

µC/OS-II Port
(Processor Specific Code)
HW

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6



Critical Sections
• 2 macros protect critical sections.
o

They enable/disable interrupts.

OS_ENTER_CRITICAL();
/* Critical Code */
OS_EXIT_CRITICAL();

• Can be used by your application
o
o

Not a good programming style
Applications may crash.

• Processor & tool chain specific

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Tasks
/* Endless Loop Task */
void My_Task (void * pdata){
for(;;){
/* Your Code */

}
}

0
1
2

May be used
in the future
extension of
μC/OS-II

3

/* Run To Completion Task */
Priority
void My_Task (void * pdata){
/* Your Code */
• Lowest priority is defined
OSTaskDel(OS_PRIO_SELF);
} as OS_LOWEST_PRIO.



Up to 56
application
tasks

60
61

62
63

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6

Used by the
system


Task States

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Task Control Blocks
• µC/OS-II uses TCBs for task management.
• Every task is assigned a TCB when created.

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Task Control Blocks cont’d
• A TCB contains:
o

o
o
o

Task’s priority
Task’s state
A pointer to the task’s top of stack
Other task’s related data

• TCBs reside in RAM.

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Ready List
• The kernel maintains a list of tasks that can be ready to run.
• The highest priority task is kept at the beginning of the task.

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Task Scheduling
• Task-level scheduling is performed by OS_Sched.
• ISR-level scheduling is handled by OSIntExit.

Amr Ali Abdel-Naby@2010


Introduction to uCOS-II V2.6


Task Level Context Switch
• OS_TASK_SW is a macro used by μC/OS-II to perform the
context switch.
o

It simply saves registers of the preempted task & loads registers of
the task to be resumed.

• The context switch can be viewed at three moments:
o
o
o

The context at the call
Saving the current task’s context
Resuming the highest priority ready task

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Task Level Context Switch cont’d
Low Priority Task

High Priority Task


OSTCBHighRdy
OSTCBHighRdy
OSTCBCur

CPU

Low Memory

SP

Low Memory

R1
R2

R4

R3

R3

R4

R1

R2
PC

PC

High Memory

Amr Ali Abdel-Naby@2010

PSW
Introduction to uCOS-II V2.6

PSW

High Memory


Task Level Context Switch cont’d
Low Priority Task

High Priority Task
OSTCBHighRdy

OSTCBCur

CPU

Low Memory

SP

Low Memory

R1
R4

R3
R2
R1

R2
R3

R3

R4

R1

High Memory

Amr Ali Abdel-Naby@2010

R2
PC

PC
PSW

R4

PC
PSW
Introduction to uCOS-II V2.6

PSW


High Memory


Task Level Context Switch cont’d
Low Priority Task
OSTCBCur

OSTCBHighRdy

High Priority Task

OSTCBCur

CPU

Low Memory

SP

Low Memory

R1
R4
R3
R2
R1

R2
R3


R3

R4

R1

High Memory

Amr Ali Abdel-Naby@2010

R2
PC

PC
PSW

R4

PC
PSW
Introduction to uCOS-II V2.6

PSW

High Memory


Locking & Unlocking the Scheduler
• A mechanism used by a task to keep control of the CPU, even if

there are higher priority tasks ready.
• Two kernel services are provided & must be used in pairs:
o

OSSchedLock & OSSchedUnlock

• After calling OSSchedLock, your application should not call a
service that suspends execution.
o

Your application will crash.
LPT

OSSchedLock

Amr Ali Abdel-Naby@2010

HPT
LPT

HPT is ready here

Introduction to uCOS-II V2.6

OSSchedUnlock


Idle Task
• Executed when there is no other task ready to run
o


Always set to the lowest priority

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Statistics Task






Its priority is higher than IDLE task by 1.
It provides runtime statistics.
It is called OS_TaskStat & it is called every second.
It tells you how long was the CPU used by your application.
To use it, you must call OSStatInit from the first & the only task
created during initialization.
void main(void){
OSInit();
...
Create your startup task TaskStart()
...
OSStart();
}
void TaskStart(void * pdata){
OSStatInit();

...
}

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Interrupts Under µC/OS-II
• You should keep ISRs as short as possible.
• Interrupts either use an interrupt stack or task stack.
• Stack size must account for:
o
o
o

ISR nesting
Function call nesting
Local variables

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Interrupts Under µC/OS-II cont’d

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6



Interrupts Under µC/OS-II cont’d

Amr Ali Abdel-Naby@2010

Introduction to uCOS-II V2.6


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×