Presentation is loading. Please wait.

Presentation is loading. Please wait.

2015-09-18MicroC/OS-II(Ch1)1 MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ.

Similar presentations


Presentation on theme: "2015-09-18MicroC/OS-II(Ch1)1 MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ."— Presentation transcript:

1

2 2015-09-18MicroC/OS-II(Ch1)1 MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ.

3 2015-09-18MicroC/OS-II(Ch1)2 INTRODUCTION

4 2015-09-18MicroC/OS-II(Ch1)3 Brief History  Developed in C by Jean Labrosse in 1992  Currently, maintained by Micrium Inc. (http://www.micrium.com/products/rtos/kerne l/rtos.html) http://www.micrium.com/products/rtos/kerne l/rtos.htmlhttp://www.micrium.com/products/rtos/kerne l/rtos.html  The current version is  C/OS-II v3.10(v2.52 for textbook )

5 2015-09-18MicroC/OS-II(Ch1)4 Brief History  The new version  C/OS-III provides more features features Round-robin schedulingRound-robin scheduling –Allow multiple tasks to run at the same priority level Near zero interrupt disable timeNear zero interrupt disable time Unlimited number of application tasksUnlimited number of application tasks Error checking and more.Error checking and more.

6 2015-09-18MicroC/OS-II(Ch1)5 Brief History  Licensing Free distribution of  C/OS-II source and object code to accredited Colleges and Universities w/o requiring licenseFree distribution of  C/OS-II source and object code to accredited Colleges and Universities w/o requiring license ‘Object Code Distribution License’ is required for commercial products‘Object Code Distribution License’ is required for commercial products

7 2015-09-18MicroC/OS-II(Ch1)6 Brief History   C/OS-II A highly portable, ROMable, scalable, preemptive, real-time, deterministic multitasking kernel for microprocessors, microcontrollers and DSP-based devicesA highly portable, ROMable, scalable, preemptive, real-time, deterministic multitasking kernel for microprocessors, microcontrollers and DSP-based devices Actual target: embedded systemActual target: embedded system Easily portable to many processor (http://www.micrium.com/products/rtos/kernel/po rts.html)Easily portable to many processor (http://www.micrium.com/products/rtos/kernel/po rts.html)http://www.micrium.com/products/rtos/kernel/po rts.htmlhttp://www.micrium.com/products/rtos/kernel/po rts.html

8 2015-09-18MicroC/OS-II(Ch1)7  Major available ports ACTEL (Cortex-M1)ACTEL (Cortex-M1) ALTERA (NIOS II)ALTERA (NIOS II) Analog Devices (ADSP-21xx)Analog Devices (ADSP-21xx) ARM by various 3 rd -party (Samsung, TI, PHILIPS, etc.)ARM by various 3 rd -party (Samsung, TI, PHILIPS, etc.) ATMEL (SAM7, SAM9)ATMEL (SAM7, SAM9) Energy Micro (Cortex-M4F)Energy Micro (Cortex-M4F) Freescale (9S08)Freescale (9S08) Fujitsu (FR-50, SPARClite)Fujitsu (FR-50, SPARClite) Infineon (TriCore, 80C16x)Infineon (TriCore, 80C16x) Intel (80x86)Intel (80x86) Lattice(Mico32)Lattice(Mico32)

9 2015-09-18MicroC/OS-II(Ch1)8  Major available ports LUMINARY Micro (Cortex-M3)LUMINARY Micro (Cortex-M3) Microchip (PIC24)Microchip (PIC24) MIPS Technologies (M14K)MIPS Technologies (M14K) NXP (ARM7, ARM9)NXP (ARM7, ARM9) Renesas (H8)Renesas (H8) SAMSUNG (ARM7, ARM0)SAMSUNG (ARM7, ARM0) ST (STR7, STR9)ST (STR7, STR9) TI (MSP-430, TMS320)TI (MSP-430, TMS320) Toshiba (Cortex-M3)Toshiba (Cortex-M3) XILINX (MicroBlaze)XILINX (MicroBlaze) Zilog (eZ80, Z-80 and Z-180)Zilog (eZ80, Z-80 and Z-180)

10 2015-09-18MicroC/OS-II(Ch1)9  C/OS-II Features  Open source code  Portable Written in ANSI C + target-specific code written in assembly languageWritten in ANSI C + target-specific code written in assembly language Run on most 8-, 16-, 32- or 64-bit platformsRun on most 8-, 16-, 32- or 64-bit platforms Portable data typesPortable data types –typedef unsigned charINT8U –typedef unsigned intINT16U –typedef unsigned shortINT16U (for 32-bit) –typedef unsigned longINT32U

11 2015-09-18MicroC/OS-II(Ch1)10  ROMable Designed for embedded applicationsDesigned for embedded applications Embedded as part of productsEmbedded as part of products  Scalability using conditional compilation May contain only needed features for a small footprintMay contain only needed features for a small footprint Depending on the processor, the size can be reduced as small as between 5KB to 24KBDepending on the processor, the size can be reduced as small as between 5KB to 24KB

12 2015-09-18MicroC/OS-II(Ch1)11  Fully preemptible real-time, deterministic, multitasking kernel for microprocessors, microcontrollers and DSPs  Multitasking Manage up to 64 tasksManage up to 64 tasks –8 system tasks and 56 application tasks –Up to 63 app tasks allowed No round-robin allowedNo round-robin allowed –Each task has a unique 64 priority levels

13 2015-09-18MicroC/OS-II(Ch1)12  Deterministic The execution time for most of the functions and services is both constant and known in advanceThe execution time for most of the functions and services is both constant and known in advance The execution time is independent of the number of tasks currently runningThe execution time is independent of the number of tasks currently running ExceptionException –OSTimeTick() –Some event flag services(e.g., OSFlagCreate(), OSFlagPost(), etc.)

14 2015-09-18MicroC/OS-II(Ch1)13  Task stacks Each tasks requires its own stackEach tasks requires its own stack Different stack sizes for different tasksDifferent stack sizes for different tasks Exact size can be determined by stack-checking featureExact size can be determined by stack-checking feature –Reduce the amount of RAM needed by an each application code –Use OSTaskStkChk()

15 2015-09-18MicroC/OS-II(Ch1)14  System services SemaphoresSemaphores Mutual Exclusion Semaphores (to reduce priority inversions)Mutual Exclusion Semaphores (to reduce priority inversions) Event FlagsEvent Flags Message MailboxesMessage Mailboxes Message QueuesMessage Queues Task Management (Create, Delete, Change Priority, Suspend/Resume etc.)Task Management (Create, Delete, Change Priority, Suspend/Resume etc.) Fixed Sized Memory Block ManagementFixed Sized Memory Block Management Time ManagementTime Management Timer ManagementTimer Management

16 2015-09-18MicroC/OS-II(Ch1)15  Interrupt management: 255 levels  Robust and Reliable Used in 100s of commercial apps since 1992Used in 100s of commercial apps since 1992 Suitable for Safety Critical Systems common to Aviation and Medical productsSuitable for Safety Critical Systems common to Aviation and Medical products Certifiable for use in Safety Critical SystemsCertifiable for use in Safety Critical Systems –A Validation Suite provides all of the documentation necessary to deliver µC/OS-II as a pre-certifiable software component for safety critical systems –Include avionics RTCA DO-178B and EUROCAE/ ED-12B, medical FDA 510(k), and IEC 61508 standard for transportation and nuclear systems

17 2015-09-18MicroC/OS-II(Ch1)16  Robust and Reliable Revised to follow most of the 127 MISRA C rulesRevised to follow most of the 127 MISRA C rules –The source code for µC/OS-II is now 99% compliant with the Motor Industry Software Reliability Association (MISRA) C Coding Standards. –Improve the safety, reliability and predictability of C programs in critical automotive systems. –Members of the MISRA consortium : Delco Electronics, Ford Motor Company, Jaguar Cars Ltd., Lotus Engineering, Lucas Electronics, Rolls-Royce, Rover Group Ltd., etc.

18 2015-09-18MicroC/OS-II(Ch1)17Applications  Avionics  Medical equipment/devices  Data communications equipment  White goods (Appliances)  Mobile phones, PDAs, MIDs  Industrial controls  Consumer electronics  Automotive  A wide range of embedded applications

19 2015-09-18MicroC/OS-II(Ch1)18 Chapter 1 Getting Started with  C/OS-II

20 2015-09-18MicroC/OS-II(Ch1)19 Installing  C/OS-II  The installation environments Compiler: the Borland Turbo C++ 4.5Compiler: the Borland Turbo C++ 4.5 SW platform: Win95/98/Me/NT/2000/XP computerSW platform: Win95/98/Me/NT/2000/XP computer  Example #1: Basic multitasking Each of 10 tasks displays a specific number at arbitrary locations on the screenEach of 10 tasks displays a specific number at arbitrary locations on the screen #Tasks: 13#Tasks: 13 –2 internal tasks: –The idle task (OS_TaskIdle)(): Executed when all tasks are waiting either for events or for time to expire –A task for CPU usage statistics –Other 11 tasks are created (Listing1.1 on pp3)

21 2015-09-18MicroC/OS-II(Ch1)20 Installing  C/OS-II  Listing 1.2: main() OsInit()OsInit() –Invoked before any other services –Create two tasks –An idle task: Execute when no other task is ready to run –A statistic task: Compute CPU usage PC_DOSSaveReturn()PC_DOSSaveReturn() –Save the processors’s registers for proper return to DOS –Must be called before setting  C/OS-II context-switch vector PC_VectSet(uCos, OSCtxSw)PC_VectSet(uCos, OSCtxSw) –Install the  C/OS-II context-switch handler –uCos: The interrupt vector # (0 ~ 255) –OSCtxSw: The address of the interrupt/exception handler

22 2015-09-18MicroC/OS-II(Ch1)21 Installing  C/OS-II  Listing 1.2 OSSemCreate(INT16U cnt)OSSemCreate(INT16U cnt) –Create a binary semaphore to protect the random-number generator function –Return a handle to the semaphore used for its reference OSStart()OSStart() –Start multitasking and give control to  C/OS-II –At least one task should be created before being called  Listing 1.3: TaskStart() pdata = pdata just for fake reference to avoid compiler warningpdata = pdata just for fake reference to avoid compiler warning TaskStartDispInit()TaskStartDispInit() –Make 25 consecutive calls to PC_DispStr(x,y,s,color) to display an ASCII string s in color from (x,y)

23 2015-09-18MicroC/OS-II(Ch1)22 Installing  C/OS-II  Listing 1.3: TaskStart() PC_VectSet(0x08, OSTickISP): Replace the address of the DOS tick service with one used by  C/OS-IIPC_VectSet(0x08, OSTickISP): Replace the address of the DOS tick service with one used by  C/OS-II PC-SetTickRate(OS_TICKS_PER_SEC): Change the tick rate to 200 rather than 18.2HzPC-SetTickRate(OS_TICKS_PER_SEC): Change the tick rate to 200 rather than 18.2Hz OSStatInit(): Determine the speed of CPU to find out the actual usage of the CPUOSStatInit(): Determine the speed of CPU to find out the actual usage of the CPU TaskStartCreateTasks(): Create N_TASKS identical tasksTaskStartCreateTasks(): Create N_TASKS identical tasks

24 2015-09-18MicroC/OS-II(Ch1)23 Installing  C/OS-II  Listing 1.3: TaskStart() TaskStartDisp(): Display various information at the bottom of the DOS windowTaskStartDisp(): Display various information at the bottom of the DOS window PC_GetKey(): Check if a key is pressedPC_GetKey(): Check if a key is pressed OSTimeDlyHMSM(0, 0, 1, 0): Suspend the current task for 1 sec. to initiate next most important taskOSTimeDlyHMSM(0, 0, 1, 0): Suspend the current task for 1 sec. to initiate next most important task

25 2015-09-18MicroC/OS-II(Ch1)24 Installing  C/OS-II  Listing 1.4: TaskStartCreateTasks() OSTaskCreate(Task, (void *) &TaskData[i],&TaskStk[i][TASK_STK_SIZE-1], i+1)OSTaskCreate(Task, (void *) &TaskData[i],&TaskStk[i][TASK_STK_SIZE-1], i+1) –Task() places an ASCII character at a random location –Create tasks with priorities 1 through 10

26 2015-09-18MicroC/OS-II(Ch1)25 Installing  C/OS-II  Listing 1.5: Task() OSSemPend(RandomSem, 0, &err)OSSemPend(RandomSem, 0, &err) –Acquire the semaphore to guard access to random# generator –Timeout: The value of 0 means no timeout OSTimeDly(1)OSTimeDly(1) –Notify  C/OS-II that it’s done –Delay the current task for 1 clock tick (5ms)

27 2015-09-18MicroC/OS-II(Ch1)26 Installing  C/OS-II  Example #2 shows The amount of stack space used by each taskThe amount of stack space used by each task The amount of free stack spaceThe amount of free stack space The execution time of the stack-checking functionThe execution time of the stack-checking function –Useful when we don’t know –How much stack space needs to be allocated for each task –How much execution time it takes to determine each task stack size

28 2015-09-18MicroC/OS-II(Ch1)27 Installing  C/OS-II  Listing 1.7: main() PC_ElapsedInit()PC_ElapsedInit() –Initialize the elapsed-time-measurement function –Measure the execution time of PC_ElapsedStart() and PC_ElapsedStop() OSTaskStkInit_FPE_x86(&pptos,&ppbos,&psize)OSTaskStkInit_FPE_x86(&pptos,&ppbos,&psize) –Modify the top-of-stack pointer –Called prior to calling OSTaskCreateExt() –Initialize the stack frame of each task for ft-pt operations for Borland v3.x and 4.5x compilers

29 2015-09-18MicroC/OS-II(Ch1)28 Installing  C/OS-II  Listing 1.7: main() OSTaskCreateExt(): Also, modify the stack and check the stack size at run timeOSTaskCreateExt(): Also, modify the stack and check the stack size at run time –Pass the new TOS pointer modified by OSTaskStkInit_FPE_x86() –Pass a task ID, which can be any value –Pass the new size modified by OSTaskStkInit_FPE_x86() –Pass the new TOS pointer modified by OSTaskStkInit_FPE_x86() –Pass a TCB extension pointer –A set of options necessary for stack-size checking and stack clearing

30 2015-09-18MicroC/OS-II(Ch1)29 Installing  C/OS-II  Listing 1.8: TaskStart() TaskStartDispInit() initializes the displayTaskStartDispInit() initializes the display OSMboxCreate(void *msg)OSMboxCreate(void *msg) –Create and initialize a mailbox –Empty when msg is NULL –Allow tasks and ISRs to send a pointer-sized variable to one or more tasks TaskStartCreateTasks()TaskStartCreateTasks() –Create 6 tasks using OSTaskCreateExt() OSTimeDly(OS_TICKS_SEC)OSTimeDly(OS_TICKS_SEC) –Delay TaskSart() for OS_TICKS_SEC ticks

31 2015-09-18MicroC/OS-II(Ch1)30 Installing  C/OS-II  Listing 1.9: Task1() Check the size of the stack for each of 7 application tasksCheck the size of the stack for each of 7 application tasks 6 tasks created by TaskStart() and TaskStart() itself6 tasks created by TaskStart() and TaskStart() itself PC_ElapsedStop() returns the time difference in  secPC_ElapsedStop() returns the time difference in  sec OSTaskStkChk()OSTaskStkChk() –Determine the actual stack usage of a task –Two arguments –The task priority of the task to check –A pointer to a data structure to hold task’s stack information

32 2015-09-18MicroC/OS-II(Ch1)31 Installing  C/OS-II PC_DispStr(x, y, *s, color)PC_DispStr(x, y, *s, color) –x and y: Specify the coordinates (col, row) where the 1st char appears –s: A pointer to the array of chars to display –color: Specify the color combination of the chars to be displayed  Task2()’s wheel spins clockwise at 5 rotations per second while Task3()’s 2.5 rotations per second

33 2015-09-18MicroC/OS-II(Ch1)32 Installing  C/OS-II  Listing 1.11 OSMboxPost(pevent, msg)OSMboxPost(pevent, msg) –pevent: a pointer to the mailbox –msg: the actual message sent to the task OSMBoxPend(AckMbox, 0, &err)OSMBoxPend(AckMbox, 0, &err) –Task4() waits for an Ack from Task5 –The 2 nd argument specifies a timeout as an integral number of clock ticks

34 2015-09-18MicroC/OS-II(Ch1)33 Installing  C/OS-II  Example #3 uses (Fig. 1.5) The TCB extension capabilityThe TCB extension capability The user-defined context-switch hookThe user-defined context-switch hook The user-defined statistic-task hookThe user-defined statistic-task hook Message queuesMessage queues  Listing 1.13 TASK_USER_DATA holds additional information about a taskTASK_USER_DATA holds additional information about a task –Task name –The number of times that a task has executed –Task execution time –Total task execution time OS_EVENT (Listing 6.1 on pp154): Maintain the state of an ECBOS_EVENT (Listing 6.1 on pp154): Maintain the state of an ECB

35 2015-09-18MicroC/OS-II(Ch1)34 Installing  C/OS-II  Listing 1.15, TaskStart() OSQCreate(start, size) creates a message queueOSQCreate(start, size) creates a message queue –start: the base address of the message storage area –Size: the number of entries of the message storage area –Returned value: a pointer to the ECB allocated to the queue TaskStartCreateTasks()TaskStartCreateTasks() –Create six tasks –Each task is assigned an entry in the TaskUserData[] array

36 2015-09-18MicroC/OS-II(Ch1)35 Installing  C/OS-II  Listing 1.16, Task1() ~ Task4() OSQPend((*pevent, timeout, *err)OSQPend((*pevent, timeout, *err) –pevent: a pointer to the queue from which the messages are received –Timeout –Maximum timeout = 65535 –Wait forever if timeout = 0 –Returned value: a message sent by a task or an ISR

37 2015-09-18MicroC/OS-II(Ch1)36 Installing  C/OS-II  Listing 1.17,  C/OS-II’s hooks If OS_CPU_HOOKS_EN = 0, we can declare the hook function in a different fileIf OS_CPU_HOOKS_EN = 0, we can declare the hook function in a different file  Listing 1.18, empty hook functions  Listing 1.19, OSTaskSwHook() Called when  C/OS-II switches from a low priority to a higher priority taskCalled when  C/OS-II switches from a low priority to a higher priority task PC_ElapsedStop() return the execution time of the task being switched outPC_ElapsedStop() return the execution time of the task being switched out

38 2015-09-18MicroC/OS-II(Ch1)37 Installing  C/OS-II Task control block(OS_TCB) (pp81)Task control block(OS_TCB) (pp81) –Maintain the task state when being preempted –OSTCBCur points to the TCB of the current task –OSTCBExtPtr –A pointer to a user-definable TCB extension –Only used by OSTaskCreateExt()

39 2015-09-18MicroC/OS-II(Ch1)38 Installing  C/OS-II  Listing 1.20, OSTaskStatHook() Called every second from the ststistics task OSTaskStat()Called every second from the ststistics task OSTaskStat() DispTaskStat(i)DispTaskStat(i) –Display individual statistics on the screen –Display each task name

40 2015-09-18MicroC/OS-II(Ch1)39 Installing  C/OS-II  Example #4 A port is some processor-specific codeA port is some processor-specific code Create 10 identical tasks, each running 200 times per secondCreate 10 identical tasks, each running 200 times per second Each task computes the sine and cosine of an angleEach task computes the sine and cosine of an angle The angle is offset by 36 degreesThe angle is offset by 36 degrees Every time the task executes, the angle is incremented by 0.01Every time the task executes, the angle is incremented by 0.01

41 2015-09-18MicroC/OS-II(Ch1)40 Installing  C/OS-II  Listing 1.21, TaskStartCreateTasks() (void *)&TaskData[i](void *)&TaskData[i] –An argument passed to a task when it is first started –OS_TASK_OPT_SAVE_FP –Save floating-point registers during a context switch  Listing 1.22, Task() OSTimeDly(1)OSTimeDly(1) –Each task is delayed by 1 tick(50ms) –Each task executes 200 times per second


Download ppt "2015-09-18MicroC/OS-II(Ch1)1 MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ."

Similar presentations


Ads by Google