Chapter 1: Getting Started with μC/OS-II 1. kernel Introduction 2 LinuxμC/OS-II Task (process) kernel Device driver User mode (0-3G) (Kernel mode) 3G-4G.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Real-Time Library: RTX
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
MicroC/OS-II Embedded Systems Design and Implementation.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Real-Time Operating Systems Suzanne Rivoire November 20, 2002
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Introduction to Embedded Systems
SOC Consortium Course Material SoC Design Laboratory Lab 8 Real-time OS - 2 Speaker: Yung-Chih Chen Advisor: Prof. Chun-Yao Wang November 17, 2003 Department.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
The  C/OS-II Real-Time Operating System.  C/OS-II Real-time kernel –Portable, scalable, preemptive RTOS –Ported to over 90 processors Pronounced “microC.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
SOC Consortium Course Material Real-time OS Speaker: 沈文中 April. 9, 2003 National Taiwan University Adopted from National Chiao- Tung University SOC Course.
Getting Started with the µC/OS-III Real Time Kernel Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
Real Time Operating Systems
Real-time OS Hao-yuan Chin Feb. 18, Institute of Electronics, National Chiao Tung University Real-time OS 1 Outline Introduction to RTOS Introduction.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 – μC/OS 2015/10/13/ 13 1.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
SOC Consortium Course Material SoC Design Laboratory Lab 8 Real-time OS - 1 Speaker: Yung-Chih Chen Advisor: Prof. Chun-Yao Wang November 17, 2003 Department.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 7: Semaphore Management Seulki Lee 1. Semaphore?  A protocol mechanism offered by most multitasking kernels  Control access to a shared resource.
Chapter 3: Kernel Structure 1. Objectives To understand what a task is. To learn how μ C/OS-II manages tasks. To know how an interrupt service routine.
Chapter 13: Porting μC/OS-II 1. Outline Requirements Hardware Software Tasks of Porting µC/OS-II OS_CPU_C.H OS_CPU_C.C OS_CPU_A.ASM Testing a port 2.
Chapter 3: Kernel Structure 1. Objectives To understand what a task is. To learn how μ C/OS-II manages tasks. To know how an interrupt service routine.
Outlines  Introduction  Kernel Structure  Porting.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Lab 5 Department of Computer Science and Information Engineering National Taiwan University Lab5 – μC/OS 2016/5/31/ 13 1.
Chapter 2: Operating System Concepts 1. Objectives To know essential topics on the design of (embedded) operating systems 2 1.Task & resources 2.Kernel.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Chapter 1: Getting Started with μC/OS-II
Processes and threads.
Process concept.
Chapter 13: Porting μC/OS-II
CS 6560: Operating Systems Design
OPERATING SYSTEMS CS3502 Fall 2017
Protection of System Resources
Getting Started with the µC/OS-III Real Time Kernel
Intro to Processes CSSE 332 Operating Systems
Computer System Overview
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 3: Processes.
CS510 Operating System Foundations
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Computer System Laboratory
Threads CSE 2431: Introduction to Operating Systems
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Presentation transcript:

Chapter 1: Getting Started with μC/OS-II 1

kernel Introduction 2 LinuxμC/OS-II Task (process) kernel Device driver User mode (0-3G) (Kernel mode) 3G-4G Task (thread) Device driver

Introduction μ C/OS-II – Micro-Controller Operating Systems, Version 2 – A very small real-time kernel. Memory footprint is about 20KB for a fully functional kernel. Source code is about 5,500 lines, mostly in ANSI C. It’s source is open but not free for commercial usages. 3

Introduction μ C/OS-II – Preemptible priority-driven real-time scheduling. 64 priority levels (max 64 tasks) 8 (/1/2) reserved for μ C/OS-II Each task is an infinite loop. – Deterministic execution times for most μ C/OS-II functions and services. – Nested interrupts could go up to 256 levels. 4

