ProgrammingEmbeddedSystemsinCandC.pdf

(962 KB) Pobierz
Microsoft Word - Programming Embedded Systems.doc
Programming Embedded Systems in C and C++
Programming Embedded Systems
in C and C++
Michael Barr
Publisher: O'Reilly
First Edition January 1999
ISBN: 1-56592-354-5, 191 pages
Released by guojerry@teamfly
This book introduces embedded systems to C and C++ programmers. Topics
include testing memory devices, writing and erasing Flash memory, verifying
nonvolatile memory contents, controlling on-chip peripherals, device driver
design and implementation, optimizing embedded code for size and speed,
and making the most of C++ without a performance penalty.
- 1 -
20086304.001.png 20086304.002.png
Programming Embedded Systems in C and C++
Table of Content
Dedication ....................................................................................................................................................... 4
Preface............................................................................................................................................................. 5
Why I Wrote This Book .......................................................................................................................... 5
Intended Audience................................................................................................................................... 6
Organization ............................................................................................................................................ 7
Conventions, Typographical and Otherwise............................................................................................ 8
Obtaining the Examples Online .............................................................................................................. 9
How to Contact Us .................................................................................................................................. 9
Personal Comments and Acknowledgments ......................................................................................... 10
Chapter 1. Introduction ................................................................................................................................. 11
1.1 What Is an Embedded System? ....................................................................................................... 11
1.2 Variations on the Theme .................................................................................................................. 13
1.3 C: The Least Common Denominator .............................................................................................. 18
1.4 A Few Words About Hardware........................................................................................................ 20
Chapter 2. Your First Embedded Program .................................................................................................... 22
2.1 Hello, World!................................................................................................................................... 22
2.2 Das Blinkenlights ............................................................................................................................ 23
2.3 The Role of the Infinite Loop .......................................................................................................... 27
Chapter 3. Compiling, Linking, and Locating............................................................................................... 28
3.1 The Build Process............................................................................................................................ 28
3.2 Compiling........................................................................................................................................ 30
3.3 Linking ............................................................................................................................................ 32
3.4 Locating........................................................................................................................................... 34
3.5 Building das Blinkenlights .............................................................................................................. 36
Chapter 4. Downloading and Debugging ...................................................................................................... 39
4.1 When in ROM ... ............................................................................................................................. 39
4.2 Remote Debuggers .......................................................................................................................... 40
4.3 Emulators ........................................................................................................................................ 44
4.4 Simulators and Other Tools ............................................................................................................. 45
Chapter 5. Getting to Know the Hardware.................................................................................................... 48
5.1 Understand the Big Picture.............................................................................................................. 48
5.2 Examine the Landscape................................................................................................................... 50
5.3 Learn How to Communicate ........................................................................................................... 55
5.4 Get to Know the Processor.............................................................................................................. 57
5.5 Study the External Peripherals ........................................................................................................ 61
5.6 Initialize the Hardware .................................................................................................................... 61
Chapter 6. Memory ....................................................................................................................................... 64
6.1 Types of Memory ............................................................................................................................ 64
6.2 Memory Testing .............................................................................................................................. 68
6.3 Validating Memory Contents........................................................................................................... 82
6.4 Working with Flash Memory........................................................................................................... 87
- 2 -
20086304.003.png
Programming Embedded Systems in C and C++
Chapter 7. Peripherals ................................................................................................................................... 93
7.1 Control and Status Registers ........................................................................................................... 93
7.2 The Device Driver Philosophy ........................................................................................................ 94
7.3 A Simple Timer Driver .................................................................................................................... 97
7.4 Das Blinkenlights, Revisited ......................................................................................................... 107
Chapter 8. Operating Systems ..................................................................................................................... 109
8.1 History and Purpose ...................................................................................................................... 109
8.2 A Decent Embedded Operating System ........................................................................................ 110
8.3 Real-Time Characteristics ............................................................................................................. 130
8.4 Selection Process........................................................................................................................... 131
Chapter 9. Putting It All Together ............................................................................................................... 134
9.1 Application Overview ................................................................................................................... 134
9.2 Flashing the LED .......................................................................................................................... 136
9.3 Printing "Hello, World!"................................................................................................................ 141
9.4 Working with Serial Ports ............................................................................................................. 142
9.5 The Zilog 85230 Serial Controller ................................................................................................ 149
Chapter 10. Optimizing Your Code ............................................................................................................. 151
10.1 Increasing Code Efficiency ......................................................................................................... 151
10.2 Decreasing Code Size.................................................................................................................. 154
10.3 Reducing Memory Usage ............................................................................................................ 156
10.4 Limiting the Impact of C++ ........................................................................................................ 157
Appendix A. Arcom's Target188EB ............................................................................................................ 160
Glossary....................................................................................................................................................... 161
A.......................................................................................................................................................... 161
B .......................................................................................................................................................... 162
C .......................................................................................................................................................... 162
D.......................................................................................................................................................... 164
E .......................................................................................................................................................... 166
F .......................................................................................................................................................... 167
G.......................................................................................................................................................... 167
H.......................................................................................................................................................... 167
I ........................................................................................................................................................... 168
L .......................................................................................................................................................... 170
M ......................................................................................................................................................... 170
N.......................................................................................................................................................... 172
O.......................................................................................................................................................... 172
P .......................................................................................................................................................... 173
R .......................................................................................................................................................... 176
S .......................................................................................................................................................... 178
T .......................................................................................................................................................... 180
V.......................................................................................................................................................... 180
W ......................................................................................................................................................... 181
Bibliography................................................................................................................................................ 182
12.1 Books........................................................................................................................................... 182
- 3 -
Programming Embedded Systems in C and C++
12.2 Magazines and Conferences ........................................................................................................ 183
12.3 World Wide Web ......................................................................................................................... 184
Colophon ..................................................................................................................................................... 186
Dedication
For Mom and Dad
- 4 -
Programming Embedded Systems in C and C++
Preface
First figure out why you want the students to learn the subject and what you want them to
know, and the method will result more or less by common sense.
-Richard Feynman
Embedded software is in almost every electronic device in use today. There is software
hidden away inside our watches, VCRs, cellular phones, and even a few toasters. The military
uses embedded software to guide missiles and detect enemy aircraft. And communication
satellites, deep-space probes, and many medical instruments would've been nearly impossible
to create without it.
Someone has to write all that software, and there are tens of thousands of electrical engineers,
computer scientists, and other professionals who actually do. I am one of them, and I know
from my personal experience just how hard it can be to learn the craft. There aren't any
embedded software courses in school, and I've never been able to find a decent book about the
subject in any library.
Each embedded system is unique, and the hardware is highly specialized to the application
domain. As a result, embedded systems programming can be a widely varying experience and
can take years to master. However, one common denominator across almost all embedded
software development is the use of the C programming language. This book will teach you
how to use C and its descendent C++ in any embedded system.
Even if you already know how to write embedded software, you can still learn a lot from this
book. In addition to learning how to use C and C++ more effectively, you'll also benefit from
the detailed explanations and source code solutions to common embedded software problems.
Among the advanced topics covered in the book are memory testing and verification, device
driver design and implementation, real-time operating system internals, and code optimization
techniques.
Why I Wrote This Book
I once heard an estimate that in the United States there are eight microprocessor-based
devices for every person. At the time, I wondered how this could be. Are there really that
many computers surrounding us? Later, when I had more time to think about it, I started to
make a list of the things I used that probably contained a microprocessor. Within five minutes,
my list contained ten items: television, stereo, coffee maker, alarm clock, VCR, microwave,
dishwasher, remote control, bread machine, and digital watch. And those were just my
personal possessions-I quickly came up with ten more devices I used at work.
- 5 -
Zgłoś jeśli naruszono regulamin