1 / 13

Getting Started with the µC/OS-III Real Time Kernel

Getting Started with the µC/OS-III Real Time Kernel. Akos Ledeczi EECE 354, Fall 2012 Vanderbilt University. What is an RTK?. The main task of an RTK is to manage time and the resources of a (typically embedded) computer Multitasking Creation Scheduling Synchronization Communication

tyler
Download Presentation

Getting Started with the µC/OS-III Real Time Kernel

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. Getting Started with theµC/OS-IIIReal Time Kernel Akos Ledeczi EECE 354, Fall 2012 Vanderbilt University

  2. What is an RTK? • The main task of an RTK is to manage time and the resources of a (typically embedded) computer • Multitasking • Creation • Scheduling • Synchronization • Communication • Resource management: • Memory • IO • Interrupt management • Time management • What is an RTOS? • An RTK plus higher level services such as file system, networking, GUI, etc.

  3. Multitasking • Also called multithreading or concurrent programming • Multiple, sequential tasks (or threads) • Creating the illusion of having multiple CPUs • The task body is just a C function • Each task has its own stack • The same body can be reused for multiple tasks • Synchronization and communication are very important and complicated • Advantages: • Modular code • Manages complexity inherent in RT systems • Cleaner and easier to understand and maintain

  4. Multitasking cont’d. • Because of the need to respond to timing demands made by different stimuli/responses, the system architecture must allow for fast switching between stimulus handlers. • Because of different priorities, unknown ordering and different timing requirements of different stimuli, a simple sequential loop is not usually adequate. • Real-time systems are therefore usually designed as cooperating processes with a real-time kernel controlling these processes.

  5. µC/OS-III: Creating and Initializing an App • Start in main(): • Disable interrupts • Initialize OS • Create a single Task using TaskCreate() • Start OS: start multitasking and switch to the highest priority enabled task

  6. OS Initialization • Initializes internal data structures • Creates up to 5 Tasks: • Idle Task (lowest priority task that runs when nothing else is available for running; it never blocks) • Tick Task (keeps track of time) • Statistics (optional) • Timer (optional) • Interrupt queue management (optional)

  7. Task Creation • OSTaskCreate() • 13 arguments: • Task Control Block (TCB): data structure that the OS uses to manage the task and store all relevant info about it (e.g. stack pointer, priority, pointers to manage queues, etc.) • Name • Function pointer to actual code • Argument for the task (e.g., a pointer to a task-specific memory making the C function reusable for multiple tasks) • Stack pointer, watermark, size • Error code • Etc.

  8. Initial task • Initialize hardware and CPU related things • Set up tick interrupt (rate = OSCfg_TickRateHz) • Enable interrupts • Create additional tasks (optional) • Infinite loop: • Inside there must be a blocking call

  9. Critical Sections • Code that needs to run indivisibly • Access to shared resources, for example, hardware device, shared variable, data structures, etc. • How? • Disable interrupts • Lock the scheduler • Use semaphores • Finer control (on a task by task basis) • More overhead

  10. Semaphores • Dijkstra in 1959 • “Key” to “locked code.” You need to acquire it to access the code. • Semaphore operations are “atomic.” • Binary and counting semaphores • Can be used for resource sharing and synchronization • Functions: OSSemCreate() OSSemPend() OSSemPost() OSSemDel() OSSemSet() OSSemPendAbort()

  11. Binary Semaphores • Accessing a printer • Hiding behind an API

  12. Binary Semaphores cont’d. OS_SEM MySem; void main() { OS_ERR err; … OSSemCreate(&MySem, ”My Semaphore”, 1, &err); … } void Task1 (void *p_arg) OS_ERR err; CPU_TS ts; while (1) { … OSSemPend(&MySem, 0, OS_OPT_PEND_BLOCKING, &ts, &err); /*critical section */ OSSemPost(&MySem, OS_OPT_POST_1, &err); /* check err */ } }

  13. Counting Semaphores • When multiple resources/resource elements are available • E.g., memory pool or circular buffer • Initialize semaphore to the number of items available • Need to manage consumed/available items • Pend() waits on 0, otherwise, decrements counter and returns • Post() increments counter

More Related