microbus is a small C99 event bus for embedded and host applications that want caller-owned storage, copied payload bytes, and bounded queued dispatch without heap allocation.
- Immediate publish is synchronous and deterministic.
- Deferred queue dispatch is bounded to the events present at
mbus_dispatch()entry. MBUS_TOPIC_ANYis subscribe-only.- Payload bytes are copied into the event object.
- Counter fields wrap modulo
2^32. - Default mode is single-context only.
- Optional ISR/main-loop SPSC mode is configuration-driven and requires caller-supplied critical-section hooks.
- General thread safety is not provided. Use external locking around bus operations outside the supported single-context or configured ISR mode.
#include "mbus.h" #include <stdint.h> #include <string.h> static void on_sensor(const mbus_event_t *event, void *ctx) { uint16_t millivolts = 0; (void)ctx; if (event->payload_len != sizeof(millivolts)) { return; } memcpy(&millivolts, event->payload, sizeof(millivolts)); } int main(void) { mbus_t bus; uint16_t value = 3300; int rc; rc = mbus_init(&bus, NULL); if (rc != MBUS_OK) { return 1; } rc = mbus_subscribe(&bus, MBUS_TOPIC_SENSOR, on_sensor, NULL); if (rc < 0) { return 2; } rc = mbus_publish(&bus, MBUS_TOPIC_SENSOR, &value, sizeof(value)); if (rc < 0) { return 3; } return 0; }
cmake -S . -B out/build -DMBUS_BUILD_TESTS=ON
cmake --build out/build
ctest --test-dir out/build --output-on-failuremake testThe top-level Makefile is a thin wrapper around the CMake build and honors CC, CPPFLAGS, CFLAGS, LDFLAGS, and LDLIBS.
The public configuration contract lives in mbus_config.h.
| Macro | Default | Notes |
|---|---|---|
MBUS_MAX_SUBSCRIBERS |
16 |
Must be 1..255. |
MBUS_MAX_PAYLOAD |
32 |
Must be 1..255 while payload_len stays uint8_t. |
MBUS_ENABLE_QUEUE |
1 |
Must be 0 or 1. |
MBUS_QUEUE_DEPTH |
8 |
Must be at least 1 and power-of-two when the queue is enabled. |
MBUS_ISR_SAFE_QUEUE |
0 |
Optional ISR/main-loop SPSC mode. Requires critical-section hook macros. |
Installed consumers must use the generated mbus_config.h shipped with the package rather than redefining ABI-shaping macros independently.
| Area | Status |
|---|---|
| C99 public API | Verified |
| C11 host build | Verified with GCC and Clang |
C++ consumer including mbus.h |
Verified |
| GCC host build | Verified |
| Clang host build | Verified |
| MSVC host build | Verified |
| Immediate publish | Verified |
| Queue enabled build | Verified |
| Queue disabled build | Verified |
Install + find_package(microbus CONFIG REQUIRED) consumer |
Verified |
add_subdirectory() consumer |
Verified |
| Optional ISR/main-loop SPSC mode with hooks | Implemented, not fully verified on this host |
| General multi-threaded access without external locking | Not supported |
| ARM cross-compilation | Not verified on this host |
- API reference
- Design notes
- Porting guide
- Cookbook
- Troubleshooting
- Verification log
- Contributing
- Security
MIT. See LICENSE.