Table of contents for Fundamentals of embedded software : where C and assembly meet / Daniel W. Lewis.


Bibliographic record and links to related information available from the Library of Congress catalog. Note: Electronic data is machine generated. May be incomplete or contain other coding.


Counter




Chapter 1    Introduction   1
             1.1 What is an Embedded System? 1
             1.2 What's Unique About the Design Goals for Embedded Software'
             1.3 What Does "Real-Time" Mean? 5
             1.4 What Does "Multitasking" Mean? 6
             1.5 How Powerful Are Embedded Processors? 7
             1.6 What Programming Languages Are Used?  7
             1.7 What Is a "Real-Time Kernel"? 8
             1.8 How Is Building an Embedded Application Unique? 9
             1.9 How Big Are Typical Embedded Programs? 11
             1.10 The Software Used in This Book 12
             Problems 14

Chapter 2 Data Representation 15
             2.1 Fixed-Precision Binary Numbers 15
                  2.1.1 Positional Number Systems 16
                  2.1.2 Binary-to-Decimal Conversion 17
                  2.1.3 Decimal-to-Binary Conversion 17
                  2.1.4 Counting 19
                  2.1.5 Fixed Precision and Rollover 19
                  2.1.6 Hexadecimal Representation 20
             2.2 Binary Representation of Integers 21
                  2.2.1 Signed Integers 21
                  2.2.2 Positive and Negative Representations of the Same
                       Magnitude 22
                  2.2.3 Interpreting the Value of a 2's-Complement Number 23
                  2.2.4 More on Range and Overflow 24
                  2.2.5 2's Complement and Hardware Complexity 25
             2.3 Binary Representation of Real Numbers 28
                  2.3.1 Fixed-Point Representation 28
                  2.3.2 Fixed-Point Using a Universal 16.16 Format 30
                  2.3.3 Fixed-Point Using a Universal 32.32 Format 32
                  2.3.4 Floating-Point Representation 35



              2.4 ASCII Representation of Text 37
              2.5 Binary-Coded Decimal (BCD) 39
              Problems 40

Chapter 3    Getting the Most Out of C    43
              3.1 Integer Data Types 43
              3.2 Mixing Data Types 46
              3.3 Useful Typedefs and Defines 47
              3.4 Manipulating Bits in Memory 48
                  3.4.1 Testing Bits 50
                  3.4.2 Setting, Clearing, and Inverting Bits 51
                  3.4.3 Extracting Bits 52
                  3.4.4 Inserting Bits 52
              3.5 Manipulating Bits in I/O Ports 53
                  3.5.1 Write-Only I/O Ports 53
                  3.5.2 Ports Differentiated by Reads Versus Writes 54
                  3.5.3 Ports Differentiated by Sequential Access 54
                  3.5.4 Ports Differentiated by Bits in the Written Data
              3.6 Accessing Memory-Mapped I/O Devices 55
                  3.6.1 Accessing Data Through a Pointer 55
                  3.6.2 Arrays, Pointers, and the "Address Of" Operator
              3.7 Structures 58
                  3.7.1 Packed Structures 59
                  3.7.2 Bit Fields 60
              3.8 Variant Access 61
                  3.8.1 Casting the Address of an Object 61
                  3.8.2 Using Unions 63
              Problems 63


Chapter 4    A Programmer's View of Computer Organization
              4.1 Memory 65
              4.2 The Central Processing Unit (CPU) 67
                  4.2.1 The Arithmetic and Logic Unit (ALU) 67
                  4.2.2 Other Registers 68
                  4.2.3 The Control Unit 69
              4.3 Input/Output (I/O) 70
              4.4 Introduction to the Intel Architecture 71
                   4.4.1 Instruction Formats 72
                   4.4.2 Instruction Operands 73
                   4.4.3 Operand Restrictions 74



                  4.4.4 Registers 75
                  4.4.5 The Stack 77
             4.5 The Intel Real Mode Architecture 78
                  4.5.1 Segmented Addressing 79
                  4.5.2 Addressing Modes 81
             4.6 The Intel Protected Mode Architecture 83
                  4.6.1 Segment Registers and The Global Descriptor Table 84
                  4.6.2 The Flat Memory Model 85
                  4.6.3 Addressing Modes 85
             4.7 Operand and Address-Size Override Prefixes 86
             4.8 The Intel Data Manipulation Instructions 86
                  4.8.1 Data Movement, Stack, and I/O Instructions 87
                  4.8.2 Arithmetic Instructions 89
                  4.8.3 Bitwise Instructions 91
                  4.8.4 Shift Instructions 91
             Problems 93


