lab_09_slide - Lab 8 Real-time OS - 1 time Speaker: Hao-Yun...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab 8 Real-time OS - 1 time Speaker: Hao-Yun Chin Advisor: Prof. Tian-Sheuan Chang Apr 27, 2004 SoC Design Laboratory SOC Consortium Course Material Outline Introduction to Real-time Operation System (RTOS) Introduction to μC/OS-II Real-time OS – – – – Features Task & task scheduling Start μC/OS-II Port application SoC Design Laboratory SOC Consortium Course Material 1 Real-time OS Real-time OS (RTOS) is an intermediate layer between hardware devices and software programming “Real-time” means keeping deadlines, not speed Real-time OS Advantages of RTOS in SoC design • Shorter development time • Less porting efforts • Better reusability Disadvantages • More system resources needed • Future development confined to the chosen RTOS SoC Design Laboratory SOC Consortium Course Material 2 Soft and Hard Real Time Soft real-time • Tasks are performed by the system as fast as possible, but tasks don’t have to finish by specific times Real-time OS • Priority scheduling • Multimedia streaming Hard real-time • Tasks have to be performed correctly and on time • Deadline scheduling • Aircraft controller, Nuclear reactor controller SoC Design Laboratory SOC Consortium Course Material 3 Outline Introduction to RTOS Introduction to μC/OS-II Real-time OS – – – – Features Task & task scheduling Start μC/OS-II Port application SoC Design Laboratory SOC Consortium Course Material 4 μC/OS-II Written by Jean J. Labrosse in ANSI C A portable, ROMable, scalable, preemptive, real-time, multitasking kernel Real-time OS Used in hundreds of products since its introduction in 1992 Certified by the FAA for use in commercial aircraft Available in ARM Firmware Suite (AFS) Over 90 ports for free download http://www.ucos-ii.com SoC Design Laboratory SOC Consortium Course Material 5 μC/OS-II Features Real-time OS Portable runs on architectures ranging from 8bit to 64-bit ROMable small memory footprint Scalable select features at compile time Multitasking preemptive scheduling, up to 64 tasks SoC Design Laboratory SOC Consortium Course Material 6 μC/OS-II vs. μHAL uHAL (pronounced Micro-HAL) is the ARM Hardware Abstraction Layer that is the basis of the ARM Firmware Suite uHAL is a basic library that enables simple application to run on a variety of ARM-based development systems Real-time OS uC/OS-II use uHAL to access ARM-based hardware uC/OS-II & User application AFS Utilities C, C++ libraries uHAL routines AFS support routines Development board SoC Design Laboratory SOC Consortium Course Material 7 Task Task is an instance of program Task thinks that it has the CPU all to itself Real-time OS Task is assigned a unique priority Task has its own set of stack Task has its own set of CPU registers (backup in its stack) Task is the basic unit for scheduling Task status are stored in Task Control Block (TCB) SoC Design Laboratory SOC Consortium Course Material 8 Task Structure Task structure: An infinite loop Real-time OS An self-delete function Task with infinite loop structure Task that delete itself void ExampleTask(void *pdata) { for(;;) { /* User Code */ /* System Call */ /* User Code */ } } void ExampleTask(void *pdata) { /* User Code */ OSTaskDel(PRIO_SELF); } SoC Design Laboratory SOC Consortium Course Material 9 Task States Waiting Waiting Real-time OS Task Delete Task Gets Event Task Create Dormant Dormant Task Delete Task Pending Events Highest Priority Task Readyy Read Interrupt Running Running Task is Preempted ISR ISR Int. Exit Task Delete SoC Design Laboratory SOC Consortium Course Material 10 Task Priority Unique priority (also used as task identifiers) Real-time OS 64 priorities max (8 reserved) Always run the highest priority task that is READY Allow dynamically change priority SoC Design Laboratory SOC Consortium Course Material 11 Task Control Block uC/OS-II use TCB to keep record of each task States Real-time OS Stack Pointer Priority Misc … Link Pointer SoC Design Laboratory SOC Consortium Course Material 12 Task Control Block(cont.) Real-time OS SoC Design Laboratory SOC Consortium Course Material 13 Exchanging CPU Control uC/OS-II Kernel API Control returns from task to OS when Kernel API is called OSMboxPend(); OSQPend(); Real-time OS void ExampleTask(void *pdata) OSSemPend(); OSTaskSuspend(); { OSTimeDly(); for(;;) { /* User Code */ OSTimeDlyHMSM(); /*System Call */ More… /* User Code */ } } SoC Design Laboratory SOC Consortium Course Material 14 Exchanging CPU Control Only one of OS, Task, Interrupt Handler gets CPU control at a time Real-time OS Interrupt Handler OS Task A B B C A Time Scheduling System Call SoC Design Laboratory Interrupt Interrupt Exit SOC Consortium Course Material 15 Task Scheduling Non-preemptive Low-priority Task Real-time OS ISR ISR makes the high-priority task ready High-priority Task low-priority task Relinquishes the CPU SoC Design Laboratory SOC Consortium Course Material Time 16 Task Scheduling Preemptive Low-priority Task ISR Real-time OS High-priority Task ISR makes the high-priority task ready high-priority task Relinquishes the CPU Time uC/OS-II adopts preemptive scheduling SoC Design Laboratory SOC Consortium Course Material 17 Starting µC/OS-II Initialize hardware & uC/OS-II Initialize hardware & uC/OS-II ARMTargetInit(), ,OSInit() ) ARMTargetInit() OSInit( Real-time OS Allocate resources Allocate resources OSMemCreate(), ,OSMboxCreate(), ,…etc OSMemCreate() OSMboxCreate() …etc Create at least one task Create at least one task OSTaskCreate() OSTaskCreate() Start Scheduler Start Scheduler OSStart() OSStart() SoC Design Laboratory SOC Consortium Course Material 18 Porting Application Necessary coding changes variables Real-time OS • use local variables for preemption • use semaphore to protect global variables (resources) data transfer • arguments => mailbox/queue memory allocation • SoC Design Laboratory malloc() => OSMemCreate() OSMemGet() SOC Consortium Course Material 19 Porting Application assign task priorities unique priority level in uC/OS-II Real-time OS • only 56 levels available • priority can be change dynamically call OSTimeDly() in infinite loop task • ensure lower priority task get a chance to run MUST: if lower priority task is pending data from higher priority task SoC Design Laboratory SOC Consortium Course Material 20 Lab 7:Real-time OS - 1 Goal – A guide to use RTOS and port programs to it Principles Real-time OS – Basic concepts and capabilities of RTOS • Task, task scheduling – Coding guideline for a program running on the embedded RTOS – Setting up the ARMulator Guidance SoC Design Laboratory Steps – Building µC/OS-II – Porting Program to µC/OS-II – Building Program with µC/OS-II Requirements and Exercises – Write an embedded software for ID checking engine (single task) Discussion – What are the advantages and disadvantages of using RTOS in SOC design? SOC Consortium Course Material 21 References [1] AFS_Reference_Guide.pdf Real-time OS SoC Design Laboratory SOC Consortium Course Material 22 ...
View Full Document

This note was uploaded on 08/23/2009 for the course IEE 5016 taught by Professor Tian-sheuanchang during the Spring '05 term at National Chiao Tung University.

Ask a homework question - tutors are online