DEV Community

NCMV
NCMV

Posted on

CASTLE – A modern C++ template library for safety-critical embedded systems

https://github.com/nguyenchiemminhvu/castle

I’ve been working on CASTLE — Common Automotive Safety-critical Template Library for Embedded engineers.

The name is intentional: the library was originally motivated by a simple goal — building small, predictable C++ building blocks for automotive and other safety-critical embedded systems.

CASTLE is a prototype C++17, header-only library built around a few embedded-friendly constraints:

  • no heap allocation
  • no exceptions or RTTI
  • fixed-capacity, statically bounded data structures
  • predictable resource usage
  • compile-time configuration where practical
  • lightweight, composable components

It currently includes fixed-capacity buffers, callbacks, event and signal dispatching, timers, logging, iterators, bit utilities, safe numeric casts, and other small utilities.

CASTLE was inspired by the Embedded Template Library (ETL), but takes a somewhat different approach, focusing on a more modern C++ coding style and more expressive APIs. In particular, I’m exploring more convenient ways to build event-driven embedded software while keeping memory usage bounded and behaviour predictable.

This is still a prototype, so I’m sharing it mainly to get feedback from people working with embedded C++, automotive software, or safety-critical systems.

Planned additions include fixed-capacity containers, finite state machines, protocol I/O, encoders/decoders, CRC and checksum algorithms, and more compile-time configuration for event-driven systems...

I’d particularly like to hear where you think this approach makes sense, where it doesn’t, and what would make CASTLE more useful in a real embedded project.

Top comments (0)