You are on page 1of 29

MicroC/OS-II

MicroC/OS-II
The
The Real-Time
Real-Time Kernel
Kernel
(#1.
(#1. Introduction
Introduction &
& Concepts
Concepts))

S.E.E 17th (97)


2003.10.17 Jung Yun-jae
(jgyver@q.ssu.ac.kr)
2

Contents
• uC/OS-II References
• uC/OS-II Introduction
• Getting Started
• uC/OS-II File Structure
• Real-time Systems Concepts

Soongsil Electronics Exhibition


3

uC/OS-II References
• “uC/OS-II, The Real-Time Kernel”,
Jean J. Labrosse, R&D Books,
ISBN 0-87930-543-6
www.uCOS-II.com

• “Embedded Systems Building Blocks, Complete


and Ready-to-Use Modules in C”,
Jean J. Labrosse, R&D Books,
ISBN 0-97930-604-1
www.uCOS-II.com
Soongsil Electronics Exhibition
4

uC/OS-II Introduction (1/7)


• uC/OS-II
– By Jean J. Labrosse
– Micro-Controller Operating System, Version 2
– Based on uC/OS 1.0 first published in 1992
– Developed and tested on a PC (MS Windows,
Borland International C/C++ compiler V4.51)
– uCOS-II is actually targeted for embedded
systems
– Can be ported easily to many different processor
architecture
• Ranging from 8- to 64-bit CPUs

Soongsil Electronics Exhibition


5

uC/OS-II Introduction (2/7)


• uC/OS-II (cont.)
– Deployed in 100s of commercial embedded
applications including cameras, medical and
musical instruments, industrial robots, etc..
– Used in numerous schools to teach real-time
systems and operating systems
– http://www.uCOS-II.com

Soongsil Electronics Exhibition


6

uC/OS-II Introduction (4/7)


• Features
– Source Code
• About 5,500 lines
• Provided with the book ($50 US or less)
– Portable
• Most of uCOS-II is written in ANSI-C
• Only target microprocessor-specific code written in assembly
language
• Run on most 8-, 16-, 32-, or even 64-bit microprocessors or
microcontrollers and digital signal processors (DSP)
– ROMable
• uCOS-II was designed for embedded application
• Embed uCOS-II as part of your product

Soongsil Electronics Exhibition


7

uC/OS-II Introduction (5/7)


• Features (cont.)
– Scalable
• You can use only the services you need in your application
• Allows you to reduce the amount of memory (Both RAM and ROM)
– Preemptive
• Fully preemptive real-time kernel
• Always run the highest priority task that is ready
– Multitasking
• uCOS-II can manage up to 64 tasks
– Reserve eight of these tasks for uC/OS-II
– Leaving your application up to 56 tasks
• Each task has a unique priority assigned to it
– Cannot do Round-Robin Scheduling
– Thus 64 priority levels

Soongsil Electronics Exhibition


8

uC/OS-II Introduction (6/7)


• Features (cont.)
– Deterministic
• Execution time of all uCOS-II function and services are
deterministic
– Task Stacks
• Each task requires its own stack
• Each task can have a different stack size
– Services
• Mutual Exclusion, Semaphores, Event Flags, Message
Mailbox, Message Queue, Task Management, Time
Management, and more

Soongsil Electronics Exhibition


9

uC/OS-II Introduction (7/7)


• Features (cont.)
– Interrupt Management
• Interrupt can suspend the execution of a task or
resume the execution of a task
• Interrupt can be nested up to 255 levels deep
– Robust and Reliable
• uCOS-II is based uCOS,which has been used in
hundreds of commercial applications since 1992
• It is safe and robust enough to be used in safety-
critical systems where human life is on the line

Soongsil Electronics Exhibition


10

Getting Started (1/6)


• Installing uC/OS-II
– Book includes a companion CD
• uC/OS-II v2.52
• C:\SOFTWARE
– Installation Environments
• On a Microsoft Windows 95,98,Me,NT,2000 or XP
• Borland C++ Compiler (ex. v3.1)
• C:\ ; HardDisk “C” Drive Root

Soongsil Electronics Exhibition


11

Getting Started (2/6)


• Directory Structure ( c:\ )
• PC
– Support Display, Keyboard, Timer
• TO
– Utility
• EX?_x86L
– Example for x86 Large Model
• lx86L
– uC/OS-II Platform Dependent Code
for x86 Large Model
• SOURCE
– uC/OS-II Platform Independent Code

Soongsil Electronics Exhibition


12

Getting Started (3/6)


• Directory Structure ( c:\ ) (cont.)
• BC45
– Borland C++ v4.5 root Directory
• BIN
– Borland C++ Binary Files
• BC, BCC, Make, Tlink, TASM etc.
• INCLUDE
– Borland C++ Include Files
• *.h
• LIB
– Borland C++ Library Files
– *.Lib, *.obj
Soongsil Electronics Exhibition
13

Getting Started (4/6)


