Book Image

Embedded Programming with Modern C++ Cookbook

By : Igor Viarheichyk
Book Image

Embedded Programming with Modern C++ Cookbook

By: Igor Viarheichyk

Overview of this book

Developing applications for embedded systems may seem like a daunting task as developers face challenges related to limited memory, high power consumption, and maintaining real-time responses. This book is a collection of practical examples to explain how to develop applications for embedded boards and overcome the challenges that you may encounter while developing. The book will start with an introduction to embedded systems and how to set up the development environment. By teaching you to build your first embedded application, the book will help you progress from the basics to more complex concepts, such as debugging, logging, and profiling. Moving ahead, you will learn how to use specialized memory and custom allocators. From here, you will delve into recipes that will teach you how to work with the C++ memory model, atomic variables, and synchronization. The book will then take you through recipes on inter-process communication, data serialization, and timers. Finally, you will cover topics such as error handling and guidelines for real-time systems and safety-critical systems. By the end of this book, you will have become proficient in building robust and secure embedded applications with C++.
Table of Contents (17 chapters)

Working with watchdogs

Embedded applications are built to work without supervision. This includes the ability to recover from errors. If an application crashes, it can be restarted automatically. But what should we do if an application hangs by entering an endless loop or due to a deadlock?

Hardware or software watchdogs are used to prevent such situations. Applications should periodically notify or feed them to indicate that they keep operating normally. If a watchdog is not fed within a specific time interval, it terminates an application or restarts the system. 

Many different implementations of watchdogs exist, but their interfaces are essentially the same. They provide a function that applications can use to reset the watchdog timer.

In this recipe, we will learn how to create a simple software watchdog on top of POSIX signals subsystems. The same technique can be used...