Chapter 5    Mixing C and Assembly      96
             5.1 Programming in Assembly 96
             5.2 Register Usage Conventions 98
             5.3 Typical Use of Addressing Options 98
                  5.3.1 Accessing Data Whose Address is a Constant 99
                  5.3.2 Accessing Data Whose Address is a Variable 100
             5.4 Instruction Sequencing 101
                  5.4.1 Compound Conditionals 102
                  5.4.2 If-Then-Else Statements 104
                  5.4.3 Building Loops 105
                  5.4.4 Faster Loops with String Instructions 106
              5.5 Procedure Call and Return 107
              5.6 Parameter Passing 108
              5.7 Retrieving Parameters 110
              5.8 Everything is Pass by Value 112
              5.9 Temporary Variables 112
              Problems 115


Chapter 6    Input/Output Programming       117
              6.1 The Intel I/O Instructions 118
              6.2 Synchronization, Transfer Rate, and Latency 118
              6.3 Polled Waiting Loops 119



              6.4 Interrupt-Driven I/O  121
                  6.4.1 The Hardware Response 121
                  6.4.2 The Interrupt Service Routine 124
                  6.4.3 Programmable Interrupt Controllers 125
                  6.4.4 Buffers and Queues 126
                  6.4.5 Writing Interrupt Service Routines in Assembly 128
                  6.4.6 Writing Interrupt Service Routines in C 129
                  6.4.7 Nonmaskable Interrupts 130
                  6.4.8 Software Interrupts 130
                  6.4.9 Exceptions 132
              6.5 Direct Memory Access 132
                  6.5.1 Double Buffering 133
              6.6 Comparison of Methods 134
              Problems 135


Chapter 7    Concurrent Software    138
              7.1 Foreground/Background Systems 138
                  7.1.1 Thread State and Serialization 139
                  7.1.2 Managing Latency 139
                  7.1.3 Preventing Interrupt Overrun 143
                  7.1.4 Moving Work into the Background 144
              7.2 Multithreaded Programming 145
                  7.2.1 Concurrent Execution of Independent Threads 145
                  7.2.2 Context Switching 146
                  7.2.3 Nonpreemptive (Cooperative) Multitasking 147
                  7.2.4 Preemptive Multitasking 147
              7.3 Shared Resources and Critical Sections 148
                  7.3.1 Disabling Interrupts 150
                  7.3.2 Disabling Task Switching 150
                  7.3.3 Spin Locks 151
                  7.3.4 Mutex Objects 152
                  7.3.5 Semaphores 152
              Problems 153


Chapter 8    Scheduling    155
              8.1 Thread States 155
              8.2 Pending Threads 156
              8.3 Context Switching 157
              8.4 Round-Robin Scheduling 158




              8.5 Priority-Based Scheduling 159
                  8.5.1 Priority Inversion 159
                  8.5.2 The Priority Inheritance Protocol 160
                  8.5.3 The Priority Ceiling Protocol 161
              8.6 Assigning Priorities 161
                  8.6.1 Deadline-Driven Scheduling 161
                  8.6.2 Rate-Monotonic Scheduling 162
              8.7 Deadlock 163
              8.8 Watchdog Timers 164
              Problems 166


