μC/OS-III
TM
The Real-Time Kernel
User’s Manual
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 © 2012 by Micriμm except where noted otherwise. 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.
For bulk orders, please contact Micrium Press at: +1 954 217 2036
ISBN: 978-0-9823375-9-2
600-uCOS-III-Users-Manual-004
3
Table of Contents
Preface .................................................................................................. 13
Chapter 1 Introduction .......................................................................................... 15
1-1 Foreground/Background Systems ...................................................... 16
1-2 Real-Time Kernels ................................................................................ 17
1-3 RTOS (Real-Time Operating System) .................................................. 19
1-4 μC/OS-III ............................................................................................... 19
1-5 μC/OS, μC/OS-II and μC/OS-III Features Comparison ...................... 24
1-6 How the Book is Organized ................................................................. 26
1-7 μC/Probe .............................................................................................. 26
1-8 Conventions ......................................................................................... 27
1-9 Chapter Contents ................................................................................. 28
1-10 Licensing .............................................................................................. 32
1-11 Contacting Micrium .............................................................................. 32
Chapter 2 Directories and Files ............................................................................ 33
2-1 Application Code ................................................................................. 36
2-2 CPU ....................................................................................................... 37
2-3 Board Support Package (BSP) ............................................................ 38
2-4 μC/OS-III, CPU Independent Source Code ........................................ 39
2-5 μC/OS-III, CPU Specific Source Code ................................................ 43
2-6 μC/CPU, CPU Specific Source Code .................................................. 44
2-7 μC/LIB, Portable Library Functions ..................................................... 46
2-8 Summary .............................................................................................. 48
Chapter 3 Getting Started with μC/OS-III ............................................................ 51
3-1 Single Task Application ....................................................................... 52
3-2 Multiple Tasks Application with Kernel Objects ................................. 60
4
Table of Contents
Chapter 4 Critical Sections ................................................................................... 69
4-1 Disabling Interrupts .............................................................................. 70
4-1-1 Measuring Interrupt Disable Time ....................................................... 70
4-2 Locking the Scheduler ......................................................................... 71
4-2-1 Measuring Scheduler Lock Time ......................................................... 72
4-3 μC/OS-III Features with Longer Critical Sections ............................... 73
4-4 Summary .............................................................................................. 74
Chapter 5 Task Management ............................................................................... 75
5-1 Assigning Task Priorities ..................................................................... 84
5-2 Determining the Size of a Stack .......................................................... 86
5-3 Detecting Task Stack Overflows ......................................................... 87
5-4 Task Management Services ................................................................ 91
5-5 Task Management Internals ................................................................ 92
5-5-1 Task States ........................................................................................... 92
5-5-2 Task Control Blocks (TCBs) ................................................................. 97
5-6 Internal Tasks ..................................................................................... 109
5-6-1 The Idle Task (OS_IdleTask(), os_core.c) .......................................... 109
5-6-2 The Tick Task (OS_TickTask(), os_tick.c) .......................................... 111
5-6-3 The Statistic Task (OS_StatTask(), os_stat.c) ................................... 118
5-6-4 The Timer Task (OS_TmrTask(), os_tmr.c) ........................................ 121
5-6-5 The ISR Handler Task (OS_IntQTask(), os_int.c) .............................. 122
5-7 Summary ............................................................................................ 123
Chapter 6 The Ready List ................................................................................... 125
6-1 Priority Levels ..................................................................................... 126
6-2 The Ready List ................................................................................... 130
6-3 Adding Tasks to the Ready List ........................................................ 133
6-4 Summary ............................................................................................ 134
Chapter 7 Scheduling .......................................................................................... 135
7-1 Preemptive Scheduling ...................................................................... 136
7-2 Scheduling Points .............................................................................. 138
7-3 Round-Robin Scheduling .................................................................. 140
7-4 Scheduling Internals .......................................................................... 142
7-4-1 OSSched() .......................................................................................... 143
7-4-2 OSIntExit() ........................................................................................... 144
5
7-4-3 OS_SchedRoundRobin() .................................................................... 145
7-5 Summary ............................................................................................ 147
Chapter 8 Context Switching .............................................................................. 149
8-1 OSCtxSw() .......................................................................................... 152
8-2 OSIntCtxSw() ...................................................................................... 154
8-3 Summary ............................................................................................ 157
Chapter 9 Interrupt Management ....................................................................... 159
9-1 Handling CPU Interrupts .................................................................... 160
9-2 Typical μC/OS-III Interrupt Service Routine (ISR) ............................. 161
9-3 Non Kernel-Aware Interrupt Service Routine (ISR) ........................... 164
9-4 Processors with Multiple Interrupt Priorities .................................... 165
9-5 All Interrupts Vector to a Common Location .................................... 167
9-6 Every Interrupt Vectors to a Unique Location .................................. 169
9-7 Direct and Deferred Post Methods ................................................... 170
9-7-1 Direct Post Method ............................................................................ 170
9-7-2 Deferred Post Method ....................................................................... 173
9-8 Direct vs. Deferred Post Method ....................................................... 176
9-9 The Clock Tick (or System Tick) ........................................................ 177
9-10 Summary ............................................................................................ 179
Chapter 10 Pend Lists (or Wait Lists) ................................................................... 181
10-1 Summary ............................................................................................ 186
Chapter 11 Time Management ............................................................................. 187
11-1 OSTimeDly() ........................................................................................ 188
11-2 OSTimeDlyHMSM() ............................................................................ 193
11-3 OSTimeDlyResume() .......................................................................... 195
11-4 OSTimeSet() and OSTimeGet() .......................................................... 196
11-5 OSTimeTick() ...................................................................................... 196
11-6 Summary ............................................................................................ 196
Chapter 12 Timer Management ............................................................................ 197
12-1 One-Shot Timers ................................................................................ 199
12-2 Periodic (no initial delay) .................................................................... 200
评论14
最新资源