120 likes | 368 Views
MicroC/OS-II. Embedded Systems Design and Implementation. MicroC/OS-2. Real-time kernel 5,500 lines of code portable (written in ANSI C) ROMable Scalable (services selectable) Preemptive Multitasking Interrupt management Rich services. Accessing critical section.
E N D
MicroC/OS-II Embedded Systems Design and Implementation
MicroC/OS-2 • Real-time kernel • 5,500 lines of code • portable (written in ANSI C) • ROMable • Scalable (services selectable) • Preemptive • Multitasking • Interrupt management • Rich services
Accessing critical section • OS_ENTER_CRITICAL -- disabling interrupt • OS_EXIT_CRITICAL -- enabling interrupt
Issues with disabling interrupt • If you call the processor supported instruction directly • you may get inconsistency • Use PSW (processor status word) • can be done on the stack or local variable
Tasks • A task is often written as an infinite loop or as self-terminating • MicroC/OS-II supports 64 tasks, two are used by the system (priority 62 and 63) • lower number = higher priority • each task must have a unique priority; thus task id = task priority
Task creation • can be done prior to multitasking or dynamically • what happens of the priority of the created task is higher than its creator? • a task can suspend itself or wait for for events to occur
Task States task waiting task dormant task ready task running ISR running
Task control block • data structure that is used to maintain the state of a task when it is preempted so that it can resume where it left off • maintain information about the runtime stack (current top of stack, bottom of stack, stack size) • CPU content is saved on the stack
Task scheduling • execute the highest priority task ready to run • task scheduling is done in constant time • context switch is done through software trap • save CPU content of preempted task • restore CPU content of the next running task
Locking scheduler • allows a task to keep control of the CPU • interrupts still being serviced if enabled • locking function can be nested 255 levels deep
Idle and statistics tasks • idle task -- lowest priority task • increment counters to support statistics task • statistics task -- lowest-prio - 1 • compute the percentage of CPU usage