Real-Time C++, 2nd Edition

Real-Time C++, 2nd Edition

English | 2015 | ISBN: 978-3-662-47809-7 | 378 Pages | PDF | 10 MB

Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming
With this book, Christopher Kormanyos delivers a highly practical guide to programming real-time embedded microcontroller systems in C++. It is divided into three parts plus several appendices. Part I provides a foundation for real-time C++ by covering language technologies, including object-oriented methods, template programming and optimization. Next, part II presents detailed descriptions of a variety of C++ components that are widely used in microcontroller programming. It details some of C++’s most powerful language elements, such as class types, templates and the STL, to develop components for microcontroller register access, low-level drivers, custom memory management, embedded containers, multitasking, etc. Finally, part III describes mathematical methods and generic utilities that can be employed to solve recurring problems in real-time C++. The appendices include a brief C++ language tutorial, information on the real-time C++ development environment and instructions for building GNU GCC cross-compilers and a microcontroller circuit.
For this second edition, the most recent specification of C++14 in ISO/IEC 14882:2014 is used throughout the text. Several sections on new C++14 functionality have been added, and various others reworked to reflect changes in the standard. Also two new sample projects are introduced, and various user suggestions have been incorporated. To facilitate portability, no libraries other than those specified in the language standard itself are used. Efficiency is always in focus and numerous examples are backed up with real-time performance measurements and size analyses that quantify the true costs of the code down to the very last byte and microsecond.
The target audience of this book mainly consists of students and professionals interested in real-time C++. Readers should be familiar with C or another programming language and will benefit most if they have had some previous experience with microcontroller electronics and the performance and size issues prevalent in embedded systems programming.


C++ seamlessly blends object-oriented techniques with generic template methods, creating a modern powerful programming language useful for problem-solving in
countless domains. The most recent evolution of C++ from C++11 to C++14 has brought yet further improvements to this rich language.1 As C++ becomes even more expressive, growing numbers of embedded systems developers are discovering new and fascinating ways to utilize its multifaceted capabilities for creating
efficient and effective microcontroller software.

The second edition of this book retains its original purpose to serve as a practical guide to programming real-time embedded microcontroller systems in C++. New
material has been incorporated predominantly reflecting changes introduced in the C++14 standard. Various sections have been reworked according to reader suggestions. Selected passages have been reformulated in a continued effort to improve clarity. In addition, all known errors throughout the text have been corrected.

Real-time programming is characterized by demanding performance, size and safety constraints. This, combined with the large scope of the C++ language and a poten tially complex set of development tools, can make the creation of high-quality real time C++ software a truly challenging endeavor. In the harsh world of real-time C++, the stability of the development environment can contribute to the overall quality of the software as much or even more than the actual coding itself. This chapter discusses various aspects related to the robust real-time C++ environment.

Addressing the Challenges of Real-Time C++

Microcontroller software is usually cost-sensitive, safety-critical or both and demands the utmost in efficiency and robustness. The development environment and the executable program usually run on separate systems. In addition, flashing the microcontroller generally uses a connection with a hardware interface for in-system
programming (ISP) with an on-chip debugger or an in-circuit emulator (ICE). This can make it particularly difficult to visualize, debug and test microcontroller software.
When addressing the challenges of real-time C++ programming, it may be best to start with a simple project and build up tools, coding competence and a collection of re-usable software components steadily and methodically. The brief checklist below describes some considerations that need to be made when doing real-time C++ programming.

When designing an embedded microcontroller system, the most time consuming software processes should be identified up front and designed with a temporal granularity that facilitates an even distribution of the work load. In general, it is poor form to program with blocking calls that engage the CPU for long time spans such as hundreds of microseconds or even several milliseconds. It is much better to program short, fast sequences in a multitasking environment that process information or service a state machine quickly and rapidly relinquish control to other processes in the system. Interrupt service routines should be held terse and efficient. Keeping the runtime within the established limits generally leads to a more predictable software with higher quality and reliability.