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>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. | |
Static packet pool implementation.
Definition in file databank.c.
| 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.
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().
| 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().
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().
| SPP_RetVal_t SPP_SERVICES_DATABANK_returnPacket | ( | SPP_Packet_t * | p_packet | ) |
Return a packet to the pool after processing.
| [in] | p_packet | Pointer previously returned by SPP_SERVICES_DATABANK_getPacket(). |
p_packet is NULL. p_packet is not a valid pool address (double-return guard). 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().
| spp_uint32_t SPP_SERVICES_DATABANK_freeCount | ( | void | ) |
Return the number of free packets currently available.
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().
|
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().
| 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().
| [out] | p_packet | Packet previously acquired from SPP_SERVICES_DATABANK_getPacket(). |
| [in] | apid | Application Process Identifier. |
| [in] | seq | Packet sequence counter (maintained by the caller). |
| [in] | p_data | Pointer to the payload data to copy. |
| [in] | dataLen | Number of bytes to copy (must be ≤ K_SPP_PKT_PAYLOAD_MAX). |
p_packet or p_data is NULL. 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().
|
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().
|
static |
Control structure (free-list stack).
Definition at line 24 of file databank.c.
Referenced by SPP_SERVICES_DATABANK_freeCount(), SPP_SERVICES_DATABANK_getPacket(), SPP_SERVICES_DATABANK_init(), and SPP_SERVICES_DATABANK_returnPacket().
|
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().