Solaris Software
Loading...
Searching...
No Matches
pubsub.c File Reference

Priority-aware publish-subscribe packet router implementation. More...

Include dependency graph for pubsub.c:

Go to the source code of this file.

Data Structures

struct  SPP_SERVICES_PUBSUB_Producer_t
struct  SPP_SERVICES_PUBSUB_Consumer_t

Functions

static void SPP_SERVICES_PUBSUB_sendToMailbox (void)
 Copies each buffered packet to every consumer whose APID subscription matches, then resets the internal FIFO (head, tail and count back to zero).
static void SPP_SERVICES_PUBSUB_sortConsumers (void)
 Sorts the registered consumer array in ascending priority order using insertion sort. Stable — consumers with equal priority retain their registration order. Called once during init before any dispatch.
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer (const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_Kpid_t *p_assignedKpid)
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerConsumer (const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_Kpid_t subscription)
void SPP_SERVICES_PUBSUB_callProducers (void)
 Calls acquireData on every registered producer.
SPP_RetVal_t SPP_SERVICES_PUBSUB_publish (SPP_Packet_t *p_pkt)
 Copies a packet into the internal buffer and returns it to the databank.
void SPP_SERVICES_PUBSUB_callConsumers (void)
 Routes all buffered packets to matching consumer mailboxes, then clears the buffer.
spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth (void)
 Returns the number of packets currently held in the internal FIFO buffer.
void SPP_SERVICES_PUBSUB_signalProducerReady (void)
 Signals that a producer has new data pending.
SPP_RetVal_t SPP_SERVICES_PUBSUB_init (void)
SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult (const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_RetVal_t *p_initResult)
SPP_RetVal_t SPP_SERVICES_PUBSUB_getConsumerInitResult (const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_RetVal_t *p_initResult)

Variables

static SPP_SERVICES_PUBSUB_Producer_t s_producers [K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS] = {0}
static spp_uint16_t s_registeredProducers = 0U
static SPP_SERVICES_PUBSUB_Consumer_t s_consumers [K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS] = {0}
static spp_uint8_t s_registeredConsumers = 0U
static SPP_Packet_t s_packetBuffer [K_SPP_SERVICES_PUBSUB_BUFFER_SIZE]
static spp_uint8_t s_bufferHead = 0U
static spp_uint8_t s_bufferTail = 0U
static spp_uint8_t s_bufferCount = 0U
static volatile spp_bool_t s_producerReady = false

Detailed Description

Priority-aware publish-subscribe packet router implementation.

Definition in file pubsub.c.

Function Documentation

◆ SPP_SERVICES_PUBSUB_sendToMailbox()

void SPP_SERVICES_PUBSUB_sendToMailbox ( void )
static

Copies each buffered packet to every consumer whose APID subscription matches, then resets the internal FIFO (head, tail and count back to zero).

Iterates the circular packet buffer from head to head+count. For each packet it walks the registered consumer list and performs a bitmask check on suscribeToApid vs primaryHeader.apid. On a match the full SPP_Packet_t is copied by value into the consumer's p_mailBox. When all consumers have been served the buffer is cleared.

Definition at line 271 of file pubsub.c.

References K_SPP_SERVICES_PUBSUB_BUFFER_SIZE, K_SPP_SERVICES_PUBSUB_STEP, s_bufferCount, s_bufferHead, s_consumers, s_packetBuffer, s_registeredConsumers, SPP_Packet_t, and SPP_SERVICES_PUBSUB_sendToMailbox().

Referenced by SPP_SERVICES_PUBSUB_callConsumers(), and SPP_SERVICES_PUBSUB_sendToMailbox().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_sortConsumers()

void SPP_SERVICES_PUBSUB_sortConsumers ( void )
static

Sorts the registered consumer array in ascending priority order using insertion sort. Stable — consumers with equal priority retain their registration order. Called once during init before any dispatch.

Definition at line 300 of file pubsub.c.

References K_SPP_SERVICES_PUBSUB_OFFSET, K_SPP_SERVICES_PUBSUB_SORT_START_INDEX, K_SPP_SERVICES_PUBSUB_ZERO_INDEX, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, SPP_SERVICE_ConsumerContract_t::priority, s_consumers, s_registeredConsumers, and SPP_SERVICES_PUBSUB_sortConsumers().

Referenced by SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_sortConsumers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_registerProducer()

SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer ( const SPP_SERVICE_ProducerContract_t * p_producerData,
SPP_Kpid_t * p_assignedKpid )

Definition at line 58 of file pubsub.c.

References SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NOT_INITIALIZED, K_SPP_ERROR_NULL_POINTER, K_SPP_ERROR_REGISTRY_FULL, K_SPP_OK, K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS, SPP_SERVICES_PUBSUB_Producer_t::kpid, SPP_SERVICES_PUBSUB_Producer_t::p_contract, s_producers, s_registeredProducers, SPP_SERVICES_PUBSUB_registerProducer(), and SPP_Kpid_t::value.

Referenced by CUSTOM_registerConsumerProducer(), and SPP_SERVICES_PUBSUB_registerProducer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_registerConsumer()

SPP_RetVal_t SPP_SERVICES_PUBSUB_registerConsumer ( const SPP_SERVICE_ConsumerContract_t * p_consumerData,
SPP_Kpid_t subscription )

Definition at line 94 of file pubsub.c.

References SPP_SERVICES_PUBSUB_Consumer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NOT_INITIALIZED, K_SPP_ERROR_NULL_POINTER, K_SPP_ERROR_REGISTRY_FULL, K_SPP_OK, K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, s_consumers, s_registeredConsumers, SPP_SERVICES_PUBSUB_registerConsumer(), and SPP_SERVICES_PUBSUB_Consumer_t::subcription.

Referenced by SPP_SERVICES_PUBSUB_registerConsumer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_callProducers()

void SPP_SERVICES_PUBSUB_callProducers ( void )

Calls acquireData on every registered producer.

Definition at line 119 of file pubsub.c.

References SPP_SERVICES_PUBSUB_Producer_t::kpid, s_producerReady, s_producers, s_registeredProducers, and SPP_SERVICES_PUBSUB_callProducers().

Referenced by SPP_SERVICES_PUBSUB_callProducers(), and statefunction_bmpPerformanceLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_publish()

SPP_RetVal_t SPP_SERVICES_PUBSUB_publish ( SPP_Packet_t * p_pkt)

Copies a packet into the internal buffer and returns it to the databank.

Called by producers after filling a packet. The packet is copied by value into the next free slot of the internal circular buffer; the original is returned to the databank pool immediately. Returns K_SPP_ERROR if the buffer is full (packet is still returned to the pool).

Parameters
p_pktPacket to publish (ownership transferred — do not use after this call).
Returns
K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if p_pkt is NULL, K_SPP_ERROR if the buffer is full.

Definition at line 128 of file pubsub.c.

References K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, K_SPP_SERVICES_PUBSUB_BUFFER_SIZE, K_SPP_SERVICES_PUBSUB_STEP, s_bufferCount, s_bufferTail, s_packetBuffer, SPP_Packet_t, SPP_SERVICES_DATABANK_returnPacket(), and SPP_SERVICES_PUBSUB_publish().

Referenced by action_emitTelemetry(), SPP_SERVICES_BMP390_acquireData(), SPP_SERVICES_BMP390_DUMMY_acquireData(), SPP_SERVICES_ICM20948_acquireData(), and SPP_SERVICES_PUBSUB_publish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_callConsumers()

void SPP_SERVICES_PUBSUB_callConsumers ( void )

Routes all buffered packets to matching consumer mailboxes, then clears the buffer.

Definition at line 152 of file pubsub.c.

References K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY, s_consumers, s_producerReady, s_registeredConsumers, SPP_SERVICES_PUBSUB_callConsumers(), and SPP_SERVICES_PUBSUB_sendToMailbox().

Referenced by SPP_SERVICES_PUBSUB_callConsumers(), and statefunction_bmpPerformanceLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_queueDepth()

spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth ( void )

Returns the number of packets currently held in the internal FIFO buffer.

Definition at line 172 of file pubsub.c.

References s_bufferCount, and SPP_SERVICES_PUBSUB_queueDepth().

Referenced by SPP_SERVICES_PUBSUB_queueDepth(), and statefunction_bmpPerformanceLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_signalProducerReady()

void SPP_SERVICES_PUBSUB_signalProducerReady ( void )

Signals that a producer has new data pending.

Must be called from within acquireData() as soon as a DRDY flag is detected, so that callConsumers() can preempt consumers with priority > K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY.

Definition at line 177 of file pubsub.c.

References s_producerReady, and SPP_SERVICES_PUBSUB_signalProducerReady().

Referenced by SPP_SERVICES_PUBSUB_signalProducerReady().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_init()

SPP_RetVal_t SPP_SERVICES_PUBSUB_init ( void )

Definition at line 182 of file pubsub.c.

References SPP_SERVICE_ConsumerContract_t::init, SPP_SERVICE_ProducerContract_t::init, SPP_SERVICES_PUBSUB_Consumer_t::initResult, SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_OK, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, SPP_SERVICES_PUBSUB_Producer_t::p_contract, s_consumers, s_producers, s_registeredConsumers, s_registeredProducers, SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_sortConsumers().

Referenced by SPP_CORE_init(), and SPP_SERVICES_PUBSUB_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_getProducerInitResult()

SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult ( const SPP_SERVICE_ProducerContract_t * p_producerData,
SPP_RetVal_t * p_initResult )

Definition at line 220 of file pubsub.c.

References SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_producers, s_registeredProducers, and SPP_SERVICES_PUBSUB_getProducerInitResult().

Referenced by CUSTOM_initCheck(), and SPP_SERVICES_PUBSUB_getProducerInitResult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_SERVICES_PUBSUB_getConsumerInitResult()

SPP_RetVal_t SPP_SERVICES_PUBSUB_getConsumerInitResult ( const SPP_SERVICE_ConsumerContract_t * p_consumerData,
SPP_RetVal_t * p_initResult )

Definition at line 239 of file pubsub.c.

References SPP_SERVICES_PUBSUB_Consumer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_consumers, s_registeredConsumers, and SPP_SERVICES_PUBSUB_getConsumerInitResult().

Referenced by SPP_SERVICES_PUBSUB_getConsumerInitResult().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ s_producers

◆ s_registeredProducers

◆ s_consumers

◆ s_registeredConsumers

◆ s_packetBuffer

◆ s_bufferHead

spp_uint8_t s_bufferHead = 0U
static

Definition at line 42 of file pubsub.c.

Referenced by SPP_SERVICES_PUBSUB_sendToMailbox().

◆ s_bufferTail

spp_uint8_t s_bufferTail = 0U
static

Definition at line 43 of file pubsub.c.

Referenced by SPP_SERVICES_PUBSUB_publish().

◆ s_bufferCount

spp_uint8_t s_bufferCount = 0U
static

◆ s_producerReady

volatile spp_bool_t s_producerReady = false
static