Time Points and Intervals

Embedded applications handle events and control processes happening in the physical world—that is why the correct handling of time and delays is crucial for them. Switching traffic lights; generation of sound tones; synchronization of data from multiple sensors—all these tasks rely on proper time measurements.

Plain C does not provide any standard functions to work with time. It is expected that application developers will use a time API specific for the target operating system—Windows, Linux, or macOS. For bare-metal embedded systems, developers have to create custom functions to work with time, based on a low-level timer API specific for the target platform. As a result, the code is hard to port to other platforms. 

To overcome the portability issue, C++ (starting with C++11) defines data types and functions to work with time and time intervals. This API, referenced as an std::chrono library, helps developers work with time in a uniform way in any environment and on any target platform. 

In this chapter, we will learn how to work with timestamps, time intervals, and delays in our applications. We will discuss some of the common pitfalls related to time management, along with the proper workarounds for them.

We will cover the following topics:

  • Exploring the C++ Chrono library
  • Measuring time intervals
  • Working with delays
  • Using the monotonic clock
  • Using Portable Operating System Interface (POSIX) timestamps

Using these recipes, you will be able to write portable code for time handling that works on any embedded platform.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.1.136