Chapter 9     Memory Management        168
              9.1 Objects in C 168
              9.2 Scope 169
                  9.2.1 Refining Local Scope 169
                  9.2.2 Refining Global Scope 170
              9.3 Lifetime 171
              9.4 Automatic Allocation 172
                  9.4.1 Storage Class "Register" 173
              9.5 Static Allocation 174
              9.6 Three Programs to Distinguish Static from Automatic 174
                   9.6.1 Object Creation 175
                   9.6.2 Object Initialization 175
                   9.6.3 Object Destruction 176
              9.7 Dynamic Allocation 177
                   9.7.1 Fragmentation 178
                   9.7.2 Memory Allocation Pools 179
              9.8 Automatic AllocationwithVariableSize(alloca) 179
                   9.8.1 Variable-Size Arrays 180
              9.9 Recursive Functions and Memory Allocation 181
              Problems 182


Chapter 10 Shared Memory 189
              10.1 Recognizing Shared Objects 189
                   10.1.1 Shared Global Data 190
                   10.1.2 Shared Private Data 190
                   10.1.3 Shared Functions 190
              10.2 Reentrant Functions 190



             10.3 Read-Only Data 191
                  10.3.1 Type Qualifier "const" 191
             10.4 Coding Practices to Avoid 192
                  10.4.1 Functions That Keep Internal State in Local Static Objects 192
                  10.4.2 Functions That Return the Address of a Local Static Object 194
             10.5 Accessing Shared Memory 195
                  10.5.1 The Effect of Processor Word Size 196
                  10.5.2 Read-Only and Write-Only Access 197
                  10.5.3 Type Qualifier "volatile" 198
             Problems 200

Chapter 11    System Initialization  203
             11.1 Memory Layout 203
             11.2 The CPU 204
                  11.2.1 Setting Up a Flat Memory Model 204
                  11.2.2 Switching into Protected Mode 207
             11.3 C Run-Time Environment 207
                  11.3.1 Copying from ROM to RAM  208
                  11.3.2 Zeroing Uninitialized Statics 208
                  11.3.3 Setting Up a Heap 209
             11.4 System Timer 211
                  11.4.1 Timer 0: Timer Tick 211
                  11.4.2 Timer 1: Memory Refresh 212
                  11.4.3 Timer 2: Speaker Frequency 212
             11.5 Interrupt System 213
                  11.5.1 Initializing the IDT 213
                  11.5.2 Initializing the 8259 PICs 215
                  11.5.3 Installing a New Interrupt Service Routine 216

Appendix A: Contents of the CD-Rom 219

Appendix B: The DJGPP C/C++ Compiler          220
             Installation 220
             Compilation 221
             On-Line Documentation (Info) 222


Appendix C: The NASM Assembler 223
             Installation 223
             Running NASM 223



Appendix D: Programming Projects 225
              Files Required from the CD-ROM for All Applications 225
              Files Required for Nonpreemptive Multithreaded Applications 225
              Files Required for Preemptive Multithreaded Applications 226
              Compiling and Assembling Your Embedded Application 226
              Linking Your Embedded Application 226
              Preparing the Boot Diskette 227
              Running Your Embedded Application 227
                 Program 1: Getting Started with the DJGPP Compiler Tools 228
                 Program 2: Using Fixed-Point Real Numbers 230
                 Program 3: Using Macros and Packed Operands 231
                 Program 4: Using "Makefiles" 232
                 Program 5: Coding Extended Precision Multiplication in Assembly 235
                 Program 6: Coding Extended Precision Division in Assembly 237
                 Program 7: Polled Waiting Loop and Interrupt-Driven I/O 238
                 Program 8: A Simple Nonpreemptive Multithreaded Application 240
                 Program 9: Preemptive Kernels and Shared Resources 242
                 Program 10: Avoiding Unbounded Priority Inversion 245
                 Program 11: Avoiding Deadlock 246


Appendix E: The libepc Library 247
              Memory Layout and Initialization 247
              Display Functions (display.c) 248
              Window Functions (window.c) 250
              Keyboard Functions (keyboard.c) 251
              Speaker Functions (speaker.c) 252
              Timer Functions (timer.c, cycles.asm) 252
              Interrupt Vector Access Functions (init-idt.c) 253
              Dyamic Memory Allocation Functions (heap.c) 254
              Fixed Point (fixedpt.asm) 254
              Interfunction Jumps (setjmp.asm) 255
              Miscellaneous Functions (init-crt.c) 256