| |
| |
Preface | |
| |
| |
| |
Introduction | |
| |
| |
| |
What is an Embedded System? | |
| |
| |
| |
What's Unique About the Design Goals for Embedded Software? | |
| |
| |
| |
What Does "Real-Time" Mean? | |
| |
| |
| |
What Does "Multitasking" Mean? | |
| |
| |
| |
How Powerful Are Embedded Processors? | |
| |
| |
| |
What Programming Languages Are Used? | |
| |
| |
| |
What Is a "Real-Time Kernel"? | |
| |
| |
| |
How Is Building an Embedded Application Unique? | |
| |
| |
| |
How Big Are Typical Embedded Programs? | |
| |
| |
| |
The Software Used in This Book | |
| |
| |
Problems | |
| |
| |
| |
Data Representation | |
| |
| |
| |
Fixed-Precision Binary Numbers | |
| |
| |
| |
Positional Number Systems | |
| |
| |
| |
Binary-to-Decimal Conversion | |
| |
| |
| |
Decimal-to-Binary Conversion | |
| |
| |
| |
Counting | |
| |
| |
| |
Fixed Precision and Rollover | |
| |
| |
| |
Hexadecimal Representation | |
| |
| |
| |
Binary Representation of Integers | |
| |
| |
| |
Signed Integers | |
| |
| |
| |
Positive and Negative Representations of the Same Magnitude | |
| |
| |
| |
Interpreting the Value of a 2's-Complement Number | |
| |
| |
| |
More on Range and Overflow | |
| |
| |
| |
2's Complement and Hardware Complexity | |
| |
| |
| |
Binary Representation of Real Numbers | |
| |
| |
| |
Fixed-Point Representation | |
| |
| |
| |
Fixed-Point Using a Universal 16.16 Format | |
| |
| |
| |
Fixed-Point Using a Universal 32.32 Format | |
| |
| |
| |
Floating-Point Representation | |
| |
| |
| |
ASCII Representation of Text | |
| |
| |
| |
Binary-Coded Decimal (BCD) | |
| |
| |
Problems | |
| |
| |
| |
Getting the Most Out of C | |
| |
| |
| |
Integer Data Types | |
| |
| |
| |
Mixing Data Types | |
| |
| |
| |
Useful Typedefs and Defines | |
| |
| |
| |
Manipulating Bits in Memory | |
| |
| |
| |
Testing Bits | |
| |
| |
| |
Setting, Clearing, and Inverting Bits | |
| |
| |
| |
Extracting Bits | |
| |
| |
| |
Inserting Bits | |
| |
| |
| |
Manipulating Bits in I/O Ports | |
| |
| |
| |
Write-Only I/O Ports | |
| |
| |
| |
Ports Differentiated by Reads Versus Writes | |
| |
| |
| |
Ports Differentiated by Sequential Access | |
| |
| |
| |
Ports Differentiated by Bits in the Written Data | |
| |
| |
| |
Accessing Memory-Mapped I/O Devices | |
| |
| |
| |
Accessing Data Through a Pointer | |
| |
| |
| |
Arrays, Pointers, and the "Address Of" Operator | |
| |
| |
| |
Structures | |
| |
| |
| |
Packed Structures | |
| |
| |
| |
Bit Fields | |
| |
| |
| |
Variant Access | |
| |
| |
| |
Casting the Address of an Object | |
| |
| |
| |
Using Unions | |
| |
| |
Problems | |
| |
| |
| |
A Programmer's View of Computer Organization | |
| |
| |
| |
Memory | |
| |
| |
| |
The Central Processing Unit (CPU) | |
| |
| |
| |
The Arithmetic and Logic Unit (ALU) | |
| |
| |
| |
Other Registers | |
| |
| |
| |
The Control Unit | |
| |
| |
| |
Input/Output (I/O) | |
| |
| |
| |
Introduction to the Intel Architecture | |
| |
| |
| |
Instruction Formats | |
| |
| |
| |
Instruction Operands | |
| |
| |
| |
Operand Restrictions | |
| |
| |
| |
Registers | |
| |
| |
| |
The Stack | |
| |
| |
| |
The Intel Real Mode Architecture | |
| |
| |
| |
Segmented Addressing | |
| |
| |
| |
Addressing Modes | |
| |
| |
| |
The Intel Protected Mode Architecture | |
| |
| |
| |
Segment Registers and The Global Descriptor Table | |
| |
| |
| |
The Flat Memory Model | |
| |
| |
| |
Addressing Modes | |
| |
| |
| |
Operand and Address-Size Override Prefixes | |
| |
| |
| |
The Intel Data Manipulation Instructions | |
| |
| |
| |
Data Movement, Stack, and I/O Instructions | |
| |
| |
| |
Arithmetic Instructions | |
| |
| |
| |
Bitwise Instructions | |
| |
| |
| |
Shift Instructions | |
| |
| |
Problems | |
| |
| |
| |
Mixing C and Assembly | |
| |
| |
| |
Programming in Assembly | |
| |
| |
| |
Register Usage Conventions | |
| |
| |
| |
Typical Use of Addressing Options | |
| |
| |
| |
Accessing Data Whose Address is a Constant | |
| |
| |
| |
Accessing Data Whose Address is a Variable | |
| |
| |
| |
Instruction Sequencing | |
| |
| |
| |
Compound Conditionals | |
| |
| |
| |
If-Then-Else Statements | |
| |
| |
| |
Building Loops | |
| |
| |
| |
Faster Loops with String Instructions | |
| |
| |
| |
Procedure Call and Return | |
| |
| |
| |
Parameter Passing | |
| |
| |
| |
Retrieving Parameters | |
| |
| |
| |
Everything is Pass by Value | |
| |
| |
| |
Temporary Variables | |
| |
| |
Problems | |
| |
| |
| |
Input/Output Programming | |
| |
| |
| |
The Intel I/O Instructions | |
| |
| |
| |
Synchronization, Transfer Rate, and Latency | |
| |
| |
| |
Polled Waiting Loops | |
| |
| |
| |
Interrupt-Driven I/O | |
| |
| |
| |
The Hardware Response | |
| |
| |
| |
The Interrupt Service Routine | |
| |
| |
| |
Programmable Interrupt Controllers | |
| |
| |
| |
Buffers and Queues | |
| |
| |
| |
Writing Interrupt Service Routines in Assembly | |
| |
| |
| |
Writing Interrupt Service Routines in C | |
| |
| |
| |
Nonmaskable Interrupts | |
| |
| |
| |
Software Interrupts | |
| |
| |
| |
Exceptions | |
| |
| |
| |
Direct Memory Access | |
| |
| |
| |
Double Buffering | |
| |
| |
| |
Comparison of Methods | |
| |
| |
Problems | |
| |
| |
| |
Concurrent Software | |
| |
| |
| |
Foreground/Background Systems | |
| |
| |
| |
Thread State and Serialization | |
| |
| |
| |
Managing Latency | |
| |
| |
| |
Preventing Interrupt Overrun | |
| |
| |
| |
Moving Work into the Background | |
| |
| |
| |
Multithreaded Programming | |
| |
| |
| |
Concurrent Execution of Independent Threads | |
| |
| |
| |
Context Switching | |
| |
| |
| |
Nonpreemptive (Cooperative) Multitasking | |
| |
| |
| |
Preemptive Multitasking | |
| |
| |
| |
Shared Resources and Critical Sections | |
| |
| |
| |
Disabling Interrupts | |
| |
| |
| |
Disabling Task Switching | |
| |
| |
| |
Spin Locks | |
| |
| |
| |
Mutex Objects | |
| |
| |
| |
Semaphores | |
| |
| |
Problems | |
| |
| |
| |
Scheduling | |
| |
| |
| |
Thread States | |
| |
| |
| |
Pending Threads | |
| |
| |
| |
Context Switching | |
| |
| |
| |
Round-Robin Scheduling | |
| |
| |
| |
Priority-Based Scheduling | |
| |
| |
| |
Priority Inversion | |
| |
| |
| |
The Priority Inheritance Protocol | |
| |
| |
| |
The Priority Ceiling Protocol | |
| |
| |
| |
Assigning Priorities | |
| |
| |
| |
Deadline-Driven Scheduling | |
| |
| |
| |
Rate-Monotonic Scheduling | |
| |
| |
| |
Deadlock | |
| |
| |
| |
Watchdog Timers | |
| |
| |
Problems | |
| |
| |
| |
Memory Management | |
| |
| |
| |
Objects in C | |
| |
| |
| |
Scope | |
| |
| |
| |
Refining Local Scope | |
| |
| |
| |
Refining Global Scope | |
| |
| |
| |
Lifetime | |
| |
| |
| |
Automatic Allocation | |
| |
| |
| |
Storage Class "Register" | |
| |
| |
| |
Static Allocation | |
| |
| |
| |
Three Programs to Distinguish Static from Automatic | |
| |
| |
| |
Object Creation | |
| |
| |
| |
Object Initialization | |
| |
| |
| |
Object Destruction | |
| |
| |
| |
Dynamic Allocation | |
| |
| |
| |
Fragmentation | |
| |
| |
| |
Memory Allocation Pools | |
| |
| |
| |
Automatic Allocation with Variable Size (alloca) | |
| |
| |
| |
Variable-Size Arrays | |
| |
| |
| |
Recursive Functions and Memory Allocation | |
| |
| |
Problems | |
| |
| |
| |
Shared Memory | |
| |
| |
| |
Recognizing Shared Objects | |
| |
| |
| |
Shared Global Data | |
| |
| |
| |
Shared Private Data | |
| |
| |
| |
Shared Functions | |
| |
| |
| |
Reentrant Functions | |
| |
| |
| |
Read-Only Data | |
| |
| |
| |
Type Qualifier "const" | |
| |
| |
| |
Coding Practices to Avoid | |
| |
| |
| |
Functions That Keep Internal State in Local Static Objects | |
| |
| |
| |
Functions That Return the Address of a Local Static Object | |
| |
| |
| |
Accessing Shared Memory | |
| |
| |
| |
The Effect of Processor Word Size | |
| |
| |
| |
Read-Only and Write-Only Access | |
| |
| |
| |
Type Qualifier "volatile" | |
| |
| |
Problems | |
| |
| |
| |
System Initialization | |
| |
| |
| |
Memory Layout | |
| |
| |
| |
The CPU | |
| |
| |
| |
Setting Up a Flat Memory Model | |
| |
| |
| |
Switching into Protected Mode | |
| |
| |
| |
C Run-Time Environment | |
| |
| |
| |
Copying from ROM to RAM | |
| |
| |
| |
Zeroing Uninitialized Statics | |
| |
| |
| |
Setting Up a Heap | |
| |
| |
| |
System Timer | |
| |
| |
| |
Timer 0: Timer Tick | |
| |
| |
| |
Timer 1: Memory Refresh | |
| |
| |
| |
Timer 2: Speaker Frequency | |
| |
| |
| |
Interrupt System | |
| |
| |
| |
Initializing the IDT | |
| |
| |
| |
Initializing the 8259 PICs | |
| |
| |
| |
Installing a New Interrupt Service Routine | |
| |
| |
| |
Contents of the CD-Rom | |
| |
| |
| |
The DJGPP C/C++ Compiler | |
| |
| |
Installation | |
| |
| |
Compilation | |
| |
| |
On-Line Documentation (Info) | |
| |
| |
| |
The NASM Assembler | |
| |
| |
Installation | |
| |
| |
Running NASM | |
| |
| |
| |
Programming Projects | |
| |
| |
Files Required from the CD-ROM for All Applications | |
| |
| |
Files Required for Nonpreemptive Multithreaded Applications | |
| |
| |
Files Required for Preemptive Multithreaded Applications | |
| |
| |
Compiling and Assembling Your Embedded Application | |
| |
| |
Linking Your Embedded Application | |
| |
| |
Preparing the Boot Diskette | |
| |
| |
Running Your Embedded Application | |
| |
| |
| |
Getting Started with the DJGPP Compiler Tools | |
| |
| |
| |
Using Fixed-Point Real Numbers | |
| |
| |
| |
Using Macros and Packed Operands | |
| |
| |
| |
Using "Makefiles" | |
| |
| |
| |
Coding Extended Precision Multiplication in Assembly | |
| |
| |
| |
Coding Extended Precision Division in Assembly | |
| |
| |
| |
Polled Waiting Loop and Interrupt-Driven I/O | |
| |
| |
| |
A Simple Nonpreemptive Multithreaded Application | |
| |
| |
| |
Preemptive Kernels and Shared Resources | |
| |
| |
| |
Avoiding Unbounded Priority Inversion | |
| |
| |
| |
Avoiding Deadlock | |
| |
| |
| |
The libepc Library | |
| |
| |
Memory Layout and Initialization | |
| |
| |
Display Functions (display.c) | |
| |
| |
Window Functions (window.c) | |
| |
| |
Keyboard Functions (keyboard.c) | |
| |
| |
Speaker Functions (speaker.c) | |
| |
| |
Timer Functions (timer.c, cycles.asm) | |
| |
| |
Interrupt Vector Access Functions (init-idt.c) | |
| |
| |
Dyamic Memory Allocation Functions (heap.c) | |
| |
| |
Fixed Point (fixedpt.asm) | |
| |
| |
Interfunction Jumps (setjmp.asm) | |
| |
| |
Miscellaneous Functions (init-crt.c) | |
| |
| |
| |
The Boot Loader | |
| |
| |
Index | |