uCOS-01

March 27, 2018 | Author: Kagitha Tirumala | Category: Electronics, Digital & Social Media, Digital Technology, Computer Hardware, Software


Comments



Description

MicroC/OS-II : The Real-Time KernelProf. Sung Jo Kim School of Computer Science and Engineering Chung-Ang Univ. 2014-01-06 MicroC/OS-II(Ch1) 1 INTRODUCTION 2014-01-06 MicroC/OS-II(Ch1) 2 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)  The current version is C/OS-II v3.10(v2.52 for textbook) 2014-01-06 MicroC/OS-II(Ch1) 3 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. 2014-01-06 MicroC/OS-II(Ch1) 4 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 2014-01-06 MicroC/OS-II(Ch1) 5 . preemptive. scalable. deterministic multitasking kernel for microprocessors. ROMable. real-time.Brief History  C/OS-II • A highly portable.micrium.com/products/rtos/kernel/po rts.html) 2014-01-06 MicroC/OS-II(Ch1) 6 . microcontrollers and DSP-based devices • Actual target: embedded system • Easily portable to many processor (http://www. ) ATMEL (SAM7. SPARClite) Infineon (TriCore. TI. Major available ports • • • • • • • • • • • ACTEL (Cortex-M1) ALTERA (NIOS II) Analog Devices (ADSP-21xx) ARM by various 3rd-party (Samsung. SAM9) Energy Micro (Cortex-M4F) Freescale (9S08) Fujitsu (FR-50. 80C16x) Intel (80x86) Lattice(Mico32) MicroC/OS-II(Ch1) 7 2014-01-06 . PHILIPS. etc. Z-80 and Z-180) MicroC/OS-II(Ch1) 8 2014-01-06 . STR9) TI (MSP-430. ARM9) Renesas (H8) SAMSUNG (ARM7. ARM0) ST (STR7. Major available ports • • • • • • • • • • • LUMINARY Micro (Cortex-M3) Microchip (PIC24) MIPS Technologies (M14K) NXP (ARM7. TMS320) Toshiba (Cortex-M3) XILINX (MicroBlaze) Zilog (eZ80. or 64-bit platforms • Portable data types – typedef – typedef – typedef – typedef 2014-01-06 unsigned unsigned unsigned unsigned char int short long INT8U INT16U INT16U (for 32-bit) INT32U 9 MicroC/OS-II(Ch1) .C/OS-II Features  Open source code  Portable • Written in ANSI C + target-specific code written in assembly language • Run on most 8-. 32. 16-.  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 2014-01-06 MicroC/OS-II(Ch1) 10 .  Fully preemptible real-time. multitasking kernel for microprocessors. microcontrollers and DSPs  Multitasking • Manage up to 64 tasks – 8 system tasks and 56 application tasks – Up to 63 app tasks allowed – Each task has a unique 64 priority levels • No round-robin allowed 2014-01-06 MicroC/OS-II(Ch1) 11 . deterministic. .) 2014-01-06 MicroC/OS-II(Ch1) 12 . OSFlagPost(). 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. OSFlagCreate().g. etc.  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() 2014-01-06 MicroC/OS-II(Ch1) 13 .  System services • Semaphores • Mutual Exclusion Semaphores (to reduce priority inversions) • Event Flags • Message Mailboxes • Message Queues • Task Management (Create. Change Priority.) • Fixed Sized Memory Block Management • Time Management • Timer Management 2014-01-06 MicroC/OS-II(Ch1) 14 . Delete. Suspend/Resume etc. medical FDA 510(k). and IEC 61508 standard for transportation and nuclear systems 2014-01-06 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. Lotus Engineering. 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. reliability and predictability of C programs in critical automotive systems. – Improve the safety. – Members of the MISRA consortium : Delco Electronics. etc.. 2014-01-06 MicroC/OS-II(Ch1) 16 . Lucas Electronics.. Rolls-Royce. Jaguar Cars Ltd. Rover Group Ltd. Ford Motor Company. 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 2014-01-06 MicroC/OS-II(Ch1) 17 . Chapter 1 Getting Started with C/OS-II 2014-01-06 MicroC/OS-II(Ch1) 18 . 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) 2014-01-06 MicroC/OS-II(Ch1) 19 . OSCtxSw) – Install the C/OS-II context-switch handler – uCos: The interrupt vector # (0 ~ 255) – OSCtxSw: The address of the interrupt/exception handler 2014-01-06 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. y.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.Installing C/OS-II  Listing 1.color) to display an ASCII string s in color from (x.3: TaskStart() • pdata = pdata just for fake reference to avoid compiler warning • TaskStartDispInit() – Make 25 consecutive calls to PC_DispStr(x.y) 2014-01-06 MicroC/OS-II(Ch1) 21 .s. 2Hz • OSStatInit(): Determine the speed of CPU to find out the actual usage of the CPU • TaskStartCreateTasks(): Create N_TASKS identical tasks 2014-01-06 MicroC/OS-II(Ch1) 22 .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.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.Installing C/OS-II  Listing 1. 1. to initiate next most important task 2014-01-06 MicroC/OS-II(Ch1) 23 . 0): Suspend the current task for 1 sec. 0. Installing C/OS-II  Listing 1.&TaskStk[i][TASK_STK_SIZE-1].4: TaskStartCreateTasks() • OSTaskCreate(Task. (void *) &TaskData[i]. i+1) – Task() places an ASCII character at a random location – Create tasks with priorities 1 through 10 2014-01-06 MicroC/OS-II(Ch1) 24 . 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) 2014-01-06 MicroC/OS-II(Ch1) 25 .Installing C/OS-II  Listing 1.5: Task() • OSSemPend(RandomSem. 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 2014-01-06 MicroC/OS-II(Ch1) 26 . x and 4.Installing C/OS-II  Listing 1.&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.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.5x compilers 2014-01-06 MicroC/OS-II(Ch1) 27 . 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 2014-01-06 MicroC/OS-II(Ch1) 28 . 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.7: main() • OSTaskCreateExt(): Also.Installing C/OS-II  Listing 1. 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 2014-01-06 MicroC/OS-II(Ch1) 29 . 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 2014-01-06 MicroC/OS-II(Ch1) 30 . y.5 rotations per second 2014-01-06 MicroC/OS-II(Ch1) 31 .Installing C/OS-II • PC_DispStr(x. *s. 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. color) – x and y: Specify the coordinates (col. Installing C/OS-II  Listing 1. &err) – Task4() waits for an Ack from Task5 – The 2nd argument specifies a timeout as an integral number of clock ticks 2014-01-06 MicroC/OS-II(Ch1) 32 .11 • OSMboxPost(pevent. msg) – pevent: a pointer to the mailbox – msg: the actual message sent to the task • OSMBoxPend(AckMbox. 0. 5) • • • • The TCB extension capability The user-defined context-switch hook The user-defined statistic-task hook Message queues  Listing 1. 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 2014-01-06 MicroC/OS-II(Ch1) 33 .Installing C/OS-II  Example #3 uses (Fig. TaskStart() • OSQCreate(start.Installing C/OS-II  Listing 1. 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 2014-01-06 MicroC/OS-II(Ch1) 34 .15. timeout.Installing C/OS-II  Listing 1. Task1() ~ Task4() • OSQPend((*pevent. *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 2014-01-06 MicroC/OS-II(Ch1) 35 .16. 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 2014-01-06 MicroC/OS-II(Ch1) 36 . empty hook functions  Listing 1.19.Installing C/OS-II  Listing 1.18.17. we can declare the hook function in a different file  Listing 1. C/OS-II’s hooks • If OS_CPU_HOOKS_EN = 0. 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() 2014-01-06 MicroC/OS-II(Ch1) 37 . 20.Installing C/OS-II  Listing 1. OSTaskStatHook() • Called every second from the ststistics task OSTaskStat() • DispTaskStat(i) – Display individual statistics on the screen – Display each task name 2014-01-06 MicroC/OS-II(Ch1) 38 . 01 2014-01-06 MicroC/OS-II(Ch1) 39 .Installing C/OS-II  Example #4 • A port is some processor-specific code • Create 10 identical tasks. the angle is incremented by 0. 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. 22.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. Task() • OSTimeDly(1) – Each task is delayed by 1 tick(50ms) – Each task executes 200 times per second 2014-01-06 MicroC/OS-II(Ch1) 40 .
Copyright © 2024 DOKUMEN.SITE Inc.