logo资料库

嵌入式实时操作系统uC/OS III.pdf

第1页 / 共848页
第2页 / 共848页
第3页 / 共848页
第4页 / 共848页
第5页 / 共848页
第6页 / 共848页
第7页 / 共848页
第8页 / 共848页
资料共848页,剩余部分请下载后查看
Book Cover
Table of Contents
Part I
Foreword to µC/OS-III — by Jack Ganssle
Preface
Introduction
1-1 Foreground/Background Systems
1-2 Real-Time Kernels
1-3 RTOS (Real-Time Operating System)
1-4 µC/OS-III
1-5 µC/OS, µC/OS-II and µC/OS-III Features Comparison
1-6 How the Book is Organized
1-7 µC/Probe
1-8 Conventions
1-9 Chapter Contents
1-10 Licensing
1-11 Contacting Micrium
Directories and Files
2-1 Application Code
2-2 CPU
2-3 Board Support Package (BSP)
2-4 µC/OS-III, CPU Independent Source Code
2-5 µC/OS-III, CPU Specific Source Code
2-6 µC/CPU, CPU Specific Source Code
2-7 µC/LIB, Portable Library Functions
2-8 Summary
Getting Started with µC/OS-III
3-1 Single Task Application
3-2 Multiple Tasks Application with Kernel Objects
Critical Sections
4-1 Disabling Interrupts
4-1-1 Measuring Interrupt Disable Time
4-2 Locking the Scheduler
4-2-1 Measuring Scheduler Lock Time
4-3 µC/OS-III Features with Longer Critical Sections
4-4 Summary
Task Management
5-1 Assigning Task Priorities
5-2 Determining the Size of a Stack
5-3 Detecting Task Stack Overflows
5-4 Task Management Services
5-5 Task Management Internals
5-5-1 Task States
5-5-2 Task Control Blocks (TCBs)
5-6 Internal Tasks
5-6-1 The Idle Task (OS_IdleTask())
5-6-2 The Tick Task (OS_TickTask())
5-6-3 The Statistic Task (OS_StatTask())
5-6-4 The Timer Task (OS_TmrTask())
5-6-5 The ISR Handler Task (OS_IntQTask())
5-7 Summary
The Ready List
6-1 Priority Levels
6-2 The Ready List
6-3 Adding Tasks to the Ready List
6-4 Summary
Scheduling
7-1 Preemptive Scheduling
7-2 Scheduling Points
7-3 Round-Robin Scheduling
7-4 Scheduling Internals
7-4-1 OSSched()
7-4-2 OSIntExit()
7-4-3 OS_SchedRoundRobin()
7-5 Summary
Context Switching
8-1 OSCtxSw()
8-2 OSIntCtxSw()
8-3 Summary
Interrupt Management
9-1 Handling CPU Interrupts
9-2 Typical µC/OS-III Interrupt Service Routine (ISR)
9-3 Short Interrupt Service Routine (ISR)
9-4 All Interrupts Vector to a Common Location
9-5 Every Interrupt Vectors to a Unique Location
9-6 Direct and Deferred Post Methods
9-6-1 Direct Post Method
9-6-2 Deferred Post Method
9-7 Direct vs. Deferred Post Method
9-8 The Clock Tick (or System Tick)
9-9 Summary
Pend Lists (or Wait Lists)
10-1 Summary
Time Management
11-1 OSTimeDly()
11-2 OSTimeDlyHMSM()
11-3 OSTimeDlyResume()
11-4 OSTimeSet() and OSTimeGet()
11-5 OSTimeTick()
11-6 Summary
Timer Management
12-1 One-Shot Timers
12-2 Periodic (no initial delay)
12-3 Periodic (with initial delay)
12-4 Timer Management Internals
12-4-1 Timer Management Internals - Timers States
12-4-2 Timer Management Internals - OS_TMR
12-4-3 Timer Management Internals - Timer Task
12-4-4 Timer Management Internals - Timer List
12-5 Summary
Resource Management
13-1 Disable/Enable Interrupts
13-2 Lock/Unlock
13-3 Semaphores
13-3-1 Binary Semaphores
13-3-2 Counting Semaphores
13-3-3 Notes on Semaphores
13-3-4 Semaphore Internals (for resource sharing)
13-3-5 Priority Inversions
13-4 Mutual Exclusion Semaphores (Mutex)
13-4-1 Mutual Exclusion Semaphore Internals
13-5 Should You Use a Semaphore Instead of a Mutex?
13-6 Deadlocks (or Deadly Embrace)
13-7 Summary
Synchronization
14-1 Semaphores
14-1-1 Unilateral Rendezvous
14-1-2 Credit Tracking
14-1-3 Multiple Tasks Waiting on a Semaphore
14-1-4 Semaphore Internals (for synchronization)
14-2 Task Semaphore
14-2-1 Pending (i.e., Waiting) on a Task Semaphore
14-2-2 Posting (i.e., Signaling) a Task Semaphore
14-2-3 Bilateral Rendezvous
14-3 Event Flags
14-3-1 Using Event Flags
14-3-2 Event Flags Internals
14-4 Synchronizing Multiple Tasks
14-5 Summary
Message Passing
15-1 Messages
15-2 Message Queues
15-3 Task Message Queue
15-4 Bilateral Rendezvous
15-5 Flow Control
15-6 Keeping the Data in Scope
15-7 Using Message Queues
15-8 Clients and Servers
15-9 Message Queues Internals
15-10 Summary
Pending On Multiple Objects
16-1 Summary
Memory Management
17-1 Creating a Memory Partition
17-2 Getting a Memory Block from a Partition
17-3 Returning a Memory Block to a Partition
17-4 Using Memory Partitions
17-5 Summary
Porting µC/OS-III
18-1 µC/CPU
18-2 µC/OS-III Port
18-3 Board Support Package (BSP)
18-4 Summary
Run-Time Statistics
19-1 General Statistics – Run-Time
19-2 Per-Task Statistics – Run-Time
19-3 Kernel Object – Run-Time
19-4 OS_DBG.C – Static
19-5 OS_CFG_APP.C – Static
19-6 Summary
µC/OS-III API Reference Manual
A-1 Task Management
A-2 Time Management
A-3 Mutual Exclusion Semaphores – Resource Management
A-4 Event Flags – Synchronization
A-5 Semaphores – Synchronization
A-6 Task Semaphores – Synchronization
A-7 Message Queues – Message Passing
A-8 Task Message Queues – Message Passing
A-9 Pending on Multiple Objects
A-10 Timers
A-11 Fixed-Size Memory Partitions – Memory Management
OSCtxSw()
OSFlagCreate()
OSFlagDel()
OSFlagPend()
OSFlagPendAbort()
OSFlagPendGetFlagsRdy()
OSFlagPost()
OSIdleTaskHook()
OSInit()
OSInitHook()
OSIntCtxSw()
OSIntEnter()
OSIntExit()
OSMemCreate()
OSMemGet()
OSMemPut()
OSMutexCreate()
OSMutexDel()
OSMutexPend()
OSMutexPendAbort()
OSMutexPost()
OSPendMulti()
OSQCreate()
OSQDel()
OSQFlush()
OSQPend()
OSQPendAbort()
OSQPost()
OSSafetyCriticalStart()
OSSched()
OSSchedLock()
OSSchedRoundRobinCfg()
OSSchedRoundRobinYield()
OSSchedUnlock()
OSSemCreate()
OSSemDel()
OSSemPend()
OSSemPendAbort()
OSSemPost()
OSSemSet()
OSStart()
OSStartHighRdy()
OSStatReset()
OSStatTaskCPUUsageInit()
OSStatTaskHook()
OSTaskChangePrio()
OSTaskCreate()
OSTaskCreateHook()
OSTaskDel()
OSTaskDelHook()
OSTaskQPend()
OSTaskQPendAbort()
OSTaskQPost()
OSTaskRegGet()
OSTaskRegSet()
OSTaskReturnHook()
OSTaskResume()
OSTaskSemPend()
OSTaskSemPendAbort()
OSTaskSemPost()
OSTaskSemSet()
OSTaskStatHook()
OSTaskStkChk()
OSTaskStkInit()
OSTaskSuspend()
OSTaskSwHook()
OSTaskTimeQuantaSet()
OSTickISR()
OSTimeDly()
OSTimeDlyHMSM()
OSTimeDlyResume()
OSTimeGet()
OSTimeSet()
OSTimeTick()
OSTimeTickHook()
OSTmrCreate()
OSTmrDel()
OSTmrRemainGet()
OSTmrStart()
OSTmrStateGet()
OSTmrStop()
OSVersion()
µC/OS-III Configuration Manual
B-1 µC/OS-III Features (OS_CFG.H)
B-2 Data Types (OS_TYPE.H)
B-3 µC/OS-III Stacks, Pools and other (OS_CFG_APP.H)
Migrating from µC/OS-II to µC/OS-III
C-1 Differences in Source File Names and Contents
C-2 Convention Changes
C-3 Variable Name Changes
C-4 API Changes
C-4-1 Event Flags
C-4-2 Message Mailboxes
C-4-3 Memory Management
C-4-4 Mutual Exclusion Semaphores
C-4-5 Message Queues
C-4-6 Semaphores
C-4-7 Task Management
C-4-8 Time Management
C-4-9 Timer Management
C-4-10 Miscellaneous
C-4-11 Hooks and Port
MISRA-C:2004 and µC/OS-III
D-1 MISRA-C:2004, Rule 8.5 (Required)
D-2 MISRA-C:2004, Rule 8.12 (Required)
D-3 MISRA-C:2004, Rule 14.7 (Required)
D-4 MISRA-C:2004, Rule 15.2 (Required)
D-5 MISRA-C:2004, Rule 17.4 (Required)
Bibliography
Licensing Policy
Part II
Introduction
1-1 The MicriUm µC/Eval-STM32F107
1-2 Part II Chapter Contents
1-3 Acknowledgements
The ARM Cortex-M3 and the STM32
2-1 The Cortex CPU
2-1-1 The Program Status Register
2-1-2 Stacking and Interrupts
2-2 Nested Vector Interrupt Controller (NVIC)
2-3 Exception Vector Table
2-4 SYSTICK (System Tick)
2-5 Memory Map
2-6 Instruction Set
2-7 Debugging Features
2-8 The STmicroelectronics STM32
Setup
3-1 Downloading µC/OS-III projects for this book
3-1-1 \EvalBoards
3-1-2 \uC-CPU
3-1-3 \uC-LIB
3-1-4 \uCOS-III
3-2 Downloading µC/Probe
3-3 Downloading the IAR Embedded Workbench for ARM
3-4 Downloading the STM32F107 documentation
µC/OS-III Example #1
4-1 Running the Project
4-2 How the example project works
4-3 Monitoring variables using µC/Probe
4-4 Summary
µC/OS-III Example #2
5-1 Running the Project
5-2 Monitoring the temperature sensor using µC/Probe
µC/OS-III Example #3
6-1 Running the Project
6-2 Examining Performance Test Results with µC/Probe
6-3 How the test code works
6-4 Other performance measurements
6-5 Summary
µC/OS-III Example #4
7-1 Running the Project
7-2 Displaying Rotating Wheel Data
7-3 RPM Measurement simulation implementation
7-3-1 Measuring RPM using an Input Capture
7-4 How the code works
7-5 Observations
7-6 Summary
µC/OS-III port for the Cortex-M3
A-1 OS_CPU.H
A-2 OS_CPU_C.C
A-2-1 OS_CPU_C.C – OSIdleTaskHook()
A-2-2 OS_CPU_C.C – OSInitHook()
A-2-3 OS_CPU_C.C – OSStatTaskHook()
A-2-4 OS_CPU_C.C – OSTaskCreateHook()
A-2-5 OS_CPU_C.C – OSTaskDelHook()
A-2-6 OS_CPU_C.C – OSTaskReturnHook()
A-2-7 OS_CPU_C.C – OSTaskStkInit()
A-2-8 OS_CPU_C.C – OSTaskSwHook()
A-2-9 OS_CPU_C.C – OSTimeTickHook()
A-2-10 OS_CPU_C.C – OS_CPU_SysTickHandler()
A-2-11 OS_CPU_C.C – OS_CPU_SysTickInit()
A-3 OS_CPU_A.ASM
A-3-1 OS_CPU_A.ASM – OSStartHighRdy()
A-3-2 OS_CPU_A.ASM – OSCtxSw() and OSIntCtxSw()
A-3-3 OS_CPU_A.ASM – OS_CPU_PendSVHandler()
µC/CPU port for the Cortex-M3
B-1 CPU_CORE.C
B-2 CPU_CORE.H
B-3 CPU_DEF.H
B-4 CPU_CFG.H
B-5 µC/CPU functions in BSP.C
B-5-1 µC/CPU functions in BSP.C, CPU_TS_TmrInit()
B-5-2 µC/CPU functions in BSP.C, CPU_TS_TmrRd()
B-6 CPU.H
B-6-1 CPU.H – #defines
B-6-2 CPU.H – Data Types
B-6-3 CPU.H – Function Prototypes
B-7 CPU_A.ASM
IAR Systems IAR Embedded Workbench for ARM
C-1 IAR Embedded Workbench for ARM – Highlights
C-2 Modular and extensible IDE
C-3 Highly optimizing C/C++ Compiler
C-4 Device Support
C-5 State-of-the-art C-SPY® Debugger
C-6 C-SPY Debugger and target system support
C-7 IAR Assembler
C-8 IAR J-LINK Linker
C-9 IAR Library and library tools
C-10 Comprehensive documentation
C-11 First class technical support
Micriµm’s µC/Probe
D-1 µC/Probe is a Windows™-based application
D-2 Assigning a variable to an object
µC/Eval-STM32F107 User’s Guide
E-1 Features
E-2 Hardware layout and configuration
E-3 Power Supply
E-4 Boot Options
E-5 Reset Sources
E-6 CAN (Controller Area Network)
E-7 RS-232C
E-8 SD/MMC card
E-9 USB-OTG (USB On-The-Go)
E-10 LM75 Temperature Sensor
E-11 Debug Interface
E-12 Ethernet
E-13 Clock SourceS
E-14 Connectors
E-14-1 Extension connector (CN3)
E-14-2 Power connectors (CN1 & CN9)
E-14-3 RS-232C connectors (CN7)
E-15 I/O Assignments
E-16 Schematics
Bibliography
Licensing Policy
Index
μC/ OS-III TM The Real-Time Kernel Jean J. Labrosse Weston, FL 33326
Micriμm Press 1290 Weston Road, Suite 306 Weston, FL 33326 USA www.micrium.com Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where Micriμm Press is aware of a trademark claim, the product name appears in initial capital letters, in all capital letters, or in accordance with the vendor’s capatilization preference. Readers should contact the appropriate companies for more complete information on trademarks and trademark registrations. All trademarks and registerd trademarks in this book are the property of their respective holders. Copyright © 2010 by Micriμm Press except where noted otherwise. Published by Micriμm Press. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher; with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. The programs and code examples in this book are presented for instructional value. The programs and examples have been carefully tested, but are not guaranteed to any particular purpose. The publisher does not offer any warranties and does not guarantee the accuracy, adequacy, or completeness of any information herein and is not responsible for any errors and ommissions. The publisher assumes no liability for damages resulting from the use of the information in this book or for any infringement of the intellectual property rights of third parties that would result from the use of this information. Library of Congress Control Number: 2009934275 Library of Congress subject headings: 1. Embedded computer systems 2. Real-time data processing 3. Computer software - Development For bulk orders, please contact Micrium Press at: +1 954 217 2036 SBN: 978-9823375-3-0 100-uCOS-III-ST-STM32-002
To my loving and caring wife, Manon, and our two children James and Sabrina.
Table of Contents Part I: μC/OS-III – The Real-Time Kernel Foreword to μC/OS-III — by Jack Ganssle.......................................... 19 Preface .................................................................................................. 21 Chapter 1 1-1 1-2 1-3 1-4 1-5 1-6 1-7 1-8 1-9 1-10 1-11 Chapter 2 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 Introduction .......................................................................................... 23 Foreground/Background Systems ...................................................... 24 Real-Time Kernels ................................................................................ 25 RTOS (Real-Time Operating System) .................................................. 27 μC/OS-III ............................................................................................... 27 μC/OS, μC/OS-II and μC/OS-III Features Comparison ...................... 32 How the Book is Organized ................................................................. 34 μC/Probe .............................................................................................. 34 Conventions ......................................................................................... 35 Chapter Contents ................................................................................. 36 Licensing .............................................................................................. 40 Contacting Micrium .............................................................................. 40 Directories and Files ............................................................................ 41 Application Code ................................................................................. 44 CPU ....................................................................................................... 45 Board Support Package (BSP) ............................................................ 46 μC/OS-III, CPU Independent Source Code ........................................ 47 μC/OS-III, CPU Specific Source Code ................................................ 51 μC/CPU, CPU Specific Source Code .................................................. 52 μC/LIB, Portable Library Functions ..................................................... 54 Summary .............................................................................................. 55 5
Table of Contents Chapter 3 3-1 3-2 Getting Started with μC/OS-III ............................................................ 59 Single Task Application ....................................................................... 60 Multiple Tasks Application with Kernel Objects ................................. 68 Chapter 4 4-1 4-1-1 4-2 4-2-1 4-3 4-4 Chapter 5 5-1 5-2 5-3 5-4 5-5 5-5-1 5-5-2 5-6 5-6-1 5-6-2 5-6-3 5-6-4 5-6-5 5-7 Chapter 6 6-1 6-2 6-3 6-4 Critical Sections ................................................................................... 77 Disabling Interrupts .............................................................................. 78 Measuring Interrupt Disable Time ....................................................... 78 Locking the Scheduler ......................................................................... 79 Measuring Scheduler Lock Time ......................................................... 80 μC/OS-III Features with Longer Critical Sections ............................... 81 Summary .............................................................................................. 82 Task Management ............................................................................... 83 Assigning Task Priorities ..................................................................... 92 Determining the Size of a Stack .......................................................... 94 Detecting Task Stack Overflows ......................................................... 95 Task Management Services ................................................................ 99 Task Management Internals .............................................................. 100 Task States ......................................................................................... 100 Task Control Blocks (TCBs) ............................................................... 105 Internal Tasks ..................................................................................... 114 The Idle Task (OS_IdleTask()) ............................................................ 115 The Tick Task (OS_TickTask()) .......................................................... 117 The Statistic Task (OS_StatTask()) .................................................... 124 The Timer Task (OS_TmrTask()) ........................................................ 127 The ISR Handler Task (OS_IntQTask()) ............................................. 128 Summary ............................................................................................ 129 The Ready List ................................................................................... 131 Priority Levels ..................................................................................... 132 The Ready List ................................................................................... 136 Adding Tasks to the Ready List ........................................................ 139 Summary ............................................................................................ 140 Chapter 7 7-1 7-2 Scheduling .......................................................................................... 141 Preemptive Scheduling ...................................................................... 142 Scheduling Points .............................................................................. 144 6
分享到:
收藏