Event Bus

group Event Bus

Generic Publish/Subscribe Mechanism.

Variables

osusat_event_id_t id

Composite Event ID

uint8_t payload[OSUSAT_EVENT_MAX_PAYLOAD]

Data copy

uint8_t payload_len

Valid bytes in payload

group Structures

Structures used by the Event Bus.

Defines

OSUSAT_EVENT_MAX_PAYLOAD

Max payload size in bytes. Kept small (8 bytes) to fit primitives (double, uint64_t) or pointers.

OSUSAT_EVENT_MAX_SUBSCRIBERS

Maximum number of active subscriptions allowed system-wide. Adjust based on RAM constraints.

OSUSAT_BUILD_EVENT_ID(svc_uid, code)

Helper to build a unique ID from a Service UID and Local Code.

Parameters:
  • svc_uid – Unique 16-bit Service Identifier (e.g. 0xBA77 for Batt).

  • code – Local enum value (0-65535).

OSUSAT_GET_SERVICE_UID(event_id)

Helper to extract the Service UID from an Event ID.

OSUSAT_GET_LOCAL_CODE(event_id)

Helper to extract the Local Code from an Event ID.

OSUSAT_SERVICE_UID_SYSTEM

Reserved UID for Core System Events.

EVENT_SYSTICK
EVENT_SYSTEM_INIT

Typedefs

typedef uint32_t osusat_event_id_t

Event Identifier Type (32-bit).

Constructed using OSUSAT_BUILD_EVENT_ID().

typedef void (*osusat_event_handler_t)(const osusat_event_t *event, void *ctx)

Event Handler Callback definition.

Param event:

[in] Pointer to the event data.

Param ctx:

[in] User context pointer registered during subscription.

Enums

enum osusat_system_code_t

System Event Codes.

Values:

enumerator SYSTEM_SYSTICK

Periodic heartbeat (e.g. 100Hz)

enumerator SYSTEM_INIT_DONE

All services initialized

enumerator SYSTEM_HEARTBEAT

Heartbeat event for health monitoring

struct osusat_event_t
#include <event_bus.h>

The event object stored in the queue.

group Public API

External interface for interacting with the Event Bus.

Functions

void osusat_event_bus_init(osusat_event_t *queue_storage, size_t queue_capacity)

Initialize the Event Bus.

Configures the internal ring buffer and clears subscribers.

Parameters:
  • queue_storage[in] Pointer to allocated array of event structs.

  • queue_capacity[in] Number of elements in the storage array.

bool osusat_event_bus_subscribe(osusat_event_id_t event_id, osusat_event_handler_t handler, void *ctx)

Subscribe to an event.

Registers a callback to be invoked when the specific Event ID occurs.

Parameters:
  • event_id[in] The Composite ID to listen for.

  • handler[in] The function to call.

  • ctx[in] Optional context pointer passed to the handler.

Return values:
  • true – Subscription added successfully.

  • false – Subscriber table full (increase OSUSAT_EVENT_MAX_SUBSCRIBERS).

bool osusat_event_bus_publish(osusat_event_id_t event_id, const void *payload, size_t len)

Publish an event to the bus.

Copies the event data into the queue. Safe to call from ISRs.

Parameters:
  • event_id[in] The Composite ID of the event.

  • payload[in] Pointer to data to copy (can be NULL).

  • len[in] Length of data (must be <= OSUSAT_EVENT_MAX_PAYLOAD).

Return values:
  • true – Event queued successfully.

  • false – Queue full (Event Dropped!).

void osusat_event_bus_process(void)

Process the Event Queue.

Pops all pending events and executes their subscribers.

Warning

Must be called from the main loop (Thread Mode).