Embedded System Presentation Nguyễn Trần Quang Nguyễn Công Vũ 1µC/OS-II.

Slides:



Advertisements
Similar presentations
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Advertisements

Real-Time Library: RTX
Mike Holenderski, Synchronization 2IN60: Real-time Architectures (for automotive systems)
µC/OS-II, The Real-Time Kernels and the ARM7 / ARM9 Jean J. Labrosse.
Lecture 2. Real-time Systems Concept Prof. Taeweon Suh Computer Science Education Korea University COM609 Topics in Embedded Systems.
Department of Mathematics and Computer Science μC/OS-II 2IN60: Real-time Architectures (for automotive systems)
CSE Fall Introduction - 1 What is an Embedded Systems  Its not a desktop system  Fixed or semi-fixed functionality (not user programmable)
MicroC/OS-II Embedded Systems Design and Implementation.
Real-Time Operating Systems Suzanne Rivoire November 20, 2002
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Real Time Operating System
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.
國立台灣大學 資訊工程學系 Introduction to uC/OS-II
Kernel structure & Task management © P.J.Fondse April 2010.
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.
Real-Time Systems Design1 Priority Inversion When a low-priority task blocks a higher-priority one, a priority inversion is said to occur Assume that priorities:
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 9 RTOS: Inter-process communication
2-1 The critical section –A piece of code which cannot be interrupted during execution Cases of critical sections –Modifying a block of memory shared by.
Scheduling in µC/OS-III Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic.
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.
Real Time Operating Systems Mutual Exclusion, Synchronization & Intertask Communication Course originally developed by Maj Ron Smith.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 4 Review.
ID 711L: Getting Started with a Real- Time Kernel Matt Gordon Sr. Applications Engineer Version: 1.1 Micriµm 12 October 2010.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Real-Time Systems Lecture 3 Teachers: Olle Bowallius Phone: Anders Västberg Phone:
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
Real Time Operating Systems Michael Thomas Date: Rev. 1.00Date.
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.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
uC/OS-II Real-Time Systems Concepts Kernel Structure Task Management
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.
1 J.O. KLEIN Institut Universitaire de Technologie de CACHAN Université PARIS SUD - FRANCE An Introduction to Real Time Operating System.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
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.
2-1 Chapter 2 Real-Time Systems Concepts. 2-2 Foreground/Background Systems BackgroundForeground ISR Time Code execution application consists of an infinite.
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.
Real Time Operating Systems Johan Dams
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.
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.
Chapter 5: Time Management 1. Time Management OSTimeDly() OSTimeDlyHMSM() OSTimeDlyResume() OSTimeGet() OSTimeSet() 2.
Outlines  Introduction  Kernel Structure  Porting.
Chapter 5 Time Management use clock tick to provide a periodic interrupt to keep track of time delays and timeouts The frequency of the clock tick depends.
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.
REAL TIME OPERATING SYSTEM
Getting Started with Micriμm’s μC/OS-III Kernel
Chapter 1: Getting Started with μC/OS-II
REAL-TIME OPERATING SYSTEMS
Process concept.
Chapter 13: Porting μC/OS-II
Chapter 4: Task Management
Chapter 2: Operating System Concepts
Topics Covered What is Real Time Operating System (RTOS)
Chapter 8: Mutual Exclusion Semaphores
Interrupt and Time Management in µC/OS-III
Getting Started with the µC/OS-III Real Time Kernel
Computer System Laboratory
Chapter 6: Event Control Block (ECB)
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Presentation transcript:

Embedded System Presentation Nguyễn Trần Quang Nguyễn Công Vũ 1µC/OS-II

µC/OS-II 2

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 3Micro C_OS

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 4Micro C_OS

At the Beginning Written By J. Labrosse First published in 1992 µC/OS-II is a trade mark of Micrium. 1000s applications are using it all over the world. A good starting point to experience real-time OS Simple but yet very powerful 5Micro C_OS

µC/OS-II in Literature Four books were published to explain the internals: “μC/OS The Real-Time Kernel”, in 1992 “μC/OS-II The Real-Time Kernel”, in 1998 “μC/OS-II The Real-Time Kernel”, Second Edition in 2002 “μC/OS-III The Real-Time Kernel”, in Micro C_OS

