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

Static packet pool implementation. More...

#include "spp/services/databank/databank.h"
#include "spp/core/returnTypes.h"
#include "spp/core/commonbit.h"
#include "spp/core/packet.h"
#include "spp/hal/time/time.h"
#include "spp/util/crc.h"
#include <string.h>
#include <stddef.h>
Include dependency graph for databank.c:

Go to the source code of this file.

Functions

SPP_RetVal_t SPP_SERVICES_DATABANK_init (void)
 Initialise the packet pool.
SPP_Packet_t * SPP_SERVICES_DATABANK_getPacket (void)
 Acquire a free packet from the pool.
SPP_RetVal_t SPP_SERVICES_DATABANK_returnPacket (SPP_Packet_t *p_packet)
 Return a packet to the pool after processing.
spp_uint32_t SPP_SERVICES_DATABANK_freeCount (void)
 Return the number of free packets currently available.
static spp_uint16_t packetCrc (const SPP_Packet_t *p_packet)
SPP_RetVal_t SPP_SERVICES_DATABANK_packetData (SPP_Packet_t *p_packet, spp_uint16_t apid, spp_uint16_t seq, const void *p_data, spp_uint16_t dataLen)
 Fill a packet with data and compute its CRC.

Variables

static SPP_Packet_t s_packets [K_SPP_DATABANK_SIZE]
 Static storage for all packets.
static SPP_Databank_t s_databank
 Control structure (free-list stack).
static spp_bool_t s_initialized = false
 Tracks whether the pool has been initialised.

Detailed Description

Static packet pool implementation.

Definition in file databank.c.

Function Documentation

◆ SPP_SERVICES_DATABANK_init()

SPP_RetVal_t SPP_SERVICES_DATABANK_init ( void )

Initialise the packet pool.

Zeroes all packets and rebuilds the free stack. Safe to call multiple times; subsequent calls are no-ops and return K_SPP_ERROR_ALREADY_INITIALIZED.

Returns
K_SPP_OK on success, K_SPP_ERROR_ALREADY_INITIALIZED if already done.

Definition at line 33 of file databank.c.

References SPP_Databank_t::freeCount, K_SPP_DATABANK_SIZE, K_SPP_ERROR_ALREADY_INITIALIZED, K_SPP_OK, SPP_Databank_t::p_freePackets, s_databank, s_initialized, s_packets, and SPP_SERVICES_DATABANK_init().

Referenced by SPP_CORE_init(), and SPP_SERVICES_DATABANK_init().

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

◆ SPP_SERVICES_DATABANK_getPacket()

SPP_Packet_t * SPP_SERVICES_DATABANK_getPacket ( void )

Acquire a free packet from the pool.

The returned packet is removed from the free list until returned via SPP_SERVICES_DATABANK_returnPacket().

Returns
Pointer to a free SPP_Packet_t, or NULL if the pool is empty.

Definition at line 53 of file databank.c.

References SPP_Databank_t::freeCount, SPP_Databank_t::p_freePackets, s_databank, s_initialized, SPP_Packet_t, and SPP_SERVICES_DATABANK_getPacket().

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

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

◆ SPP_SERVICES_DATABANK_returnPacket()

SPP_RetVal_t SPP_SERVICES_DATABANK_returnPacket ( SPP_Packet_t * p_packet)

Return a packet to the pool after processing.

Parameters
[in]p_packetPointer previously returned by SPP_SERVICES_DATABANK_getPacket().
Returns
K_SPP_OK on success.
K_SPP_ERROR_NULL_POINTER if p_packet is NULL.
K_SPP_ERROR if p_packet is not a valid pool address (double-return guard).
K_SPP_ERROR_ALREADY_INITIALIZED if the packet is already in the free list.

Definition at line 64 of file databank.c.

References SPP_Databank_t::freeCount, K_SPP_DATABANK_SIZE, K_SPP_ERROR, K_SPP_ERROR_ALREADY_INITIALIZED, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, SPP_Databank_t::p_freePackets, s_databank, s_packets, SPP_Packet_t, and SPP_SERVICES_DATABANK_returnPacket().

Referenced by SPP_SERVICES_BMP390_acquireData(), SPP_SERVICES_BMP390_DUMMY_acquireData(), SPP_SERVICES_DATABANK_returnPacket(), 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_DATABANK_freeCount()

spp_uint32_t SPP_SERVICES_DATABANK_freeCount ( void )

Return the number of free packets currently available.

Returns
Free packet count (0 … K_SPP_DATABANK_SIZE).

Definition at line 96 of file databank.c.

References SPP_Databank_t::freeCount, s_databank, and SPP_SERVICES_DATABANK_freeCount().

Referenced by SPP_SERVICES_DATABANK_freeCount().

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

◆ packetCrc()

spp_uint16_t packetCrc ( const SPP_Packet_t * p_packet)
static

Definition at line 105 of file databank.c.

References packetCrc(), SPP_Packet_t, and SPP_UTIL_crc16().

Referenced by packetCrc(), and SPP_SERVICES_DATABANK_packetData().

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

◆ SPP_SERVICES_DATABANK_packetData()

SPP_RetVal_t SPP_SERVICES_DATABANK_packetData ( SPP_Packet_t * p_packet,
spp_uint16_t apid,
spp_uint16_t seq,
const void * p_data,
spp_uint16_t dataLen )

Fill a packet with data and compute its CRC.

Zeroes the entire packet (including any struct padding), writes all header fields, copies p_data into the payload, and computes a CRC-16/CCITT checksum over every byte of the packet except the crc field itself.

The timestamp is captured automatically via SPP_HAL_TIME_getTimeMs().

Parameters
[out]p_packetPacket previously acquired from SPP_SERVICES_DATABANK_getPacket().
[in]apidApplication Process Identifier.
[in]seqPacket sequence counter (maintained by the caller).
[in]p_dataPointer to the payload data to copy.
[in]dataLenNumber of bytes to copy (must be ≤ K_SPP_PKT_PAYLOAD_MAX).
Returns
K_SPP_OK on success.
K_SPP_ERROR_NULL_POINTER if p_packet or p_data is NULL.
K_SPP_ERROR_INVALID_PARAMETER if dataLen exceeds K_SPP_PKT_PAYLOAD_MAX.

Definition at line 117 of file databank.c.

References K_SPP_ERROR_INVALID_PARAMETER, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, K_SPP_PKT_PAYLOAD_MAX, K_SPP_PKT_VERSION, packetCrc(), SPP_HAL_TIME_getTimeMs(), SPP_Packet_t, and SPP_SERVICES_DATABANK_packetData().

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

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

Variable Documentation

◆ s_packets

SPP_Packet_t s_packets[K_SPP_DATABANK_SIZE]
static

Static storage for all packets.

Definition at line 21 of file databank.c.

Referenced by SPP_SERVICES_DATABANK_init(), and SPP_SERVICES_DATABANK_returnPacket().

◆ s_databank

SPP_Databank_t s_databank
static

◆ s_initialized

spp_bool_t s_initialized = false
static

Tracks whether the pool has been initialised.

Definition at line 27 of file databank.c.

Referenced by SPP_SERVICES_DATABANK_getPacket(), and SPP_SERVICES_DATABANK_init().