Reusable C Software (RCSW) Library#
RCSW is a C11 library of building blocks (data structures, algorithms, synchronization, logging, and the small runtime pieces an embedded project ends up writing for itself) that runs everywhere from a bare-metal bootloader with no heap and no libc to a multithreaded Linux application.
Its defining feature is that you decide where the memory comes from. Every
module that owns memory can take its handle, its element storage, and its
bookkeeping from the caller instead of malloc(), independently. The same
linked list, hashmap, or memory pool code works with a heap on Linux and
entirely from static buffers on a microcontroller.
Quickstart Example shows a linked list that never touches the heap.
Features#
No heap required. Pass
RCSW_NOALLOC_HANDLE,RCSW_NOALLOC_DATAand/orRCSW_NOALLOC_METAto supply memory yourself, or build withRCSW_CONFIG_NOALLOCto forbid allocation library-wide. Sizing functions (xx_element_space(),xx_meta_space()) tell you how much to reserve. A few parts always need a heap;RCSW_CONFIG_NOALLOClists them. See Memory Model.Bare metal and POSIX from one codebase. The core, data structures, algorithms, utilities, logging, and a
printf()replacement work without an OS; threading, process management, and the software bus are added on POSIX. See Components.Alignment handled for you. Caller buffers are declared as
dptr_tarrays, aligned toRCSW_CONFIG_PTR_ALIGNfor the target, so stored structs don’t fault on cores that trap on misaligned access. See Memory Model.Configurable argument checking. Public functions validate their arguments with precondition checks that, chosen at build time, return an error with
errno = EINVAL,assert(), or compile out entirely. See Function preconditions.Pluggable logging. One set of macros (
ER_DEBUG,ER_WARN, …) with per-module control, compile-time level filtering that removes disabled statements entirely, and a choice of backend: the built-in LOG4CL or simple plugins, zlog, or your own. See Event Reporting and Event Reporting (ER).Tested. Every module has unit tests (Catch2), run in CI under AddressSanitizer, with coverage tracked. The tests double as usage examples.
Components#
RCSW is split into components, roughly one per directory under
include/rcsw. Which ones are built depends on
RCSW_BUILD_FOR; how they depend on each other is covered in
Components and Linking.
Component |
Contents |
|
|
|---|---|---|---|
Ringbuffer, FIFO, multi-FIFO, lock-free single-producer/consumer raw FIFO, linked list, dynamic array, hashmap, binary heap, binary search tree (plain, red-black, order-statistic, interval), static/dynamic/ adjacency matrices, iterators. |
✓ |
✓ |
|
Binary search, quicksort, insertion sort, radix sort, edit distance, longest common subsequence, matrix-chain ordering. |
✓ |
✓ |
|
Checksums (XOR, additive, CRC-32), hashes (FNV-1a, Jenkins, DJB2),
bit and byte manipulation, register/memory access and hex dumps,
|
✓ |
✓ (except time utilities) |
|
|
✓ (optional; disable with |
✓ (primary use case) |
|
Event reporting (logging) front end and plugins. |
✓ (all plugins) |
✓ ( |
|
Mutex, condition variable, binary and counting semaphores, fair reader/writer lock, reference-counted memory pool, producer-consumer queue, thread-to-core pinning. |
✓ |
✗ (requires POSIX threads) |
|
|
✓ (socket pinning: Linux only) |
✗ |
|
Publish-subscribe software bus with zero-copy publishing. |
✓ |
✗ (requires multithread) |
|
Minimon, an interactive serial monitor for board bring-up: read and write memory, load and send data, jump, plus your own commands. |
Built for testing only |
✓ (intended target) |
|
Grind, lightweight timing and execution-count instrumentation. |
✓ |
✗ (requires POSIX) |
|
Build provenance, version, and license information. |
✓ |
✓ |
Core (core) and Abstraction Layer (al) (status codes, allocation, flags, compiler helpers, and the platform abstraction layer) underlie every component and are documented in the API reference only.
Documentation#
Linking RCSW into your project, building it, and every build option. |
|
The memory model, error handling, components and linking, event reporting, data structure conventions, and concurrency. Read these first; the rest of the documentation assumes them. |
|
A guide to each component: what it’s for, how to use it, and its caveats. |
|
Generated from the headers. |