µC/OS-II History µC/OS-II V2.86 µC/OS-II V2.52 µC/OS-II V2.00 µC/OS V1.08 µC/OS-III µC/OS V Memory Manager + Stack Checking + CPU Load Checking µC/OS-II V Safety Critical + Mutexes + Semaphores + Event Flags µC/OS-II V Timers Tasks + MMU & MPU µC/OS-II V RR Scheduling + Infinite # of Tasks & Services 7Micro C_OS

µC/OS-II Features Source code Portable Preemptive Multitasking Task stack Services Interrupt management Robust & reliable … 8Micro C_OS

Source Code High quality Neat Consistent Organized Commented MISRA-C compliant 9Micro C_OS

Source Code Highly portable ANSI C Assembly is kept minimum Supports 8-, 16-, 32-, 64- bit processors Ported over 100 different processors All ports are freely available at Micrium website 10Micro C_OS

Amr Ali to uCOS-II V2.6 11Micro C_OS

Preemptive Fully preemptive Always runs the highest priority task that is ready to run 12Micro C_OS

Multitasking Manages up to 64 tasks 8 tasks are used by µC/OS-II 56 tasks are left to applications A unique task/priority RR and FIFO are not supported 13Micro C_OS

Task Stacks Each task has its stack μC/OS-II allows different stack sizes Stack checking utility You can determine & decide how much stack is needed for each task 14Micro C_OS

Task Stacks Each task has its stack μC/OS-II allows different stack sizes Stack checking utility You can determine & decide how much stack is needed for each task 15Micro C_OS

Services Semaphores Mutexes Event flags Message queues Mailboxes Fixed size memory partitions Task management Time management 16Micro C_OS

Interrupt Management An interrupt can suspend a task execution The highest priority ready task runs after serving the interrupt Nested interrupts Up to 255 level 17Micro C_OS

Robust & Reliable Used by many products Support Tested & certified in safety critical systems 18Micro C_OS

Related Products µC/Probe µC/TCP-IP µC/FS µC/GUI µC/USB µC/CAN µC/Modbus µC/FL µC/Building Blocks µC/OSEK-VDX 19Micro C_OS

µC/OS-II Market Distributors all over the word Huge customer list 20Micro C_OS

License Educational Free Universities Non-profitable use Source Code If µC/OS will be distributed with your product as a source code Object Code If µC/OS will be distributed with your product as a binary Not royalty free 21Micro C_OS

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 22Micro C_OS

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 23Micro C_OS

Kernel Architecture µC/OS-II Port (Processor Specific Code) µC/OS-II (Processor Independent code) µC/OS-II Configuration (Application Specific) Application SW (Your Code) HW 24Micro C_OS

Critical Sections 2 macros protect critical sections They enable/disable interrupts Can be used by your application Not a good programming style Applications may crash Processor & tool chain specific OS_ENTER_CRITICAL(); /* Critical Code */ OS_EXIT_CRITICAL(); 25Micro C_OS

Tasks Distributors all over the word Huge customer list Lowest priority is defined as OS_LOWEST_PRIO /* Endless Loop Task */ void My_Task (void * pdata){ for(;;){ /* Your Code */ } /* Run To Completion Task */ void My_Task (void * pdata){ /* Your Code */ OSTaskDel(OS_PRIO_SELF); } Up to 56 application tasks … Priority Used by the system May be used in the future extension of μC/OS-II 26Micro C_OS

Task States 27Micro C_OS

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

Task Control Blocks cont’d A TCB contains: Task’s priority Task’s state A pointer to the task’s top of stack Other task’s related data TCBs reside in RAM 29Micro C_OS

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 30Micro C_OS

Task Scheduling Task-level scheduling is performed by OS_Sched ISR-level scheduling is handled by OSIntExit Task Level context switch 31Micro C_OS

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: OSSchedLock & OSSchedUnlock After calling OSSchedLock, your application should not call a service that suspends execution Your application will crash LPT HPT LPT OSSchedLockOSSchedUnlock HPT is ready here 32Micro C_OS

Idle Task Executed when there is no other task ready to run Always set to the lowest priority 33Micro C_OS

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 34Micro C_OS

Statistics Task void main(void){ OSInit();... Create your startup task TaskStart()... OSStart(); } void TaskStart(void * pdata){ OSStatInit();... } 35Micro C_OS

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: ISR nesting Function call nesting Local variables 36Micro C_OS

Clock Tick µC/OS-II requires a periodic time source to keep track of time delays & timeouts Ticker interrupts must be enabled after starting multitasking The clock tick is serviced by calling OSTimeTick from the tick ISR void main(void){ OSInit();... Enable Ticker Interrupt /* Mistake */... OSStart(); } 37Micro C_OS

µC/OS-II Initialization µC/OS-II requires that OSInit is called before any other service It initializes all µC/OS-II variables & data structures It creates idle & statistics tasks void main(void){ OSInit();... OSStart(); } 38Micro C_OS

Starting µC/OS-II Multitasking is started by calling OSStart after creating at least 1 task void main(void){ OSInit();... Create at least 1 task here... OSStart(); } 39Micro C_OS

Obtaining the Current Version By calling OSVersion 40Micro C_OS

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 41Micro C_OS

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 42Micro C_OS

43Micro C_OS

Creating a Task, OSTaskCreate INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio) task: A pointer to the task's code pdata: A pointer to an optional data area which can be used to pass parameters to the task when the task first executes ptos: A pointer to the task's top of stack prio: The task's priority Return value: o No error o Priority exist o Invalid priority 44Micro C_OS

