logo资料库

100-uCOS-III-ST-STM32-003.pdf

第1页 / 共934页
第2页 / 共934页
第3页 / 共934页
第4页 / 共934页
第5页 / 共934页
第6页 / 共934页
第7页 / 共934页
第8页 / 共934页
资料共934页,剩余部分请下载后查看
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
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(), os_core.c)
5-6-2 The Tick Task (OS_TickTask(), os_tick.c)
5-6-3 The Statistic Task (OS_StatTask(), os_stat.c)
5-6-4 The Timer Task (OS_TmrTask(), os_tmr.c)
5-6-5 The ISR Handler Task (OS_IntQTask(), os_int.c)
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 Non Kernel-Aware Interrupt Service Routine (ISR)
9-4 Processors with Multiple Interrupt Priorities
9-5 All Interrupts Vector to a Common Location
9-6 Every Interrupt Vectors to a Unique Location
9-7 Direct and Deferred Post Methods
9-7-1 Direct Post Method
9-7-2 Deferred Post Method
9-8 Direct vs. Deferred Post Method
9-9 The Clock Tick (or System Tick)
9-10 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 Rendez-vous
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 Rendez-vous
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 Rendez-vous
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 Conventions
18-2 µC/CPU
18-2-1 cpu_bsp.h
18-2-2 cpu_def.h
18-2-3 cpu_cfg.h
18-2-4 cpu_core.c
18-2-5 cpu_core.h
18-2-6 cpu.h
18-2-7 cpu_c.c
18-2-8 cpu_a.asm
18-3 µC/OS-III Port
18-3-1 os_cpu.h
18-3-2 os_cpu_c.c
18-3-3 os_cpu_a.asm
18-3-4 os_cpu_a.inc
18-4 Board Support Package (BSP)
18-4-1 bsp.c and bsp.h
18-4-2 bsp_int.c and bsp_int.h
18-5 Testing a Port
18-5-1 Creating a Simple Test Project
18-5-2 Verifying Task Context Switches
18-5-3 Verifying Interrupt Context Switches
18-6 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
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
A-12 OSCtxSw()
A-13 OSFlagCreate()
A-14 OSFlagDel()
A-15 OSFlagPend()
A-16 OSFlagPendAbort()
A-17 OSFlagPendGetFlagsRdy()
A-18 OSFlagPost()
A-19 OSIdleTaskHook()
A-20 OSInit()
A-21 OSInitHook()
A-22 OSIntCtxSw()
A-23 OSIntEnter()
A-24 OSIntExit()
A-25 OSMemCreate()
A-26 OSMemGet()
A-27 OSMemPut()
A-28 OSMutexCreate()
A-29 OSMutexDel()
A-30 OSMutexPend()
A-31 OSMutexPendAbort()
A-32 OSMutexPost()
A-33 OSPendMulti()
A-34 OSQCreate()
A-35 OSQDel()
A-36 OSQFlush()
A-37 OSQPend()
A-38 OSQPendAbort()
A-39 OSQPost()
A-40 OSSafetyCriticalStart()
A-41 OSSched()
A-42 OSSchedLock()
A-43 OSSchedRoundRobinCfg()
A-44 OSSchedRoundRobinYield()
A-45 OSSchedUnlock()
A-46 OSSemCreate()
A-47 OSSemDel()
A-48 OSSemPend()
A-49 OSSemPendAbort()
A-50 OSSemPost()
A-51 OSSemSet()
A-52 OSStart()
A-53 OSStartHighRdy()
A-54 OSStatReset()
A-55 OSStatTaskCPUUsageInit()
A-56 OSStatTaskHook()
A-57 OSTaskChangePrio()
A-58 OSTaskCreate()
A-59 OSTaskCreateHook()
A-60 OSTaskDel()
A-61 OSTaskDelHook()
A-62 OSTaskQFlush()
A-63 OSTaskQPend()
A-64 OSTaskQPendAbort()
A-65 OSTaskQPost()
A-66 OSTaskRegGet()
A-67 OSTaskRegSet()
A-68 OSTaskReturnHook()
A-69 OSTaskResume()
A-70 OSTaskSemPend()
A-71 OSTaskSemPendAbort()
A-72 OSTaskSemPost()
A-73 OSTaskSemSet()
A-74 OSStatTaskHook()
A-75 OSTaskStkChk()
A-76 OSTaskStkInit()
A-77 OSTaskSuspend()
A-78 OSTaskSwHook()
A-79 OSTaskTimeQuantaSet()
A-80 OSTickISR()
A-81 OSTimeDly()
A-82 OSTimeDlyHMSM()
A-83 OSTimeDlyResume()
A-84 OSTimeGet()
A-85 OSTimeSet()
A-86 OSTimeTick()
A-87 OSTimeTickHook()
A-88 OSTmrCreate()
A-89 OSTmrDel()
A-90 OSTmrRemainGet()
A-91 OSTmrStart()
A-92 OSTmrStateGet()
A-93 OSTmrStop()
A-94 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 capitalization preference. Readers should contact the appropriate companies for more complete information on trademarks and trademark registrations. All trademarks and registered trademarks in this book are the property of their respective holders. Copyright © 2011 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 or omissions. 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 ISBN: 978-0-9823375-3-0 100-uCOS-III-ST-STM32-003
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 Introduction .......................................................................................... 31 Foreground/Background Systems ...................................................... 32 Real-Time Kernels ................................................................................ 33 RTOS (Real-Time Operating System) .................................................. 35 μC/OS-III ............................................................................................... 35 μC/OS, μC/OS-II and μC/OS-III Features Comparison ...................... 40 How the Book is Organized ................................................................. 42 μC/Probe .............................................................................................. 42 Conventions ......................................................................................... 43 Chapter Contents ................................................................................. 44 Directories and Files ............................................................................ 49 Application Code ................................................................................. 52 CPU ....................................................................................................... 53 Board Support Package (BSP) ............................................................ 54 μC/OS-III, CPU Independent Source Code ........................................ 55 μC/OS-III, CPU Specific Source Code ................................................ 59 μC/CPU, CPU Specific Source Code .................................................. 60 μC/LIB, Portable Library Functions ..................................................... 62 Summary .............................................................................................. 64 Chapter 1 1-1 1-2 1-3 1-4 1-5 1-6 1-7 1-8 1-9 Chapter 2 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 Chapter 3 3-1 3-2 Getting Started with μC/OS-III ............................................................ 67 Single Task Application ....................................................................... 68 Multiple Tasks Application with Kernel Objects ................................. 76 5
Table of Contents Critical Sections ................................................................................... 85 Disabling Interrupts .............................................................................. 86 Measuring Interrupt Disable Time ....................................................... 86 Locking the Scheduler ......................................................................... 87 Measuring Scheduler Lock Time ......................................................... 88 μC/OS-III Features with Longer Critical Sections ............................... 89 Summary .............................................................................................. 90 Task Management ............................................................................... 91 Assigning Task Priorities ................................................................... 100 Determining the Size of a Stack ........................................................ 102 Detecting Task Stack Overflows ....................................................... 103 Task Management Services .............................................................. 107 Task Management Internals .............................................................. 108 Task States ......................................................................................... 108 Task Control Blocks (TCBs) ............................................................... 113 Internal Tasks ..................................................................................... 125 The Idle Task (OS_IdleTask(), os_core.c) .......................................... 125 The Tick Task (OS_TickTask(), os_tick.c) .......................................... 127 The Statistic Task (OS_StatTask(), os_stat.c) ................................... 134 The Timer Task (OS_TmrTask(), os_tmr.c) ........................................ 137 The ISR Handler Task (OS_IntQTask(), os_int.c) .............................. 138 Summary ............................................................................................ 139 The Ready List ................................................................................... 141 Priority Levels ..................................................................................... 142 The Ready List ................................................................................... 146 Adding Tasks to the Ready List ........................................................ 149 Summary ............................................................................................ 150 Scheduling .......................................................................................... 151 Preemptive Scheduling ...................................................................... 152 Scheduling Points .............................................................................. 154 Round-Robin Scheduling .................................................................. 156 Scheduling Internals .......................................................................... 158 OSSched() .......................................................................................... 159 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 Chapter 7 7-1 7-2 7-3 7-4 7-4-1 6
分享到:
收藏