Real-Time C++ (eBook)

Efficient Object-Oriented and Template Microcontroller Programming
eBook Download: PDF
2018 | 3rd ed. 2018
XXXIII, 426 Seiten
Springer Berlin Heidelberg (Verlag)
978-3-662-56718-0 (ISBN)

Lese- und Medienproben

Real-Time C++ - Christopher Kormanyos
Systemvoraussetzungen
53,49 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

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 third edition, the most recent specification of C++17 in ISO/IEC 14882:2017 is used throughout the text. Several sections on new C++17 functionality have been added, and various others reworked to reflect changes in the standard. Also several new sample projects are introduced and existing ones extended, 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.



Christopher Kormanyos is a senior system architect at a major automotive supplier with 25 years of experience in software development, microcontroller system design and application deployment. Chris is well-connected in the microcontroller industry and has strong professional ties to both tier-one silicon suppliers as well as compiler and tool vendors. He received a PhD in experimental particle physics from the University of Colorado in 1994 and also holds several patents for automotive electronic technologies.

Christopher Kormanyos is a senior system architect at a major automotive supplier with 25 years of experience in software development, microcontroller system design and application deployment. Chris is well-connected in the microcontroller industry and has strong professional ties to both tier-one silicon suppliers as well as compiler and tool vendors. He received a PhD in experimental particle physics from the University of Colorado in 1994 and also holds several patents for automotive electronic technologies.

