1 / 40

MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering

MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ. INTRODUCTION. Brief History. Developed in C by Jean Labrosse in 1992 Currently, maintained by Micrium Inc. ( http://www.micrium.com/products/rtos/kernel/rtos.html )

kamea
Download Presentation

MicroC/OS-II : The Real-Time Kernel Prof. Sung Jo Kim School of Computer Science and Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. INTRODUCTION MicroC/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/kernel/rtos.html) • The current version is C/OS-II v3.10(v2.52 for textbook) MicroC/OS-II(Ch1)

  4. Brief History • The new version C/OS-III provides more features • Round-robin scheduling • Allow multiple tasks to run at the same priority level • Near zero interrupt disable time • Unlimited number of application tasks • Error checking and more.  MicroC/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 license • ‘Object Code Distribution License’ is required for commercial products MicroC/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 devices • Actual target: embedded system • Easily portable to many processor (http://www.micrium.com/products/rtos/kernel/ports.html) MicroC/OS-II(Ch1)

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

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

  9. C/OS-II Features • Open source code • Portable • Written in ANSI C + target-specific code written in assembly language • Run on most 8-, 16-, 32- or 64-bit platforms • Portable data types • typedef unsigned char INT8U • typedef unsigned int INT16U • typedef unsigned short INT16U (for 32-bit) • typedef unsigned long INT32U MicroC/OS-II(Ch1)

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

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

  12. Deterministic • The 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 running • Exception • OSTimeTick() • Some event flag services(e.g., OSFlagCreate(), OSFlagPost(), etc.) MicroC/OS-II(Ch1)

  13. Task stacks • Each tasks requires its own stack • Different stack sizes for different tasks • Exact size can be determined by stack-checking feature • Reduce the amount of RAM needed by an each application code • Use OSTaskStkChk() MicroC/OS-II(Ch1)

  14. System services • Semaphores • Mutual Exclusion Semaphores (to reduce priority inversions) • Event Flags • Message Mailboxes • Message Queues • Task Management (Create, Delete, Change Priority, Suspend/Resume etc.) • Fixed Sized Memory Block Management • Time Management • Timer Management MicroC/OS-II(Ch1)

  15. Interrupt management: 255 levels • Robust and Reliable • Used in 100s of commercial apps since 1992 • Suitable for Safety Critical Systems common to Aviation and Medical products • Certifiable 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 MicroC/OS-II(Ch1)

  16. Robust and Reliable • Revised 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. MicroC/OS-II(Ch1)

  17. Applications • 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 MicroC/OS-II(Ch1)

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

  19. Installing C/OS-II • The installation environments • Compiler: the Borland Turbo C++ 4.5 • SW 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 screen • #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) MicroC/OS-II(Ch1)

  20. Installing C/OS-II • Listing 1.2: main() • 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() • 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) • Install the C/OS-II context-switch handler • uCos: The interrupt vector # (0 ~ 255) • OSCtxSw: The address of the interrupt/exception handler MicroC/OS-II(Ch1)

  21. Installing C/OS-II • Listing 1.2 • 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() • 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 warning • TaskStartDispInit() • Make 25 consecutive calls to PC_DispStr(x,y,s,color) to display an ASCII string s in color from (x,y) MicroC/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-II • PC-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 CPU • TaskStartCreateTasks(): Create N_TASKS identical tasks MicroC/OS-II(Ch1)

  23. Installing C/OS-II • Listing 1.3: TaskStart() • TaskStartDisp(): Display various information at the bottom of the DOS window • PC_GetKey(): Check if a key is pressed • OSTimeDlyHMSM(0, 0, 1, 0): Suspend the current task for 1 sec. to initiate next most important task MicroC/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) • Task() places an ASCII character at a random location • Create tasks with priorities 1 through 10 MicroC/OS-II(Ch1)

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

  26. Installing C/OS-II • Example #2 shows • The amount of stack space used by each task • The amount of free stack space • The 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 MicroC/OS-II(Ch1)

  27. Installing C/OS-II • Listing 1.7: main() • PC_ElapsedInit() • Initialize the elapsed-time-measurement function • Measure the execution time of PC_ElapsedStart() and PC_ElapsedStop() • 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 MicroC/OS-II(Ch1)

  28. Installing C/OS-II • Listing 1.7: main() • OSTaskCreateExt(): 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 MicroC/OS-II(Ch1)

  29. Installing C/OS-II • Listing 1.8: TaskStart() • TaskStartDispInit() initializes the display • 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() • Create 6 tasks using OSTaskCreateExt() • OSTimeDly(OS_TICKS_SEC) • Delay TaskSart() for OS_TICKS_SEC ticks MicroC/OS-II(Ch1)

  30. Installing C/OS-II • Listing 1.9: Task1() • Check the size of the stack for each of 7 application tasks • 6 tasks created by TaskStart() and TaskStart() itself • PC_ElapsedStop() returns the time difference in sec • 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 MicroC/OS-II(Ch1)

  31. Installing C/OS-II • 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 MicroC/OS-II(Ch1)

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

  33. Installing C/OS-II • Example #3 uses (Fig. 1.5) • The TCB extension capability • The user-defined context-switch hook • The user-defined statistic-task hook • Message queues • Listing 1.13 • TASK_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 ECB MicroC/OS-II(Ch1)

  34. Installing C/OS-II • Listing 1.15, TaskStart() • OSQCreate(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() • Create six tasks • Each task is assigned an entry in the TaskUserData[] array MicroC/OS-II(Ch1)

  35. Installing C/OS-II • Listing 1.16, Task1() ~ Task4() • 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 MicroC/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 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 task • PC_ElapsedStop() return the execution time of the task being switched out MicroC/OS-II(Ch1)

  37. Installing C/OS-II • 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() MicroC/OS-II(Ch1)

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

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

  40. Installing C/OS-II • Listing 1.21, TaskStartCreateTasks() • (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) • Each task is delayed by 1 tick(50ms) • Each task executes 200 times per second MicroC/OS-II(Ch1)

More Related