EARTH WEEK
Now through April 22, save up to 70% on digital learning resources. Learn more.
Register your product to gain access to bonus material or receive a coupon.
Real-time embedded systems have rigid requirements and must conform to strict size, cost, weight, power, operation, and response-time specifications. They must be crash-proof and must operate under a wide range of conditions. Add to these requirements the ever-increasing competitive pressures to bring products to market faster and at a lower cost, and it is easy to see why building such systems is difficult. Real-time programmers must write software that meets unforgiving objectives under numerous constraints. Teaching you how is the goal of this book.
Real-Time Programming is a comprehensive guide that
No matter what hardware and software platforms you will ultimately use, this book lays the groundwork and gets you up-to-speed on the unique requirements of real-time embedded programming.
(Each chapter concludes with a Summary.)
Acknowledgments.
Introduction.
1. An Introduction to Embedded Systems.
Real-Time Systems.
Hard Real-Time.
Soft Real-Time.
Real-Time Embedded Systems.
Embedded Processors.
The Advent of PC Embedded Systems.
PC Hardware Components.
The Advantages of the PC Architecture.
Does an Embeddable PC Suit Your Application?
A Practical Approach.
The Iterative Approach.
The Analysis Phase.
Stating the Problem.
Specifying Project Constraints.
Listing Customer Requirements.
Specifying Hardware and Software.
Verifying Your Analysis.
An Example.
The Design Phase.
Reviewing the Analysis.
Specifying Hardware Components.
Defining Hardware Interfaces.
Specifying Software Subsystems.
Defining Software Interfaces.
Specifying the Start-up and Shutdown Processes.
Specifying Error Handling.
Verifying Your Design.
An Example.
Some Decisions.
Choosing a Processor.
Choosing Hardware Components.
Choosing an Operating System.
Choosing a Programming Language.
Choosing Software Development Tools.
Choosing Hardware Debugging Tools.
Choosing Software Components.
The Implementation Phase.
Planning the Implementation.
Implementing the Design.
Choosing a Platform and Tools.
ToolSuite Lite Components.
Embedded StudioExpress.
LinkLoc.
Real-Time ETS Kernel.
What’s Lite About ToolSuite Lite?
ETS Kernel Application Environment.
Segment Selectors.
Null Pointer Detection.
The Stack and the Heap.
The Command Line and the Environment.
Interrupts.
Hardware Setup.
Software Installation and Setup.
Installing ToolSuite Lite.
Configuring Visual C++ and Developer Studio.
Setting Up the Host Environment.
Building a Boot Disk.
Testing the Host-Target Connection.
Programming Projects.
Opening a Workspace.
Running a Program.
Building a Program.
Creating New Programming Projects.
Software Debuggers.
Hardware Debuggers.
In-Circuit Emulators.
ROM Emulators.
Software Simulators.
Debugging with ToolSuite.
A Buggy Calculation.
Debugging the Application.
Embedded StudioExpress Extensions.
Target Port Input/Output.
Target System Information.
How the POS Project Works.
Designing the Simulation.
Software Subsystems.
Software Interfaces.
Start-up and Shutdown Processes.
Error Handling.
Building the POS Project.
Running the POS Project.
A Quick Tour of the Source.
Buttons, Keypads, and Keyboards.
LEDs, LCDs, and Displays.
ETS Kernel Support of Keyboard and Screen I/O.
Host Console I/O.
ETS Kernel Keyboard Driver.
ETS Kernel Screen Driver.
Code from the POS Project.
Keyboard Input.
Screen Output.
Choosing a File System.
Performance.
Reliability.
Multitasking and Multiuser Capabilities.
Choosing a Storage Device.
RAM Disks.
Flash Disks.
ROM Disks.
Hard Disk Drives.
Floppy Disk Drives.
CD-ROM Drives.
Magnetic Tape.
ETS Kernel File System.
Local File System.
Remote File System.
File I/O in the POS Project.
How the UPS Project Works.
Designing the Simulation.
Software Subsystems.
Software Interfaces.
Start-up and Shutdown Processes.
Error Handling.
Building the UPS Project.
Running the UPS Project.
A Quick Tour of the Source.
How Interrupts Work.
Hardware Interrupts.
Software Interrupts.
Exceptions.
ISR Fundamentals.
Using High-Level Languages.
Reentrancy.
Interrupt Latency.
Chaining ISRs.
Multitasking Considerations.
Interrupts on the PC Architecture.
Interrupt Handling Under ETS Kernel.
C Interrupt Handlers.
IDT Interrupt Handlers.
Timer and Keyboard Callbacks.
Interrupts in the UPS Project.
Keyboard Callbacks.
Timer Callbacks.
Timer Applications.
Selecting Timer Hardware.
Software Considerations.
ETS Kernel Timers.
Timers in the UPS Project.
How the Smart UPS Project Works.
Designing the Simulation.
Software Subsystems.
Software Interfaces.
Start-up and Shutdown Processes.
Error Handling.
Building the Smart UPS Project.
Running the Smart UPS Project.
A Quick Tour of the Source.
Processes and Multiprocessing.
Threads and Multithreading.
Processes versus Threads.
Scheduling.
Round-Robin Scheduling.
Task Priorities.
vPriority Inversion.
Deadlock.
Starvation.
Synchronization.
Mutex Objects.
Semaphore Objects.
Event Objects.
Interlocked Variable Access.
Intertask Communication.
Pipes.
Message Queues.
Shared Memory.
Remote Procedure Calls.
Interrupt Handling.
Choosing an RTOS.
Debugging.
Threads in the Smart UPS Project.
Starting a Thread.
Controlling Thread Priority.
Terminating a Thread.
Writing ISRs.
The Smart UPS Code.
Fundamentals of Serial I/O.
Baud Rate versus Bits Per Second.
Asynchronous versus Synchronous Communications.
Error Detection.
Flow Control.
Electrical Standards and Communication Protocols.
The UART.
Writing Serial Port ISRs.
The RS-232C Serial Standard.
Mechanical Specification.
Electrical Specification.
Functional Specification.
Procedural Specification.
Peripheral Serial Buses.
Chip-to-Chip Serial Buses.
Serial I/O in the Smart UPS.
The 8250/16x50 UART Family.
Initializing the Serial I/O Subsystem.
Cleaning Up.
The Serial I/O Thread.
How the Network-Aware UPS Project Works.
Designing the Simulation.
Software Subsystems.
Software Interfaces.
Start-up and Shutdown Processes.
Error Handling.
Building the Network-Aware UPS Project.
Running the Network-Aware UPS Project.
A Quick Tour of the Source.
Networking Concepts.
What Is a Network?
Internetworks and the Internet.
Network Technologies.
Protocols.
The ISO/OSI Network Design Model.
Repeaters, Bridges, and Routers.
Virtual Communication.
Comparing Connection-Oriented and Connectionless Protocols.
Comparing Reliable and Unreliable Protocols.
The Client/Server Model.
Networking in Embedded Systems.
Selecting the Protocol Stack.
Selecting a Network Technology.
Selecting an Existing Implementation.
Using Standard Application Protocols.
Popular Network Architectures.
Advantages of the TCP/IP Protocol Stack.
The TCP/IP Network Implementation.
Network Interface Layer.
Internet Layer.
Transport Layer.
Application Layer.
Network Programming for ETS Kernel.
WinSock API.
Building the Finger Server Project.
Running the Finger Server Project.
The Finger Server Code.
HTTP In Embedded Applications.
The HTTP Protocol.
Web Browsers.
Web Servers.
URLs and URIs.
HTTP Messages.
Persistent Connections.
Caching.
Secure HTTP.
HTML in Embedded Applications.
Dynamic HTML.
ETS Kernel HTTP Server.
HTML-On-The-Fly in the Network-Aware UPS.
A Language and a Platform.
Platform Alternatives.
Compiler Alternatives.
Advantages for Embedded Development.
Processor Independence.
Object-Oriented Programming.
Security and Secure Operations.
Memory Management.
Garbage Collection.
Networking.
Dynamic Configuration.
Exception Handling.
Threading.
Graphics.
Limitations of Java.
Performance.
Garbage Collection Overhead.
JVM Overhead.
Hardware Access.
Language Immaturity.
The Java-Enabled UPS.
Building the Java-Enabled UPS Project.
Running the Java-Enabled UPS Project.
A Quick Tour of the Source.
Scientific Notation Terminology.
Floating-Point Support on Embedded Systems.
Floating-Point Data Formats.
Exponent Format.
Mantissa Format.
Number Holes.
Special Numbers.
Floating-Point Hardware and Software.
Hardware.
Software.
Why Use Floating-Point Emulation Software?
A Bitmap Filter.
How the Bitmap Filter Project Works.
Building the Bitmap Filter Project.
Running the Bitmap Filter Project.
A Quick Tour of the Source.
What Is a DLL?
Advantages of Using DLLs.
Memory Requirements.
System Upgrades.
System Configuration and Customization.
Disadvantages of Using DLLs.
Using DLLs with ETS Kernel.
The ENCDEC Project.
Building the ENCDEC Project.
Running the ENCDEC Project.
A Quick Tour of the Source.
Benefits of Exception Handling.
Exception Handling in Embedded Systems.
Robust Code.
Clean Code.
C++ Exception Handling.
Structured Exception Handling.
Structured Exceptions in C.
Structured Exceptions in C++.
A Restartable UPS.
Building the Restartable UPS Project.
Running the Restartable UPS Project.
A Quick Tour of the Source.
Using ROM in Embedded Systems.
Types of ROM.
Mask-Programmed and Fusible-Link ROMs.
EPROMs.
EEPROMs.
Flash Memory.
Programming PROMs.
Device Programmers.
Input Files for Device Programmers.
In-Circuit Programmers.
In-the-Field Software Updates.
Debugging Programs in ROM.
PC Boot Methods.
Boot Jump ROM.
BIOS Extension Boot.
ROM-based File System Boot.
ToolSuite Support for ROM.
This is a practical, hands-on guide to building real-time embedded software. You read right. Plenty of books take a high-level, theoretical approach to real-time embedded systems development; other texts take a hardware-specific approach, emphasizing building applications for atypical hardware. Few books, however, focus on developing real-time embedded software.
We understand why authors have gravitated to one of these two extremes. The absence of standard hardware, standard development tools, and a standard operating system virtually demanded that authors pursue either a theoretical or hardware-specific approach.
The world is changing, however. As time to market becomes ever more important, developers of embedded systems are starting to turn more to off-the-shelf boards and components. In particular, the PC architecture, with its high-volume cost advantages, standardized interfaces, and plethora of suppliers, is an attractive choice for systems produced in low to medium quantities.
This shift--that is, the emergence of a standard platform that is also already widely used and understood by developers--enabled us to carve out a middle ground: a book that focuses on software issues surrounding real-time embedded application development. From the beginning, we cover everyday programming topics such as designing, developing, and debugging real-time embedded applications. We show you how to implement interrupts, timers, threads, and more in real-time embedded programs. And we illustrate all topics with code examples. Because you're probably already familiar with the PC architecture, and because it's been exhaustively explored and documented, we don't spend time on hardware details--and neither do you. Both the host and target development platforms are PC-based, so you should have all the hardware you need to get started; you don't have to spend time or money building custom hardware.
At least half the value of using standard hardware is using standard software. This is where Phar Lap Software's ToolSuite Lite comes in. Included on the CD-ROM, ToolSuite Lite is a limited version of Phar Lap's TNT Embedded ToolSuite, Realtime Edition. TNT Embedded ToolSuite supports off-the-shelf compilers and tools, and enables you to build and deploy real-time embedded applications that use the PC architecture.
ToolSuite Lite includes a real-time embedded operating system (ETS Kernel) that supports a subset of Microsoft's Win32 API--the same API used for Windows 95, 98, and NT. (ETS Kernel is not Microsoft Windows. The kernel looks and acts like Windows, but that's as far as the similarity goes. Phar Lap's ETS Kernel is compact, scalable, and optimized for real-time embedded systems.) ToolSuite Lite also includes support for the Microsoft Visual C++ compiler and run-time libraries, Microsoft Developer Studio Integrated Developer Environment (IDE), and the use of the Developer Studio debugger as a cross-debugger for real-time embedded programs.
Note: According to Microsoft Visual C++ 6.0 Programmer's Guide (Microsoft Press, 1998), with the release of Visual C++ 6.0, Microsoft no longer distinguishes between Visual C++ the product and Developer Studio the IDE, and uses Visual C++ to refer to both. For the purposes of our discussion, however, we continue to refer to the IDE in Visual C++ 6.0 as Developer Studio.
We included ToolSuite Lite because the best way to learn how to write programs is to, well, write them. With the software on the CD-ROM, a copy of Microsoft Visual C++, two PC-compatible computers, and a LapLink-compatible cable, you can build, run, and debug all the programming projects in this book.
Is This Book for You?Does this book target only PC and Win32 developers? Not at all. We had to choose specific hardware and software platforms so that you could actually build and run the real-time embedded programs in this book. But you can apply the principles of embedded systems development described here to the design and development of any embedded product, regardless of which specific processor, real-time operating system, and software tools you use.
You'll find this book worthwhile if you are one of the following:
We have only one prerequisite. You should be conversant in the C programming language so that you can read the source code (most examples are in C) and understand what's going on. A few projects are written partially in C++, and one of the programming projects includes a Java applet. Nevertheless, C is the only requirement. Knowledge of C++, the Win32 API, and Java, however, would provide a headstart.
Embedded Systems: Wave? You Mean TsunamiThe number and types of embedded systems available make it almost impossible to miss the trend toward embedded systems. Your programmable microwave is an embedded system. Your VCR is an embedded system. Your TV remote is an embedded system. And if your TV is programmable, it's embedded, too.
You can expect the embedded systems trend to continue. In the September 1996 issue of Computer Design magazine, Ray Weiss wrote an article titled, "Embedded Advances in Auto, Communications, Office, Industry, and Consumer Markets." Based on information released by Motorola, Weiss wrote that the average 1990 car contained about 14 microprocessors; by the year 2000, that number is expected to reach 35.
Now combine this with another trend that's even more difficult to miss: that wildfire called the Internet. The same Computer Design article mentioned earlier continues:
Home set-top-box and Internet connections via ISDN or higher home-connection technologies like 8-Mbit ADSL (Asymmetric Digital Subscriber Line) have the potential to feed huge communications growth as homes tie into advanced digital services for set-top or cable boxes. And expect these boxes to become integrated into TV sets soon...VMEbus and PC-based systems are expected to play a major role as system bases for these applications.
Set-top boxes, routers, modems--in short, the infrastructure of the Internet--are embedded systems, a fact that further supports the expectation that embedded systems will become increasingly prevalent.
Although the growth of the embedded market is largely due to new uses and applications for embedded systems, it's also been fueled by advancements in microprocessors. Increases in processor speed, bus width, and the number of peripherals that manufacturers can squeeze on a chip have increased the variety of chips available for embedded systems and their suitability to a wider variety of tasks. RISC chips are now common in high-end embedded applications and even in not so high-end applications, if you loo