Chapter 1 Introduction
1.1 What is an Embedded System?
1.2 What's Unique About the Design Goals for Embedded Software?
1.3 What Does "Real-Time" Mean?
1.4 What Does "Multitasking" Mean?
1.5 How Powerful Are Embedded Processors?
1.6 What Programming Languages Are Used?
1.7 What Is a "Real-Time Kernel"?
1.8 How Is Building an Embedded Application Unique?
1.9 How Big Are Typical Embedded Programs?
1.10 The Software Used in This Book
Problems
Chapter 2 Data Representation
2.1 Fixed-Precision Binary Numbers
2.1.1 Positional Number Systems
2.1.2 Binary-to-Decimal Conversion
2.1.3 Decimal-to-Binary Conversion
2.1.4 Counting
2.1.5 Fixed Precision and Rollover
2.1.6 Hexadecimal Representation
2.2 Binary Representation of Integers
2.2.1 Signed Integers
2.2.2 Positive and Negative Representations of the Same Magnitude
2.2.3 Interpreting the Value of a 2's-Complement Number
2.2.4 More on Range and Overflow
2.2.5 2's Complement and Hardware Complexity
2.3 Binary Representation of Real Numbers
2.3.1 Fixed-Point Representation
2.3.2 Fixed-Point Using a Universal 16.16 Format
2.3.3 Fixed-Point Using a Universal 32.32 Format
2.3.4 Floating-Point Representation
2.4 ASCII Representation of Text
2.5 Binary-Coded Decimal (BCD)
Problems
Chapter 3 Getting the Most Out of C
3.1 Integer Data Types
3.2 Mixing Data Types
3.3 Useful Typedefs and Defines
3.4 Manipulating Bits in Memory
3.4.1 Testing Bits
3.4.2 Setting, Clearing, and Inverting Bits
3.4.3 Extracting Bits
3.4.4 Inserting Bits
3.5 Manipulating Bits in I/O Ports
3.5.1 Write-Only I/O Ports
3.5.2 Ports Differentiated by Reads Versus Writes
3.5.3 Ports Differentiated by Sequential Access
3.5.4 Ports Differentiated by Bits in the Written Data
3.6 Accessing Memory-Mapped I/O Devices
3.6.1 Accessing Data Through a Pointer
3.6.2 Arrays, Pointers, and the "Address of" Operator
3.7 Structures
3.7.1 Packed Structures
3.7.2 Bit Fields
3.8 Variant Access
3.8.1 Casting the Address of an Object
3.8.2 Using Unions
Problems
Chapter 4 A Programmer's View of Computer Organization
4.1 Memory
4.2 The Central Processing Unit (CPU)
4.2.1 The Arithmetic and Logic Unit (ALU)
4.2.2 Other Registers
4.2.3 The Control Unit
4.3 Input/Output (I/O)
4.4 Introduction to the Intel Architecture
4.4.1 Instruction Formats
4.4.2 Instruction Operands
4.4.3 Operand Restrictions
4.4.4 Registers
4.4.5 The Stack
4.5 The Intel Real Mode Architecture
4.5.1 Segmented Addressing
4.5.2 Addressing Modes
4.6 The Intel Protected Mode Architecture
4.6.1 Segment Registers and The Global Descriptor Table
4.6.2 The Flat Memory Model
4.6.3 Addressing Modes
4.7 Operand and Address-Size Override Prefixes
4.8 The Intel Data Manipulation Instructions
4.8.1 Data Movement, Stack, and I/O Instructions
4.8.2 Arithmetic Instructions
4.8.3 Bitwise Instructions
4.8.4 Shift Instructions
Problems
Chapter 5 Mixing C and Assembly
5.1 Programming in Assembly
5.2 Register Usage Conventions
5.3 Typical Use of Addressing Options
5.3.1 Accessing Data Whose Address is a Constant
5.3.2 Accessing Data Whose Address is a Variable
5.4 Instruction Sequencing
5.4.1 Compound Conditionals
5.4.2 If-Then-Else Statements
5.4.3 Building Loops
5.4.4 Faster Loops with String Instructions
5.5 Procedure Call and Return
5.6 Parameter Passing
5.7 Retrieving Parameters
5.8 Everything is Pass by Value
5.9 Temporary Variables
Problems
Chapter 6 Input/Output Programming
6.1 The Intel I/O Instructions
6.2 Synchronization, Transfer Rate, and Latency
6.3 Polled Waiting Loops
6.4 Interrupt-Driven I/O
6.4.1 The Hardware Response
6.4.2 The Interrupt Service Routine
6.4.3 Programmable Interrupt Controllers
6.4.4 Buffers and Queues
6.4.5 Writing Interrupt Service Routines in Assembly
6.4.6 Writing Interrupt Service Routines in C
6.4.7 Nonmaskable Interrupts
6.4.8 Software Interrupts
6.4.9 Exceptions
6.5 Direct Memory Access
6.5.1 Double Buffering
6.6 Comparison of Methods
Problems
Chapter 7 Concurrent Software
7.1 Foreground/Background Systems
7.1.1 Thread State and Serialization
7.1.2 Managing Latency
7.1.3 Preventing Interrupt Overrun
7.1.4 Moving Work into the Background
7.2 Multithreaded Programming
7.2.1 Concurrent Execution of Independent Threads
7.2.2 Context Switching
7.2.3 Nonpreemptive (Cooperative) Multitasking
7.2.4 Preemptive Multitasking
7.3 Shared Resources and Critical Sections
7.3.1 Disabling Interrupts
7.3.2 Disabling Task Switching
7.3.3 Spin Locks
7.3.4 Mutex Objects
7.3.5 Semaphores
Problems
Chapter 8 Scheduling
8.1 Thread States
8.2 Pending Threads
8.3 Context Switching
8.4 Round-Robin Scheduling
8.5 Priority-Based Scheduling
8.5.1 Priority Inversion
8.5.2 The Priority Inheritance Protocol
8.5.3 The Priority Ceiling Protocol
8.6 Assigning Priorities
8.6.1 Deadline-Driven Scheduling
8.6.2 Rate-Monotonic Scheduling
8.7 Deadlock
8.8 Watchdog Timers
Problems
Chapter 9 Memory Management
9.1 Objects in C
9.2 Scope
9.2.1 Refining Local Scope
9.2.2 Refining Global Scope
9.3 Lifetime
9.4 Automatic Allocation
9.4.1 Storage Class "Register"
9.5 Static Allocation
9.6 Three Programs to Distinguish Static from Automatic
9.6.1 Object Creation
9.6.2 Object Initialization
9.6.3 Object Destruction
9.7 Dynamic Allocation
9.7.1 Fragmentation
9.7.2 Memory Allocation Pools
9.8 Automatic Allocation with Variable Size (alloca)
9.8.1 Variable-Size Arrays
9.9 Recursive Functions and Memory Allocation
Problems
Chapter 10 Shared Memory
10.1 Recognizing Shared Objects
10.1.1 Shared Global Data
10.1.2 Shared Private Data
10.1.3 Shared Functions
10.2 Reentrant Functions
10.3 Read-Only Data
10.3.1 Type Qualifier "const"
10.4 Coding Practices to Avoid
10.4.1 Functions That Keep Internal State in Local Static Objects
10.4.2 Functions That Return the Address of a Local Static Object
10.5 Accessing Shared Memory
10.5.1 The Effect of Processor Word Size
10.5.2 Read-Only and Write-Only Access
10.5.3 Type Qualifier "volatile"
Problems
Chapter 11 System Initialization
11.1 Memory Layout
11.2 The CPU
11.2.1 Setting Up a Flat Memory Model
11.2.2 Switching into Protected Mode
11.3 C Run-Time Environment
11.3.1 Copying from ROM to RAM
11.3.2 Zeroing Uninitialized Statics
11.3.3 Setting Up a Heap
11.4 System Timer
11.4.1 Timer 0: Timer Tick
11.4.2 Timer 1: Memory Refresh
11.4.3 Timer 2: Speaker Frequency
11.5 Interrupt System
11.5.1 Initializing the IDT
11.5.2 Initializing the 8259 PICs
11.5.3 Installing a New Interrupt Service Routine
Appendix A: Contents of the CD-ROM
Appendix B: The DJGPP C/C++ Compiler
Installation
Compilation
On-Line Documentation (Info)
Appendix C: The NASM Assembler
Installation
Running NASM
Appendix D: 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
Appendix E: 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)
Dynamic Memory Allocation Functions (heap.c)
Fixed Point (fixedpt.asm)
Interfunction Jumps (setjmp.asm)
Miscellaneous Functions (init-crt.c)
Appendix F: The Boot Loader