Creating a Task, OSTaskCreateExt INT8U OSTaskCreateExt (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt) OSTaskCreate + id: Task’s ID, not used currently pbos: A pointer to the task's bottom of stack stk_size: A pointer to the task's top of stack pext: A pointer to a user supplied memory location which is used as a TCB extension opt: Additional information (or options) about the behavior of the task 45Micro C_OS

Task Stacks Each task has its own stack. It must be: Declared as OS_STK Consistent & contiguous memory It can be allocated static Or dynamic OS_STK MyTaskSTack[stack_size]; OS_STK *pstk;... pstk = (OS_STK*)malloc(stack_size); 46Micro C_OS

Naming a Task, OSTaskNameSet void OSTaskNameSet (INT8U prio, char *pname, INT8U *err) prio: The priority of the task that you want to assign a name to pname: A pointer to an ASCII string that contains the name of the task err: o No error o Task does not exist. o Name too long o A null pointer is passed for the name. o Invalid priority 47Micro C_OS

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 48Micro C_OS

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 49Micro C_OS

Time Management APIs Available time operations are: Delaying a task Resuming a delayed task System time getting & setting 50Micro C_OS

Delaying a Task, OSTimeDly void OSTimeDly (INT16U ticks) ticks: The time delay that the task will be suspended in number of clock ticks time 10ms OSTickISR() All HPT LPT 5ms OSTimeDly(1) 51Micro C_OS

Delaying a Task, OSTimeDlyHMSM INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli) hours: The number of hours that the task will be delayed minutes: The number of minutes seconds: The number of seconds milli: The number of milliseconds Return value: o No error o Zero delay o Invalid minutes, seconds, & milli seconds 52Micro C_OS

Resuming a Delayed Task, OSTimeDlyResume INT8U OSTimeDlyResume (INT8U prio) prio: Specifies the priority of the task to resume Return value: o No error o Invalid priority o Task is not delayed. o Task does not exist. 53Micro C_OS

System Time, OSTimeSet void OSTimeSet (INT32U ticks) ticks: Specifies the new value that OSTime needs to take 54Micro C_OS

System Time, OSTimeGet INT32U OSTimeGet (void) Return value: o The current value of OSTime 55Micro C_OS

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 56Micro C_OS

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 57Micro C_OS

Semaphores Semaphores are 16 bit unsigned integers used for resource sharing or to signal the occurrence of an event OSSemCreate() OSSemDel() OSSemPost() OSSemAccept() OSSemPend() OSSemQuery() OSSemPost() N N OSSemAccept() ISR Task 58Micro C_OS

Semaphores Functions: Creating a Semaphore, OSSemCreate Deleting a Semaphore, OSSemDel Waiting on a Semaphore (Blocking), OSSemPend Signaling a Semaphore, OSSemPost Getting a Semaphore without Waiting, OSSemAccept Obtaining the Status of a Semaphore, OSSemQuery Creating a Semaphore, OSSemCreate Obtaining the Status of a Semaphore, OSSemQuery 59Micro C_OS

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 60Micro C_OS

