+ All Categories

uCOSII

Date post: 04-Jun-2018
Category:
Upload: kagitha-tirumala
View: 221 times
Download: 0 times
Share this document with a friend

of 31

Transcript
  • 8/13/2019 uCOSII

    1/31

    :

    :

    Email: [email protected]

    URL : http://ccc.kmit.edu.tw

    : 2014/1/19

    Micro C/OS II

    mailto:[email protected]://ccc.kmit.edu.tw/http://ccc.kmit.edu.tw/mailto:[email protected]
  • 8/13/2019 uCOSII

    2/31

    2 - 2014/1/19

    Micro C/OS II Micro-Controller Operating Systems, Version 2

    Jean J. Labresse, MicroC/OS-II: The Real-Time

    Kernel, CMP Book, ISBN:1-57820-103-9

    http://www.uCOS-II.com

    http://www.ucos-ii.com/http://www.ucos-ii.com/http://www.ucos-ii.com/http://www.ucos-ii.com/
  • 8/13/2019 uCOSII

    3/31

    3 - 2014/1/19

    Micro C/OS II

    C

    Preemptible priority-driven real-time scheduling.

    550020KB

    64 priority levels (max 64 tasks)

    8 reserved for uC/OS-II

    Each task is an infinite loop.

    Deterministic execution times for most

    uC/OS-II functions and services.

    Nested interrupts could go up to 256 levels.

  • 8/13/2019 uCOSII

    4/31

    4 - 2014/1/19

    Supports of various 8-bit to 64-bit platforms:x86, 68x, MIPS, 8051, etc

    Easy for development: Borland C++compiler

    and DOS (optional). However, uC/OS-II still lacks of the following

    features:

    Resource synchronization protocols. Sporadic task support.

    Soft-real-time support.

  • 8/13/2019 uCOSII

    5/31

    5 - 2014/1/19

    Getting started with uC/OS-II!

    See how a uC/OS-II program looks like.

    Learn how to write a skeleton program for uC/OS-

    II.

    How to initialize uC/OS-II?

    How to create real-time tasks?

    How to use inter-task communicationmechanisms?

    How to catch system events?

  • 8/13/2019 uCOSII

    6/31

    6 - 2014/1/19

    Mail Box

    A mailbox is for data exchanging between tasks. A mailbox consists of a data pointer and a wait-list.

    OSMboxPend(): The message in the mailbox is retrieved.

    If the mailbox is empty, the task is immediately blocked and movedto the wait-list.

    A time-out value can be specified.

    OSMboxPost():

    A message is posted in the mailbox. If there is already a message in the mailbox, then an error is

    returned (not overwritten).

    If tasks are waiting for a message from the mailbox, then the taskwith the highest priority is removed from the wait-list and scheduledto run.

  • 8/13/2019 uCOSII

    7/31

    7 - 2014/1/19

    Message Queue

    A message queue consists of an array of

    elements and a wait-list.

    Different from a mailbox, a message queue

    can hold many data elements (in a FIFO

    basis).

  • 8/13/2019 uCOSII

    8/31

    8 - 2014/1/19

    Hooks (User Customizable)

    void OSInitHookBegin (void)

    void OSInitHookEnd (void)

    void OSTaskCreateHook (OS_TCB *ptcb)

    void OSTaskDelHook (OS_TCB *ptcb)

    void OSTaskIdleHook (void)

    void OSTaskStatHook (void)

    void OSTaskSwHook (void) void OSTCBInitHook (OS_TCB *ptcb)

    void OSTimeTickHook (void)

  • 8/13/2019 uCOSII

    9/31

    9 - 2014/1/19

    Critical Section

    A critical section is a portion of code that is not safe from raceconditions because of the use of shared resources. They can be protected by interrupt disabling/enabling interrupts or

    semaphores.

    The use of semaphores often imposes a more significant amount of

    overheads. A RTOS often use interrupts disabling/enabling to protect critical

    sections.

    Once interrupts are disabled, neither context switches nor any otherISRs can occur.

    Interrupt latency is vital to an RTOS!

    Interrupts should be disabled as short as possible to improve theresponsiveness.

    It must be accounted as a blocking time in the schedulabilityanalysis.

    Interrupt disabling must be used carefully: E.g., if OSTimeDly() is called with interrupt disabled, the machine might hang!

  • 8/13/2019 uCOSII

    10/31

    10 - 2014/1/19

    Real Time System

  • 8/13/2019 uCOSII

    11/31

    11 - 2014/1/19

  • 8/13/2019 uCOSII

    12/31

    12 - 2014/1/19

  • 8/13/2019 uCOSII

    13/31

    13 - 2014/1/19

    (Task state)

    OSStart()

    OSIntExit()OS_TASK_SW()

    Dormant

    Ready

    Running ISR

    Waiting

  • 8/13/2019 uCOSII

    14/31

    14 - 2014/1/19

    Waiting

    Dormant

    Ready Running

    ISR

    OSIntExit

    OSMBoxPend()

    OSQPend()OSSemPend()

    OSTaskSuspend()

    OSTimeDly()

    OSTimeDlyHMSM()

    OSMBoxPost()OSQPost()

    OSPostFront()

    OSSemPost()

    OSTaskRusume()

    OSTaskDlyResume()

    OSTimeTick()

    OSTaskDel()

    OSTaskDel()

    OSTaskCreate()OSTaskCreateExt()

    Preempted

    OSStart()

    OSIntExit()OS_TASK_SW()

  • 8/13/2019 uCOSII

    15/31

    15 - 2014/1/19

  • 8/13/2019 uCOSII

    16/31

    16 - 2014/1/19

    TCB (Task Control Block)

  • 8/13/2019 uCOSII

    17/31

    17 - 2014/1/19

    Ready List

  • 8/13/2019 uCOSII

    18/31

    18 - 2014/1/19

    Ready List

  • 8/13/2019 uCOSII

    19/31

    19 - 2014/1/19

    Ready List - Coding Style

    Ready List if ((OSRdyTbl[prio >> 3] &= ~OSMapTbl[prio & 0x07]) == 0)

    OSRdyGrp &= ~OSMapTbl[prio >> 3];

  • 8/13/2019 uCOSII

    20/31

    20 - 2014/1/19

    Task Scheduling

  • 8/13/2019 uCOSII

    21/31

    21 - 2014/1/19

    Task Scheduling

    A context switch must save all CPU registers and PSW of thepreempted task onto its stack, and then restore the CPUregisters and PSW of the highest-priority ready task from itsstack.

    Task-level scheduling will emulate that as ifpreemption/scheduling is done in an ISR. OS_TASK_SW() will trigger a software interrupt.

    The interrupt is directed to the context switch handler OSCtxSw(),which is installed when uC/OS-II is initialized.

    Interrupts are disabled during the locating of the highest-priorityready task to prevent another ISRs from making some tasksready.

  • 8/13/2019 uCOSII

    22/31

    22 - 2014/1/19

    OSSchedLock()

  • 8/13/2019 uCOSII

    23/31

    23 - 2014/1/19

    OSSchedUnLock()

  • 8/13/2019 uCOSII

    24/31

    24 - 2014/1/19

    Statistics Task

  • 8/13/2019 uCOSII

    25/31

    25 - 2014/1/19

    Interrupts

  • 8/13/2019 uCOSII

    26/31

    26 - 2014/1/19

    Initialize

  • 8/13/2019 uCOSII

    27/31

    27 - 2014/1/19

    Initialize

  • 8/13/2019 uCOSII

    28/31

    28 - 2014/1/19

    Starting

  • 8/13/2019 uCOSII

    29/31

    29 - 2014/1/19

  • 8/13/2019 uCOSII

    30/31

    30 - 2014/1/19

    (1)

    OSTaskCreate()

    OSTaskCreateExt()

    OSTaskDel()

    OSStart() uCOSII

    OSIntExit()

    OS_TASK_SW()

    Preempted

    Interrput

  • 8/13/2019 uCOSII

    31/31

    31 - 2014/1/19

    (2) OSMBoxPend()

    OSQPend()

    OSSemPend() (Semaphore)

    OSTaskSuspend()

    OSTaskResume()

    OSTimeDly() Time Click ()

    OSTimeDlyHMSM()

    OSMBoxPost()

    OSQPost()

    OSSemPost() Semaphore

    OSTaskDlyResume() uCOSII\LPC210x\CH11_uCOS-II\lpc2100\Os_cpu_a.s

    http://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.shttp://localhost/var/www/apps/conversion/tmp/scratch_3/uCOSII/LPC210x/CH11_uCOS-II/lpc2100/Os_cpu_a.s

Recommended