• Build
– Run “MAKETEST.BAT”
• MAKE -f *.MAK MAKETEST.BAT
• View *.MAK
• Demo
TEST.MAK
– Example #1
• C:\SOFTWARE\uCOS-II\EX1_x86L\BC45\TEST\
– Example #2
• C:\SOFTWARE\uCOS-II\EX2_x86L\BC45\TEST\
– Example #3
• C:\SOFTWARE\uCOS-II\EX3_x86L\BC45\TEST\
– Example #4
• C:\SOFTWARE\uCOS-II\EX4_x86L.FP\BC45\TEST\

Soongsil Electronics Exhibition


14

Getting Started (5/6)

• Example #1 TEST.C • Example #2 TEST.C

Soongsil Electronics Exhibition


15

Getting Started (6/6)

• Example #3 TEST.C • Example #4 TEST.C

Soongsil Electronics Exhibition


16

uC/OS-II File Structure (1/3)


• Processor Independent Code
 COS-II.c // Global Variables
 COS-II.h // Global Variables and Data Structures
– OS_CORE.c // Core Internal Functions
– OS_MBOX.c // Message Mailbox Services
– OS_MEM.c // Memory Management Services
– OS_Q.c // Message Queue Services
– OS_SEM.c // Semaphore Management Services
– OS_TASK.c // Task Management Services
– OS_TIME.c // Time Management Services

Soongsil Electronics Exhibition


17

uC/OS-II File Structure (2/3)


• Processor Dependent Code
– OS_CPU.h // Compiler Specific Data
Types
• This allows the kernel to be highly portable
– OS_CPU_C.c // x86 Specific C Code
– OS_CPU_A.asm// x86 Specific Assembly Code

• PC Support Functions
– PC.h // Color Attributes and Function Prototypes
– PS.c // Display, Timer, Tick & DOS Context
Switching

Soongsil Electronics Exhibition


18

uC/OS-II File Structure (3/3)


• Example Application Code
– Test.c // Application Source Code
– Includes.h // Master Include File
– Os-cfg.h // Configuration File (Processor
Specific)
• This is how the application developer “scales” the kernel

Soongsil Electronics Exhibition


19

Real-time Systems Concepts (1/10)


• Two types of real-
time systems
User tasks
– Soft
Session Management
– Hard File Management

• Most real-time Physical I/O

systems are Kernel


HW
Embedded Real Time

• Kernels

Soongsil Electronics Exhibition


20

Real-time Systems Concepts (2/10)


• Foreground/Background Systems
– Interrupt Level
– Task Level

Soongsil Electronics Exhibition


21

Real-time Systems Concepts (3/10)


• Critical Sections of Code
– Not be interrupted
– Use macro (uC/OS-II)
• OS_ENTER_CRITICAL();
• OS_EXIT_CRITICAL();
• Shared Resource
– “Mutual Exclusion”

Soongsil Electronics Exhibition


22

Real-time Systems Concepts (4/10)


• Multitasking
– The process of
scheduling and
switching the CPU
between several tasks
– Scheduling
– Context Switching
• Task Switching
• Use macro (uC/OS-II)
– OS_TASK_SW()

Soongsil Electronics Exhibition


23

Real-time Systems Concepts (5/10)


• Tasks
– typically an infinite loop function
– A task, also called a thread
– Task States

Waiting

Dormant Ready Running ISR

Soongsil Electronics Exhibition


24

Real-time Systems Concepts (6/10)


• Tasks (cont.)
– Task States (cont.)
• Dormant
– The task resides in program space, but has not been made
available to the kernel
• Ready
– The task is ready to execute, the only thing it is lacking is the
CPU
– The highest priority task is given the CPU (to Running)
• Running
– The task which has the CPU
– Can always be interrupted

Soongsil Electronics Exhibition


25

Real-time Systems Concepts (7/10)


• Tasks (cont.)
– Task States (cont.)
• Waiting
– The task is suspended awaiting some event (semaphore,
mailbox or queue) or for some time to expire
• ISR
– the task is suspended and the Interrupt Service Routine
takes control of the CPU

Soongsil Electronics Exhibition


26

Real-time Systems Concepts (8/10)


• Schedulers (= Dispatcher)
– Most real-time kernels are priority based
– In a Priority-based kernel
• Control of the CPU is always given to the highest priority task
ready to run
– Two types of priority-based kernels
• Preemptive (-> uC/OS-II)
• Non-preemptive
• Reentrant Functions
– Can be used by more than one task without fear of data
corruption

Soongsil Electronics Exhibition


27

Real-time Systems Concepts (9/10)


• Advantages of Real-Time Kernels
– Real-time applications to be designed and expanded
easily
– With a preemptive RTOS, All time-critical events are
handled as quickly and as efficiently as possible
– Make better use of your resources by providing you
with valuable services
• Disadvantages of Real-Time Kernels
– Extra cost of the kernel at Software
– More ROM/RAM
– 2 to 4 percent additional CPU overhead

Soongsil Electronics Exhibition


28

Real-time Systems Concepts (10/10)


• Real-time
Systems
Summary

Soongsil Electronics Exhibition


29

Q&A
• Summary
• Any Question ?
• Quiz

Soongsil Electronics Exhibition

You might also like