Preface to the Third Edition 6
New or Significantly Modified Sections 6
Improved or New Examples and Code Snippets 7
Companion Code 8
Further Notes on Coding Style 8
Updated Trademarks and Acknowledgments 9
Preface to the Second Edition 10
Companion Code 11
More Notes on Coding Style 11
Preface to the First Edition 13
About This Book 13
Companion Code, Targets and Tools 14
Notes on Coding Style 15
Acknowledgements 19
Contents 20
Acronyms 26
References 29
Part I Language Technologies for Real-Time C++ 31
1 Getting Started with Real-Time C++ 32
1.1 The LED Program 32
1.2 The Syntax of C++ 35
1.3 Class Types 35
1.4 Members 39
1.5 Objects and Instances 41
1.6 #include 42
1.7 Namespaces 43
1.8 C++ Standard Library 45
1.9 The main() Subroutine 45
1.10 Low-Level Register Access 46
1.11 Compile-Time Constant 47
References 48
2 Working with a Real-Time C++ Program on a Board 49
2.1 The Target Hardware 49
2.2 Build and Flash the LED Program 50
2.3 Adding Timing for Visible LED Toggling 54
2.4 Run and Reset the LED Program 56
2.5 Recognizing and Handling Errors and Warnings 56
2.6 Reaching the Right Efficiency 58
References 61
3 An Easy Jump Start in Real-Time C++ 62
3.1 Declare Locals when Used 62
3.2 Fixed-Size Integer Types 63
3.3 The bool Type 65
3.4 Organization with Namespaces 66
3.5 Basic Classes 68
3.6 Basic Templates 69
3.7 nullptr Replaces NULL 72
3.8 Generalized Constant Expressions with constexpr 73
3.9 static assert 74
3.10 Using < limits>
3.11 std::array 75
3.12 Basic STL Algorithms 76
3.13 < numeric>
3.14 atomic load() and atomic store() 78
3.15 Digit Separators 78
3.16 Binary Literals 79
3.17 User-Defined Literals 80
3.18 Using alignof and alignas 83
3.19 The Specifier final 84
3.20 Alias as an Alternative to typedef 85
References 87
4 Object-Oriented Techniques for Microcontrollers 88
4.1 Object Oriented Programming 88
4.2 Objects and Encapsulation 93
4.3 Inheritance 94
4.4 Dynamic Polymorphism 96
4.5 The Real Overhead of Dynamic Polymorphism 97
4.6 Pure Virtual and Abstract 98
4.7 Class Relationships 99
4.8 Non-copyable Classes 101
4.9 Constant Methods 102
4.10 Static Constant Integral Members 106
4.11 Class Friends 106
4.12 Virtual Is Unavailable in the Base Class Constructor 108
References 111
5 C++ Templates for Microcontrollers 112
5.1 Template Functions 112
5.2 Template Scalability, Code Re-Use and Efficiency 114
5.3 Template Member Functions 117
5.4 Template Class Types 120
5.5 Template Default Parameters 121
5.6 Template Specialization 122
5.7 Static Polymorphism 124
5.8 Using the STL with Microcontrollers 127
5.9 Variadic Templates 129
5.10 Template Metaprogramming 131
5.11 Tuples and Generic Metaprogramming 134
5.12 Variable Templates 137
References 139
6 Optimized C++ Programming for Microcontrollers 140
6.1 Use Compiler Optimization Settings 140
6.2 Know the Microcontroller's Performance 144
6.3 Know an Algorithm's Complexity 145
6.4 Use Assembly Listings 147
6.5 Use Map Files 147
6.6 Understand Name Mangling and De-mangling 148
6.7 Know When to Use Assembly and When Not to 150
6.8 Use Comments Sparingly 151
6.9 Simplify Code with typedef and Alias 152
6.10 Use Native Integer Types 154
6.11 Use Scaling with Powers of Two 156
6.12 Potentially Replace Multiply with Shift-and-Add 157
6.13 Consider Advantageous Hardware Dimensioning 158
6.14 Consider ROM-Ability 160
6.15 Minimize the Interrupt Frame 161
6.16 Use Custom Memory Management 164
6.17 Use the STL Consistently 164
6.18 Use Lambda Expressions 166
6.19 Use Templates and Scalability 167
6.20 Use Metaprogramming to Unroll Loops 168
References 168
Part II Components for Real-Time C++ 169
7 Accessing Microcontroller Registers 170
7.1 Defining Constant Register Addresses 170
7.2 Using Templates for Register Access 172
7.3 Generic Templates for Register Access 174
7.4 Bit-Mapped Structures 177
Reference 179
8 The Right Start 180
8.1 The Startup Code 180
8.2 Initializing RAM 183
8.3 Initializing the Static Constructors 185
8.4 The Connection Between the Linker and Startup 187
8.5 Understand Static Initialization Rules 189
8.6 Avoid Using Uninitialized Objects 190
8.7 Jump to main() and Never return 192
8.8 When in main(), What Comes Next? 193
References 194
9 Low-Level Hardware Drivers in C++ 195
9.1 An I/O Port Pin Driver Template Class 195
9.2 Programming Interrupts in C++ 198
9.3 Implementing a System-Tick 202
9.4 A Software PWM Template Class 205
9.5 A Serial SPI™ Driver Class 209
9.6 CPU-Load Monitors 214
9.7 Controlling a Seven-Segment Display 216
9.8 Animating an RGB LED 222
References 228
10 Custom Memory Management 229
10.1 Dynamic Memory Considerations 229
10.2 Using Placement-new 231
10.3 Allocators and STL Containers 232
10.4 The Standard Allocator 233
10.5 Writing a Specialized ring allocator 234
10.6 Using ring allocator and Other Allocators 237
10.7 Recognizing and Handling Memory Limitations 239
References 241
11 C++ Multitasking 242
11.1 Multitasking Schedulers 242
11.2 Task Timing 244
11.3 The Task Control Block 245
11.4 The Task List 247
11.5 The Scheduler 248
11.6 Extended Multitasking 249
11.7 Preemptive Multitasking 251
11.8 The C++ Thread Support Library 252
References 253
Part III Mathematics and Utilities for Real-Time C++ 254
12 Floating-Point Mathematics 255
12.1 Floating-Point Arithmetic 255
12.2 Mathematical Constants 258
12.3 Elementary Functions 260
12.4 Special Functions 261
12.5 Complex-Valued Mathematics 271
12.6 Compile-Time Evaluation of Functions with constexpr 275
12.7 Generic Numeric Programming 279
References 286
13 Fixed-Point Mathematics 288
13.1 Fixed-Point Data Types 288
13.2 A Scalable Fixed-Point Template Class 291
13.3 Using the fixed point Class 295
13.4 Fixed-Point Elementary Transcendental Functions 297
13.5 A Specialization of std::numeric limits 308
References 310
14 High-Performance Digital Filters 311
14.1 A Floating-Point Order-1 Filter 311
14.2 An Order-1 Integer Filter 314
14.3 Order-N Integer FIR Filters 318
14.4 Some Worked-Out Filter Examples 323
References 327
15 C++ Utilities 328
15.1 The nothing Structure 328
15.2 The noncopyable Class 331
15.3 A Template timer Class 333
15.4 Linear Interpolation 336
15.5 A circular buffer Template Class 339
15.6 The Boost Library 343
References 344
16 Extending the C++ Standard Library and the STL 345
16.1 Defining the Custom dynamic array Container 345
16.2 Implementing and Using dynamic array 348
16.3 Writing Parts of the C++ Library if None is Available 352
16.4 Implementation Notes for Parts of the C++ Library and STL 352
16.5 Providing now() for < chrono>
16.6 Extended-Complex Number Templates 363
References 366
17 Using C-Language Code in C++ 367
17.1 Accessing C Language Code in C++ 367
17.2 An Existing C-Language CRC Library 368
17.3 Wrapping the C-Based CRC Library with C++ Classes 370
17.4 Return to Investigations of Efficiency and Optimization 373
References 374
18 Additional Reading 375
18.1 Literature List 375
References 377
Appendices 375
A A Tutorial for Real-Time C++ 380
A.1 C++ Cast Operators 380
A.2 Uniform Initialization Syntax 381
A.3 Overloading 383
A.4 Compile-Time Assert 384
A.5 Numeric Limits 384
A.6 STL Containers 388
A.7 STL Iterators 390
A.8 STL Algorithms 392
A.9 Lambda Expressions 396
A.10 Initializer Lists 397
A.11 Type Inference and Type Declaration with auto and decltype 398
A.12 Range-Based for(:) 399
A.13 Tuple 399
A.14 Regular Expressions 402
A.15 The < type traits>
A.16 Using std::any 406
A.17 Structured Binding Declarations 409
References 410
B A Robust Real-Time C++ Environment 411
B.1 Addressing the Challenges of Real-Time C++ 411
B.2 Software Architecture 413
B.3 Establishing and Adhering to Runtime Limits 414
References 415
C Building and Installing GNU GCC Cross Compilers 416
C.1 The GCC Prerequisites 416
C.2 Getting Started 417
C.3 Building GMP 418
C.4 Building MPFR 419
C.5 Building MPC 419
C.6 Building PPL 420
C.7 Building ISL 421
C.8 Building the Binary Utilities for the Cross Compiler 421
C.9 Building the Cross Compiler 423
C.10 Using the Cross Compiler 424
References 425
D Building a Microcontroller Circuit 426
D.1 The Circuit Schematic 426
D.2 Assembling the Circuit on a Breadboard 428
References 429
Glossary 430
Index 432

Erscheint lt. Verlag 2.5.2018
Zusatzinfo XXXIII, 426 p. 26 illus., 7 illus. in color.
Verlagsort Berlin
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Software Entwicklung
Schlagworte C++ • Embedded Systems • Low-level Programming • Microcontroller Programming • object-oriented programming • real-time programming • system performance
ISBN-10 3-662-56718-0 / 3662567180
ISBN-13 978-3-662-56718-0 / 9783662567180
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 5,1 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Das umfassende Handbuch

von Jürgen Sieben

eBook Download (2023)
Rheinwerk Computing (Verlag)
89,90
Eine kompakte Einführung

von Brendan Burns; Joe Beda; Kelsey Hightower; Lachlan Evenson

eBook Download (2023)
dpunkt (Verlag)
39,90