1. Trang chủ
  2. » Cao đẳng - Đại học

Introduction to uCOS II v2 6 m2

29 289 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 29
Dung lượng 668 KB

Nội dung

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: 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 • 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 */ } } May be used in the future extension of μC/OS-II /* 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 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 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 Clock Tick • µC/OS-II requires a periodic time source to keep track of time delays & timeouts o > 10 Hz & < 100 Hz • Ticker interrupts must be enabled after starting multitasking void main(void){ OSInit(); Enable Ticker Interrupt /* Mistake */ OSStart(); } • The clock tick is serviced by calling OSTimeTick from the tick ISR Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6 µC/OS-II Initialization • µC/OS-II requires that OSInit is called before any other service void main(void){ OSInit(); OSStart(); } • It initializes all µC/OS-II variables & data structures • It creates idle & statistics tasks Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6 Starting µC/OS-II • Multitasking is started by calling OSStart after creating at least task void main(void){ OSInit(); Create at least task here OSStart(); } Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6 Obtaining the Current Version • By calling OSVersion Amr Ali Abdel-Naby@2010 Introduction to uCOS-II V2.6 [...]... 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 Clock Tick • µC/OS -II requires a periodic time source to keep track of time delays & timeouts o > 10 Hz & < 100 Hz • Ticker interrupts... 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. .. from the tick ISR Amr Ali Abdel-Naby@2010 Introduction to uCOS- II V2. 6 µC/OS -II Initialization • µC/OS -II requires that OSInit is called before any other service void main(void){ OSInit(); OSStart(); } • It initializes all µC/OS -II variables & data structures • It creates idle & statistics tasks Amr Ali Abdel-Naby@2010 Introduction to uCOS- II V2. 6 Starting µC/OS -II • Multitasking is started by calling... 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... 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... 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... calling OSStart after creating at least 1 task void main(void){ OSInit(); Create at least 1 task here OSStart(); } Amr Ali Abdel-Naby@2010 Introduction to uCOS- II V2. 6 Obtaining the Current Version • By calling OSVersion Amr Ali Abdel-Naby@2010 Introduction to uCOS- II V2. 6 ... 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... 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... 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

Ngày đăng: 10/08/2016, 09:55

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN