|
ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
|
ICARUS OS — Lightweight Software Bus (pub/sub message router) More...
#include <stdint.h>#include <stdbool.h>Go to the source code of this file.
Macros | |
| #define | SB_MAX_ROUTES 32 |
| Maximum number of distinct message IDs that can have subscriptions. | |
| #define | SB_MAX_SUBS_PER_MSG 4 |
| Maximum subscribers per message ID. | |
Typedefs | |
| typedef uint16_t | sb_msg_id_t |
| Software Bus message identifier. | |
Functions | |
| void | sb_init (void) |
| Initialize the software bus. | |
| bool | sb_subscribe (sb_msg_id_t msg_id, uint8_t pipe_idx) |
| Subscribe a pipe to a message ID. | |
| bool | sb_unsubscribe (sb_msg_id_t msg_id, uint8_t pipe_idx) |
| Remove a subscription. | |
| uint8_t | sb_publish (sb_msg_id_t msg_id, const uint8_t *data, uint8_t len) |
Publish a message to all subscribers of msg_id. | |
| uint8_t | sb_subscriber_count (sb_msg_id_t msg_id) |
| Return the number of active subscriptions for a message ID. | |
| uint8_t | sb_route_count (void) |
| Return the total number of route entries in use. | |
| void | __sb_init (void) |
| Privileged implementation of sb_init(). | |
| bool | __sb_subscribe (sb_msg_id_t msg_id, uint8_t pipe_idx) |
| Privileged implementation of sb_subscribe(). | |
| bool | __sb_unsubscribe (sb_msg_id_t msg_id, uint8_t pipe_idx) |
| Privileged implementation of sb_unsubscribe(). | |
| uint8_t | __sb_publish (sb_msg_id_t msg_id, const uint8_t *data, uint8_t len) |
| Privileged implementation of sb_publish(). | |
| uint8_t | __sb_subscriber_count (sb_msg_id_t msg_id) |
| Privileged implementation of sb_subscriber_count(). | |
| uint8_t | __sb_route_count (void) |
| Privileged implementation of sb_route_count(). | |
ICARUS OS — Lightweight Software Bus (pub/sub message router)
A thin publish/subscribe routing layer on top of the kernel pipe IPC. Tasks subscribe to message IDs; publishers push messages by ID and the bus copies the payload into every subscriber's pipe automatically.
Design constraints:
Definition in file sb.h.
| typedef uint16_t sb_msg_id_t |
| void __sb_init | ( | void | ) |
Privileged implementation of sb_init().
Zeroes the entire route table and resets the used counter.
Definition at line 93 of file sb.c.
References route_used, and routes.
Referenced by sb_init(), and SVC_Handler_C().
| uint8_t __sb_publish | ( | sb_msg_id_t | msg_id, |
| const uint8_t * | data, | ||
| uint8_t | len | ||
| ) |
Privileged implementation of sb_publish().
| [in] | msg_id | Message identifier. |
| [in] | data | Payload bytes. |
| [in] | len | Payload length. |
Iterates all subscribers for msg_id. For each pipe, checks capacity via pipe_can_enqueue() before writing. Pipes that are full are silently skipped (best-effort).
Definition at line 173 of file sb.c.
References __pipe_can_enqueue(), __pipe_write_bytes(), sb_route_t::count, find_route(), and sb_route_t::pipes.
Referenced by sb_publish(), and SVC_Handler_C().
| uint8_t __sb_route_count | ( | void | ) |
Privileged implementation of sb_route_count().
Definition at line 209 of file sb.c.
References route_used.
Referenced by sb_route_count(), and SVC_Handler_C().
| bool __sb_subscribe | ( | sb_msg_id_t | msg_id, |
| uint8_t | pipe_idx | ||
| ) |
Privileged implementation of sb_subscribe().
| [in] | msg_id | Message identifier. |
| [in] | pipe_idx | Kernel pipe index to bind. |
| true | Subscription added. |
| false | Table full, subscriber limit hit, or duplicate pair. |
If no route exists for msg_id a new slot is allocated. Duplicate (msg_id, pipe_idx) pairs are rejected to prevent double-delivery.
Definition at line 110 of file sb.c.
References alloc_route(), sb_route_t::count, find_route(), sb_route_t::msg_id, sb_route_t::pipes, and SB_MAX_SUBS_PER_MSG.
Referenced by sb_subscribe(), and SVC_Handler_C().
| uint8_t __sb_subscriber_count | ( | sb_msg_id_t | msg_id | ) |
Privileged implementation of sb_subscriber_count().
| [in] | msg_id | Message identifier. |
Definition at line 200 of file sb.c.
References sb_route_t::count, and find_route().
Referenced by sb_subscriber_count(), and SVC_Handler_C().
| bool __sb_unsubscribe | ( | sb_msg_id_t | msg_id, |
| uint8_t | pipe_idx | ||
| ) |
Privileged implementation of sb_unsubscribe().
| [in] | msg_id | Message identifier. |
| [in] | pipe_idx | Pipe to remove. |
| true | Subscription found and removed (last-swap compaction). |
| false | No matching subscription. |
Definition at line 144 of file sb.c.
References sb_route_t::count, find_route(), and sb_route_t::pipes.
Referenced by sb_unsubscribe(), and SVC_Handler_C().
| void sb_init | ( | void | ) |
Initialize the software bus.
Clears all routes.
Initialize the software bus.
Clears all routes in privileged mode.
Definition at line 221 of file sb.c.
References __sb_init(), and SVC_SB_INIT.
| uint8_t sb_publish | ( | sb_msg_id_t | msg_id, |
| const uint8_t * | data, | ||
| uint8_t | len | ||
| ) |
Publish a message to all subscribers of msg_id.
| [in] | msg_id | Message identifier. |
| [in] | data | Payload bytes (must not be NULL when len > 0). |
| [in] | len | Payload length in bytes. |
Publish a message to all subscribers of msg_id.
| [in] | msg_id | Message identifier. |
| [in] | data | Payload bytes. |
| [in] | len | Payload length. |
Definition at line 288 of file sb.c.
References __sb_publish(), and SVC_SB_PUBLISH.
| uint8_t sb_route_count | ( | void | ) |
Return the total number of route entries in use.
Return the total number of route entries in use.
Definition at line 334 of file sb.c.
References __sb_route_count(), and SVC_SB_ROUTE_COUNT.
| bool sb_subscribe | ( | sb_msg_id_t | msg_id, |
| uint8_t | pipe_idx | ||
| ) |
Subscribe a pipe to a message ID.
| [in] | msg_id | Message identifier to subscribe to. |
| [in] | pipe_idx | Kernel pipe index that will receive copies of published messages with this ID. The pipe must already be initialized via pipe_init(). |
| true | Subscription added successfully. |
| false | Route table full, subscriber limit reached for this msg_id, or duplicate (msg_id, pipe_idx) pair. |
Subscribe a pipe to a message ID.
| [in] | msg_id | Message identifier. |
| [in] | pipe_idx | Kernel pipe index. |
| true | Subscription added. |
| false | Table full, limit hit, or duplicate. |
Definition at line 236 of file sb.c.
References __sb_subscribe(), and SVC_SB_SUBSCRIBE.
| uint8_t sb_subscriber_count | ( | sb_msg_id_t | msg_id | ) |
Return the number of active subscriptions for a message ID.
| [in] | msg_id | Message identifier. |
Return the number of active subscriptions for a message ID.
| [in] | msg_id | Message identifier. |
Definition at line 313 of file sb.c.
References __sb_subscriber_count(), and SVC_SB_SUBSCRIBER_COUNT.
| bool sb_unsubscribe | ( | sb_msg_id_t | msg_id, |
| uint8_t | pipe_idx | ||
| ) |
Remove a subscription.
| [in] | msg_id | Message identifier. |
| [in] | pipe_idx | Pipe to unsubscribe. |
| true | Subscription found and removed. |
| false | No matching subscription exists. |
Remove a subscription.
| [in] | msg_id | Message identifier. |
| [in] | pipe_idx | Pipe to unsubscribe. |
| true | Subscription found and removed. |
| false | No matching subscription. |
Definition at line 262 of file sb.c.
References __sb_unsubscribe(), and SVC_SB_UNSUBSCRIBE.