Mutexes They are used to gain exclusive access to resources. They reduce priority inversion problem (priority ceiling protocol is supported). OSMutexCreate() OSMutexDel() OSMutexPost() OSMutexPend() OSMutexAccept() OSMutexQuery() Task 61Micro C_OS

Creating a Mutex, OSMutexCreate OS_EVENT *OSMutexCreate (INT8U prio, INT8U *err) prio: Ceiling priroity err: o No error o Called from ISR o Priority exists o Invalid priority o No available resources Return value: o Non-null for successful creation o Null for failure 62Micro C_OS

Deleting a Mutex, OSMutexDel OS_EVENT *OSMutexDel (OS_EVENT *pevent, INT8U opt, INT8U *err) pevent: A pointer to the mutex to be deleted opt: Delete options o Delete always o Delete if no pending tasks err: o No error o Called from ISR o Invalid option o There are tasks pending. o pevent is null. o pevent is not a semaphore. 63Micro C_OS

Deleting a Mutex, OSMutexDel cont’d OS_EVENT *OSMutexDel (OS_EVENT *pevent, INT8U opt, INT8U *err) Return value: Null if successful 64Micro C_OS

Waiting on a Mutex (Blocking), OSMutexPend void OSMutexPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) pevent: A pointer to the mutex to acquire timeout: o 0  wait for ever o !0  wait with specific timeout err: o No error o Timeout o pevent is not a mutex. o pevent is null. o Called from ISR 65Micro C_OS

Signaling a Mutex, OSMutexPost INT8U OSMutexPost (OS_EVENT *pevent) pevent: A pointer to the mutex to release Return value: o No error o Not mutex owner o Called from ISR o pevent is not a mutex. o pevent is null. 66Micro C_OS

Getting a Mutex without Waiting, OSMutexAccept INT8U OSMutexAccept (OS_EVENT *pevent, INT8U *err) pevent: A pointer to the mutex to acquire err: o No error o Called from ISR o pevent is not a mutex. o pevent is null. Return value: o 1  resource available o 0  case of error or mutex is no available 67Micro C_OS

Obtaining the Status of a Mutex, OSMutexQuery INT8U OSMutexQuery (OS_EVENT *pevent, OS_MUTEX_DATA *pdata) pevent: A pointer to the desired mutex pdata: A pointer to the returned mutex information Return value: o No error o Called from ISR o pevent is not a mutex. o pevent is null. 68Micro C_OS

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 69Micro C_OS

Event Flags Used for synchronization of tasks with the occurrence of multiples of events Events are grouped o 8, 16 or 32 bits per group Types of synchronization o ORed: Any event occurred o ANDed: All events occured 70Micro C_OS

Amr Ali to uCOS-II V2.6 Event Flags cont’d 71Micro C_OS

Event Flags Management APIs OSFlagPost() OSFlagCreate () OSFlagDel() OSFlagPost () OSFlagAccept () OSFlagPend () OSQFlagQuery () ISR Task ISR Task OSFlagAccept () OSQFlagQuery () 72Micro C_OS

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 73Micro C_OS

Message Mailboxes A message mailbox is a μC/OS-II object that allows a task or an ISR to send pointer- sized variable to another task. OSMboxCreate() Message OSMboxPost() OSMboxAccept() OSMboxPost() OSMboxPend() OSMboxAccept() OSMboxQuery() ISR Task 74Micro C_OS

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 75Micro C_OS

Message Queues A message queue is a μC/OS-II object that allows a task or an ISR to send pointer-sized variables to another task. OSQCreate() Message OSQPost() OSQPostFront() OSQFlush() OSQAccept() OSQPostOpt() OSQPost() OSQPostFront() OSQFlush() OSQPostOpt() OSQPend() OSQAccept() OSQQuery() ISR Task 76Micro C_OS

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 77Micro C_OS

Memory Management Fixed-size memory block management o To prevent fragmentation Multiple partitions can be created with different sizes. Blocks allocated from certain partitions must be returned back to the same partitions 78Micro C_OS

Memory Management 79Micro C_OS

Memory Management 80Micro C_OS

Memory Management APIs Available memory operations are: o Creating a memory partition o Obtaining a memory block o Returning a memory block o Obtaining status of a memory partition o Naming a memory partition o Getting the name of a memory partition 81Micro C_OS