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_DATA and/or RCSW_NOALLOC_META to supply memory yourself, or build with RCSW_CONFIG_NOALLOC to 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_NOALLOC lists 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_t arrays, aligned to RCSW_CONFIG_PTR_ALIGN for 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

POSIX

BAREMETAL

Data Structures

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.

✓

✓

Algorithms

Binary search, quicksort, insertion sort, radix sort, edit distance, longest common subsequence, matrix-chain ordering.

✓

✓

Utils

Checksums (XOR, additive, CRC-32), hashes (FNV-1a, Jenkins, DJB2), bit and byte manipulation, register/memory access and hex dumps, timespec arithmetic.

✓

✓ (except time utilities)

Standard I/O (STDIO)

printf() family, string and memory routines, number conversions: enough to print from a bootloader with no libc.

✓ (optional; disable with RCSW_CONFIG_NO_STDIO)

✓ (primary use case)

Event Reporting (ER)

Event reporting (logging) front end and plugins.

✓ (all plugins)

✓ (simple plugin only without libc)

Multithread

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)

Multiprocess

fork()/exec() helper, socket (CPU package) pinning.

✓ (socket pinning: Linux only)

✗

Software Bus (SWBUS)

Publish-subscribe software bus with zero-copy publishing.

✓

✗ (requires multithread)

Console

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)

Tools (tool)

Grind, lightweight timing and execution-count instrumentation.

✓

✗ (requires POSIX)

Version (version)

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#

Using RCSW

Linking RCSW into your project, building it, and every build option.

Concepts

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.

Library

A guide to each component: what it’s for, how to use it, and its caveats.

API Reference

Generated from the headers.