Introduction μ C/OS-II – Supports of various 8-bit to 64-bit platforms: x86, 68x, MIPS, 8051, etc – Easy for development: Borland C++ compiler and DOS (optional). However, μ C/OS-II still lacks of the following features: – Resource synchronization protocols. – Sporadic task support. – Soft real-time support. 5

Introduction Getting started with μ C/OS-II ! – See how a μ C/OS-II program looks like. – Learn how to write a skeleton program for μ C/OS-II. How to initialize μ C/OS-II ? How to create tasks? How to use inter-task communication mechanisms? How to catch system events? 6

Getting started with μC/OS-II Example 1: Multitasking Example 2: Stack Checking Example 3: Extension of μ C/OS-II Example 4: Portability 7

Example 1: Multitasking 8

9 Task10 main TaskStart install tick ISR Create other tasks Exit? OSTimeDlyHMSM Exit? OSTimeDlyHMSM Task1 OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly OSInit Install context switch handler OSStart OSTaskCreate OSSemCreate OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly... longmp μC/OS-II (Multiprogramming) DOS (bootloader)

Example 1: Multitasking 13 tasks run concurrently. – 2 internal tasks: The idle task and the statistic task. – 11 user tasks: Randomly print numbers onto the screen. Focus: System initialization and task creation. 10

Example 1: Multitasking Files – The main program (test.c) – The big include file (includes.h) – The configuration of μ C/OS-II (os_cfg.h) for each application Tools needed: – Borland C++ compiler (V3.1+) 11

The μC/OS-II File Structure 12 Application Code (test.c) Processor independent implementations Scheduling policy Event flags Semaphores Mailboxes Event queues Task management Time management Memory management Processor independent implementations Scheduling policy Event flags Semaphores Mailboxes Event queues Task management Time management Memory management Application Specific Configurations OS_CFG.H Max # of tasks Max Queue length … Application Specific Configurations OS_CFG.H Max # of tasks Max Queue length … μC/OS-II port for processor specific codes CPU Timer Hardware Software

includes.h 13

OS_CFG.H

test.c 15 A semaphore (explain later) Stacks (explain later) Stacks (explain later)

test.c: main() 16

17 Task10 main TaskStart install tick ISR Create other tasks Exit? OSTimeDlyHMSM Exit? OSTimeDlyHMSM Task1 OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly OSInit Install context switch handler OSStart OSTaskCreate OSSemCreate OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly... longmp Multiprogramming DOS

OSInit() Internal structures of μ C/OS-II. – Task ready list. – Priority table. – Task control blocks (TCB). – Free pools. Create housekeeping tasks. – The idle task. – The statistic task. 18

OSinit() 19

OSinit() 20

The PC IVT Interrupt vector table (IVT) 21 Before (DOS only)After (μC/OS-II installed)

PC_DOSSaveReturn() Save the current status of DOS for the future restoration. – Interrupt vectors and the RTC tick rate. Set a global returning point by calling setjmp(). – μ C/OS-II can come back here when it terminates. – PC_DOSReturn() 22

PC_DOSSaveReturn() 23

setjmp 24 setjmp +longjmp ≒ goto

longjmp 25

PC_VectSet() PC_VectSet(uCOS, OSCtxSw) – Install the context switch handler (OSCtxSw). – Interrupt 0x08 (uCOS) under 80x86 family. Invoked by INT instruction. 26 Disable interrupt Enable interrupt

OSSemCreate() Create a semaphore for resource synchronization. – To protect non-reentrant codes. The created semaphore becomes a mutual exclusive mechanism if “1” is given as the initial value. In this example, a semaphore is created to protect the standard C library “random()”. 27

OSTaskCreate() Functionality – Create tasks with the given arguments. – Tasks become “ready” after they are created. Task – An active entity which could do some computations. – Priority, CPU registers, stack, text, housekeeping status. The μ C/OS-II picks up the highest-priority task to run on context-switching. – Tightly coupled with ISR. 28

OSTaskCreate() OSTaskCreate( TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0 ); 29 Priority (0=hightest) Top of Stack Entry point of the task (a pointer to function) User-specified data

