Stellaris® Robotic Evaluation Board and Micriµm µC/OS-III Dexter Travis, Stellaris ARM® Cortex™-M3 Applications Engineering Jean J. Labrosse, Founder, President and CEO of Micriµm 1 Introductions •Jean J. Labrosse –Founder, President and CEO of Micriµm •Dexter Travis –Stellaris® ARM® Cortex™-M3 Applications Engineering 2 Find the right ARM® Solution for you 32-bit ARM MCU for Safety-Critical Applications 32-bit ARM Cortex™-M3 MCUs ARM Cortex-A8 & ARM9™ MPUs TMS570 Stellaris® Sitara™ ARM Cortex-R4™ ARM Cortex-M3 Up to 250 DMIPS/ 160 MHz Up to 80 MHz 375MHz to >1GHz 2 MB Flash, 160 KB RAM Flash 8 KB to 256 KB USB, ENET MAC+PHY CAN, ADC, PWM, SPI Connectivity,Security, Motion Control, HMI, Industrial Automation Cache, RAM, ROM 300MHz to >1Ghz +Accelerator Cache RAM, ROM USB, CAN, SATA, SPI, PCIe, EMAC USB, ENET, PCIe, SATA, SPI Industrial automation, POS & portable data terminals $1.00 to $8.00 $5.00 to $25.00 Floating/Fixed Point Video, Audio, Voice, Security, Conferencing $5.00 to $200.00 ARM Cortex-A8 & ARM9 DSP DSP+ARM C6000™ Integra™ DaVinci™ Digital Media processors FPU, ECC, Timer/PWM Co-Proc, 12bit ADCs, CAN, EMIF, LIN, SPI, Flexray Transportation, Motor Control, Certified for use in safety critical (SIL3) systems $7.00 to $18.00 Responsive design support Development tools Software support Comprehensive developer ecosystem Agenda • RTOSs and Real-Time Kernels – A brief introduction • Micriµm - µC/OS-III – – – – – Summary of features Scheduling and Context Switching Synchronization Message Passing Other Services • Texas Instruments - EVALBOT – Features – Examples – Demo RTOS vs Real-Time Kernels Application Keyboard Keyboard Controller Graphical User Interface Display Controller Touch Screen Controller Interrupt Controller Timer Real-Time Kernel RTOS (MAC/PHY) TCP/IP Stack TCP/IP Apps File System Media Controller Audio I2S Controller CAN CAN Controller Modbus RS-232C RS-485 Other USB (Host) (Device) USB Stacks © 2010, Micriµm, All Rights Reserved (Shell) (Clk) (CRC) (etc.) Touch Interface Media CPU Ethernet Controller Display with optional www.Micrium.com (SD) (MMC) (NAND Flash) (NOR Flash) (CF) (RAM Disk) Other What is a Real-Time Kernel? Software that manages the time of a CPU Performs multitasking – ‘Switches’ the CPU between tasks – Highest priority task runs on the CPU – Round-robins tasks of equal priority Provides valuable services to an application: – – – – – – – – Task management Synchronization Mutual exclusion management Message passing Memory management Time management Soft-timer management Other © 2010, Micriµm, All Rights Reserved www.Micrium.com What is a Real-Time Kernel? High Priority Task Task Task Importance Task Each Task Task Task Task Low Priority Task © 2010, Micriµm, All Rights Reserved Event Event Task Task Infinite Loop Task www.Micrium.com Preemptive Kernels Via a kernel call, the ISR makes the high priority task ready Interrupt occurs ISR ISR completes and the kernel switches to the high-priority task ISR High-priority task The kernel switches to the low-priority task Low-priority task Time © 2010, All Rights Reserved © 2009, Micriµm,Micriµm, All Rights Reserved www.Micrium.com www.Micrium.com What is µC/OS-III? A third generation Real-Time Kernel – Has roots in µC/OS-II, the world’s most popular Real-Time Kernel µC/OS-II’s internals were described in the book: “MicroC/OS-II, The Real-Time Kernel” (1998) A new 850+ page book: – “µC/OS-III, The Real-Time Kernel” – Describes µC/OS-III’s internals – The book comes with: A Cortex-M3 based evaluation board – Featuring TI’s LM3S9B92 Links to download: – Sample code to run µC/OS-III – IAR’s 32K KickStart tools – A trial version of µC/Probe – Companion EVALBOT 5 Example projects © 2010, Micriµm, All Rights Reserved www.Micrium.com µC/OS-III Summary of Key Features Preemptive Multitasking – Round-robin scheduling of equal-priority tasks ROMable Scalable – Adjustable footprint – Compile-time and run-time configurable Portable – All µC/OS-II ports can be adapted to µC/OS-III Rich set of services – Task Management, Time Management, Semaphores, Mutexes, Message Queues, Soft Timers, Memory Management, Event Flags and more © 2010, Micriµm, All Rights Reserved www.Micrium.com µC/OS-III Summary of Key Features Real-Time, Deterministic – Reduced interrupt and task latency Built-in Performance Measurement – – – – – Measures interrupt disable time on a per-task basis Measures stack usage for each task Keeps track of the number of context switches for each task Measures the ISR-to-Task and Task-to-Task response time And more Cleanest source code in the industry Consistent API Run-Time argument checking © 2010, Micriµm, All Rights Reserved www.Micrium.com Typical µC/OS-III Tasks void { } MyTask (void *p_arg) Do something with ‘argument’ p_arg; Task initialization; for (;;) { Wait for event; /* Time to expire ... /* Signal/Msg from ISR ... /* Signal/Msg from task ... /* Processing (Your Code) } */ */ */ */ Variables Arrays Structures CPU Registers Task (Priority) Stack (RAM) © 2010, Micriµm, All Rights Reserved www.Micrium.com I/O Devices (Optional) ‘Creating’ a Task You create a task by calling a service provided by the kernel: Task Control Block OSTaskCreate(OS_TCB CPU_CHAR OS_TASK_PTR void OS_PRIO CPU_STK CPU_STK OS_STK_SIZE OS_MSG_QTY OS_TICK void OS_OPT OS_ERR © 2010, Micriµm, All Rights Reserved *p_tcb, *p_name, p_task, *p_arg, prio, *p_stk_base, *p_stk_limit, stk_size, q_size, time_slice, *p_ext, opt, *p_err); www.Micrium.com Task Name Task Start Address Priority Stack Stack Limit Stack Size Time Slice Options The µC/OS-III Scheduler Using Count Leading Zeros (CLZ) The Cortex-M3 has a CLZ instruction – Makes scheduling much faster … ex. with 64 priorities ReadyTbl[] 0 31 [0] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [1] 0 0 0 0 0 1 1 0 1 1 1 1 0 1 1 1 32 63 Ready Priority = 37 if (ReadyTbl[0] == 0) Prio = CLZ(ReadyTbl[1]) + 32; else Prio = CLZ(ReadyTbl[0]); © 2010, Micriµm, All Rights Reserved www.Micrium.com #Zeros 32 5 The µC/OS-III Ready List Highest Priority Multiple Tasks At Same Priority Lowest Priority © 2010, Micriµm, All Rights Reserved www.Micrium.com Context Switch ARM Cortex-M3 for µC/OS-III (1): Current task’s CPU registers are saved on current task’s stack (2): CPU’s SP register is saved in current task’s TCB (3): New task’s SP is restored from the new task’s TCB (4): CPU registers are restored from the new task’s stack © 2010, Micriµm, All Rights Reserved www.Micrium.com Resource Management (Mutual Exclusion Semaphore) Delta TS © 2010, Micriµm, All Rights Reserved www.Micrium.com Synchronization (Semaphores) Delta TS © 2010, Micriµm, All Rights Reserved www.Micrium.com Synchronization (Event Flags) Delta TS © 2010, Micriµm, All Rights Reserved www.Micrium.com Message Passing (Message Queues) Delta TS © 2010, Micriµm, All Rights Reserved www.Micrium.com Other µC/OS-III Features Task Management – Suspend/Resume a task – Delete a task Time Management Software Timers Fixed-Size Memory Partitions Pending on Multiple Objects And more. © 2010, Micriµm, All Rights Reserved www.Micrium.com µC/Probe © 2010, Micriµm, All Rights Reserved www.Micrium.com What is µC/Probe? ‘Windows’ application to display/change target data: – ANY variable – ANY memory location – ANY I/O port Works with ANY processor – 8-, 16-, 32-, 64-bit or DSP Works with ANY compiler – Compiler/linker needs to generate an ELF/DWARF file such as Embedded Workbench Supports many interfaces – – – – – – RS-232C USB TCP/IP (Ethernet) J-Link SWD (Cortex-M3) … NO target resident coded needed! Others Target doesn’t need an RTOS – Works with or without an RTOS © 2010, Micriµm, All Rights Reserved www.Micrium.com µC/Probe µC/OS-III Task Awareness Task Name Task Priority Max Interrupt Disable Time © 2010, Micriµm, All Rights Reserved % CPU Usage Stack Usage #Context Switches ISR to Task Response www.Micrium.com To run the book examples … you will need: • The µC/OS-III book • The TI EVALBOT – http://www.ti.com/evalbot • Download and install the IAR 32K edition of Embedded Workbench for the ARM (V5.5) – http://supp.iar.com/Download/SW/?item=EWARM-KS32 – You will need to install the J-Link driver • Download and unzip the µC/OS-III book examples: – http://www.Micrium.com/Books/Micrium-uCOS-III • Download and install the non-time limited TRIAL version of µC/Probe: – http://www.Micrium.com/Books/Micrium-uCOS-III Texas Instruments EVALBOT unassembled 26 Texas Instruments EVALBOT Bumpers (2) User Switches (2) Speaker Stellaris LM3S9B92 USB-Device Connector USB-Host Connector 96x6 OLED Display RJ45 10/100 Ethernet ON/OFF Switch MicroSD Socket Motor/Wheel (2) In-Circuit Debug Interface Batteries (3 AA) Examples • Example 1: Simple Display – Rotates a series of messages on the Display – Blinks LEDS on the board • Example 2: Using Audio – Bump sensors select next or previous wav track – SWITCH2 begins audio playback, SWITCH1 stops playback • Example 3: Simple Control – Manual start/stop of the motor via SWITCH1, SWITCH2 and bump sensors • Example 4: Autonomous Control – EVALBOT moves randomly and reacts to sensor inputs. 28 Autonomous EVALBOT Control Control Task queues commands to motor tasks If Timer expires a random turn is initiated Motor Tasks receives command, interprets and posts to PID Task PID Task closes motor control loop based on feedback from speed sensor interrupt handlers Input Monitor Task posts flags to Control Task speed sensor interrupts relay data back to PID Task buttons and Bump Sensor trigger Input monitor task 29