Handling a Family of Hardware Devices with a Single Implementation – Ben Saks – CppCon 2021

https://cppcon.org/
https://github.com/CppCon/CppCon2020
---

Embedded software typically uses memory-mapped registers to communicate with hardware. These registers are often finicky and demanding. Software that accesses a hardware register in the wrong way often produces bugs that are hard to diagnose and fix. In this session, we’ll look at ways to use operator overloading, enumeration types, and other C++ features to craft interfaces that protect against such misuses. We’ll then look at techniques for generalizing that code so that one implementation works for many variations of the hardware.

Using real-world examples of 8-bit and 16-bit hardware timers, we’ll begin by constructing a safe interface for a specific hardware timer. From there, we’ll use templates to generalize the implementation to cover more timer variations. By isolating and extracting the differences between the timers, we’ll minimize the need for code duplication. We’ll also be able to write application code that works equally well with any of the timers. Along the way, we’ll deal with smaller problems, such as dealing with non-contiguous register layouts and guaranteeing that large values are locked during accesses.

This session uses concrete examples of timers in the ARM7 and Arduino MEGA 2560 architectures. However, the techniques from this session apply to a wide variety of platforms and hardware devices such as serial ports or I/O pins.

---

Ben Saks
Chief Engineer, Saks & Associates

---

Videos Streamed & Edited by Digital Medium: http://online.digital-medium.co.uk

The CppCon YouTube Channel Is Sponsored By:
JetBrains : http://jb.gg/cpptools
SonarSource: https://www.sonarsource.com/

Filed under: Science & Technology

No comment yet, add your voice below!


Add a Comment