OSStart() – Start multitasking of μ C/OS-II. – It never returns to main(). – μ C/OS-II is terminated if PC_DOSReturn() is called. 30

31 Task10 main TaskStart install tick ISR Create other tasks Exit? OSTimeDlyHMSM Exit? OSTimeDlyHMSM Task1 OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly OSInit Install context switch handler OSStart OSTaskCreate OSSemCreate OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly... longmp Multiprogramming DOS

TaskStart() 32 for (i=0 to 9) { OSTaskCeate } Wait one second void TaskStart (void *pdata) OSTaskCreate( TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);

TaskStart() OS_ENTER_CRITICAL()/OS_EXIT_CRITICAL() – Enable/disable most interrupts. – An alternative way to accomplish mutual exclusion. No rescheduling is possible during the disabling of interrupts. (different from semaphores) – Processor specific. CLI/STI (x86 real mode) Interrupt descriptors (x86 protected mode) 33

TaskStartCreateTasks() 34 Priority Stack Argument: character to print Entry point of the created task

Task() 35 Semaphore operations.

36 Task10 main TaskStart install tick ISR Create other tasks Exit? OSTimeDlyHMSM Exit? OSTimeDlyHMSM Task1 OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly OSInit Install context switch handler OSStart OSTaskCreate OSSemCreate OSSemPend random OSSemPost OSTimeDly OSSemPend random OSSemPost OSTimeDly... longmp Multiprogramming DOS

Semaphores A semaphore consists of a wait list and an integer counter. – OSSemPend(): Counter-- If the value of the semaphore < 0, then the task is blocked and moved to the wait list immediately. A time-out value can be specified. – OSSemPost(): Counter++ If the value of the semaphore ≧ 0, then a task in the wait list is removed from the wait list. Reschedule if needed. 37

Example 1: Multitasking Summary: μ C/OS-II is initialized and started by calling OSInit() and OSStart(), respectively. Before μ C/OS-II is started, – The DOS status is saved by calling PC_DOSSaveReturn(). – A context switch handler is installed by calling PC_VectSet(). – One user task must be created first! Shared resources can be protected by semaphores. – OSSemPend(), OSSemPost(). 38

Example 2 39

40 Multiprogramming DOS main TaskStart install tick ISR Create other tasks Update the display Task1 OSTaskStkChk Task4 OSMboxPost &OSMobxPend OSMboxPost &OSMobxPend Task5 OSMboxPost OSInit Install context switch handler OSStart OSTaskStkInit_FPE_X86 & OSTaskCreateExt OSTaskStkInit_FPE_X86 & OSTaskCreateExt

Example 2: Stack Checking Five tasks do jobs on message sending/receiving. – More task creation options Better judgment on stack sizes – Stack usage of each task Different stack sizes for tasks – Emulation of floating point operations or lower-end CPU’s – Communication through mailbox Only the pointer is passed. 41

42 2 Mailboxes

Main() 43 OSTaskStkInit_FPE_x86(&ptos, &pbos, &size)

OSTaskStkInit_FPE_x86() OSTaskStkInit_FPE_x86(&ptos, &pbos, &size) – Passing the original top address, bottom address, and size of the stack. – On the return, arguments are modified, and some stack space are reserved for the floating point library. For context switches. 44 ptos pbos size

OSCreateTaskExt() OSTaskCreatExt( TaskStart, (void *)0, ptos, TASK_START_PRIO, TASK_START_ID, pbos, size, (void *)0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR ); 45 User supplied data which can be used to extend TCB options

TaskStart() 46 Create 2 mailboxes The dummy loop wait for ‘ ESC ’

Task1() 47

Task2 and Task3 48 for (i=0; i<499; i++) { dymmy[i] = ‘?’; }

Task4 and Task5 49 ??? OSTimeDlyHMSM(0, 0, 1, 0);

MailBox A mailbox is for data exchanging between tasks. – A mailbox consists of a data pointer and a wait-list. OSMboxPend(): – The message in the mailbox is retrieved. – If the mailbox is empty, the task is immediately blocked and moved to the wait-list. – A time-out value can be specified. OSMboxPost(): – A message is posted in the mailbox. – If there is already a message in the mailbox, then an error is returned (not overwritten). – If tasks are waiting for a message from the mailbox, then the task with the highest priority is removed from the wait-list and scheduled to run. 50

OSTaskStkCheck() Check for stack overflow. – bos < (tos – stack length) – Local variables, arguments for procedure calls, temporary storage for ISR’s. – μ C/OS-II can check for stack overflow on the creation of tasks and when OSTaskStkCheck() is called. – μ C/OS-II does not automatically check stacks. 51

(Linux 2.6) 52 User mode Kernel mode (kernel service routines) Kernel mode (interrupt service routines) stack

(Linux 2.4) 53 User mode Kernel mode (kernel service routines) Kernel mode (interrupt service routines) stack

μC/OS-II 54 Kernel mode (kernel service routines) Kernel mode (interrupt service routines) stack

Example2: Stack Checking Summary: – Local variable, function calls, and ISR’s will utilize the stack space of user tasks. – ISR will use the stack of the interrupted task. – If floating-point operations are needed, then some stack space should be reserved. – Mailboxes can be used to synchronize the work of tasks. 55

Example 3: Extension of μC/OS-II A Pointer to from the TCB of each task to a user-provided data structure – Passing user-specified data structures on task creations or have application-specific usage. Message queues – More than one pointers Demonstration on how to use OS hooks to receive/process desired event from the μ C/OS-II 56

Example 3 57

58 User-defined data structure to pass to tasks Message queue and an array of event

59

61

62 Task 2, 3, 4 are functionally identical.

Message Queues A message queue consists of an array of elements and a wait- list. Different from a mailbox, a message queue can hold many data elements (in a FIFO basis). As same as mailboxes, there can be multiple tasks pend/post to a message queue. OSQPost(): a message is appended to the queue. The highest- priority task (in the wait-list) receives the message and is scheduled to run, if any. OSQPend(): a message is removed from the array of elements. If no message can be retrieved, the task is moved to the wait- list and becomes blocked. 63

Hooks A hook function will be called by μ C/OS-II when the corresponding event occurs. – Event handlers could be in user programs. – For example, OSTaskSwHook () is called every time when context switch occurs. The hooks are specified in the compiling time in μ C/OS- II : – μ C/OS-II is an embedded OS. OS_CFG.H (OS_CPU_HOOKS_EN = 0) – Many OS’s can register and un-register hooks. 64

User Customizable Hooks for μC/OS-II void OSInitHookBegin (void) void OSInitHookEnd (void) void OSTaskCreateHook (OS_TCB *ptcb) void OSTaskDelHook (OS_TCB *ptcb) void OSTaskIdleHook (void) void OSTaskStatHook (void) void OSTaskSwHook (void) void OSTCBInitHook (OS_TCB *ptcb) void OSTimeTickHook (void) 65

OSTaskStatHook() 66

OSTaskSwHook() 67 OSTCBCur  TCB of the current task OSTCBHighRdy  TCB of the new task OSTCBCur  TCB of the current task OSTCBHighRdy  TCB of the new task Elapsed time for the current task

Example 3: Extension of μC/OS-II Summary: – Message queues can be used to synchronize among tasks. Multiple messages can be held in a queue. Multiple tasks can “pend”/“post” to message queues simultaneously. – Hooks can be used to do some user-specific computations on certain OS events occurs. They are specified in the compiling time. A Pointer to from the TCB of each task to a user-provided data structure 68

Getting Started with μC/OS-II? Getting Started with μ C/OS-II : – How the control flows among procedures? – How tasks are created? – How tasks are synchronized by semaphore, mailbox, and message queues? – How the space of a stack is utilized? – How to capture system events? – How to write a dummy μ C/OS-II program? 69