Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
databank.h
Go to the documentation of this file.
1
/**
2
* @file databank.h
3
* @brief Static packet pool manager.
4
*
5
* The databank maintains a fixed pool of @ref SPP_Packet_t objects.
6
* Producers call @ref SPP_SERVICES_DATABANK_getPacket() to acquire a free packet,
7
* fill it, and pass it to the @c db_flow FIFO. Consumers return packets
8
* via @ref SPP_SERVICES_DATABANK_returnPacket() after processing.
9
*
10
* The pool size is controlled by @ref K_SPP_DATABANK_SIZE (default 5).
11
*
12
* Naming conventions used in this file:
13
* - Constants/macros: K_SPP_DATABANK_*
14
* - Types: SPP_Databank_t
15
* - Public functions: SPP_SERVICES_DATABANK_*()
16
* - Pointer parameters: p_*
17
*/
18
19
#ifndef SPP_DATABANK_H
20
#define SPP_DATABANK_H
21
22
#include "
spp/core/packet.h
"
23
#include "
spp/core/returnTypes.h
"
24
#include "
spp/core/types.h
"
25
#include "
spp/util/macros.h
"
26
27
/* ----------------------------------------------------------------
28
* Databank state type
29
* ---------------------------------------------------------------- */
30
31
/**
32
* @brief Internal databank control structure.
33
*
34
* Exposed here only to allow static allocation by the caller if needed;
35
* treat all fields as private — use only the public API.
36
*/
37
typedef
struct
38
{
39
SPP_Packet_t
*
p_freePackets
[
K_SPP_DATABANK_SIZE
];
/**< Free packet stack. */
40
spp_uint32_t
freeCount
;
/**< Free packets count. */
41
}
SPP_Databank_t
;
42
43
/* ----------------------------------------------------------------
44
* Public API
45
* ---------------------------------------------------------------- */
46
47
/**
48
* @brief Initialise the packet pool.
49
*
50
* Zeroes all packets and rebuilds the free stack. Safe to call multiple
51
* times; subsequent calls are no-ops and return
52
* @c K_SPP_ERROR_ALREADY_INITIALIZED.
53
*
54
* @return K_SPP_OK on success, K_SPP_ERROR_ALREADY_INITIALIZED if already done.
55
*/
56
SPP_RetVal_t
SPP_SERVICES_DATABANK_init
(
void
);
57
58
/**
59
* @brief Acquire a free packet from the pool.
60
*
61
* The returned packet is removed from the free list until returned via
62
* @ref SPP_SERVICES_DATABANK_returnPacket().
63
*
64
* @return Pointer to a free @ref SPP_Packet_t, or NULL if the pool is empty.
65
*/
66
SPP_Packet_t
*
SPP_SERVICES_DATABANK_getPacket
(
void
);
67
68
/**
69
* @brief Return a packet to the pool after processing.
70
*
71
* @param[in] p_packet Pointer previously returned by @ref SPP_SERVICES_DATABANK_getPacket().
72
*
73
* @return K_SPP_OK on success.
74
* @return K_SPP_ERROR_NULL_POINTER if @p p_packet is NULL.
75
* @return K_SPP_ERROR if @p p_packet is not a valid pool address (double-return guard).
76
* @return K_SPP_ERROR_ALREADY_INITIALIZED if the packet is already in the free list.
77
*/
78
SPP_RetVal_t
SPP_SERVICES_DATABANK_returnPacket
(
SPP_Packet_t
*p_packet);
79
80
/**
81
* @brief Return the number of free packets currently available.
82
*
83
* @return Free packet count (0 … K_SPP_DATABANK_SIZE).
84
*/
85
spp_uint32_t
SPP_SERVICES_DATABANK_freeCount
(
void
);
86
87
/**
88
* @brief Fill a packet with data and compute its CRC.
89
*
90
* Zeroes the entire packet (including any struct padding), writes all header
91
* fields, copies @p p_data into the payload, and computes a CRC-16/CCITT
92
* checksum over every byte of the packet except the @c crc field itself.
93
*
94
* The timestamp is captured automatically via @ref SPP_HAL_TIME_getTimeMs().
95
*
96
* @param[out] p_packet Packet previously acquired from @ref SPP_SERVICES_DATABANK_getPacket().
97
* @param[in] apid Application Process Identifier.
98
* @param[in] seq Packet sequence counter (maintained by the caller).
99
* @param[in] p_data Pointer to the payload data to copy.
100
* @param[in] dataLen Number of bytes to copy (must be ≤ K_SPP_PKT_PAYLOAD_MAX).
101
*
102
* @return K_SPP_OK on success.
103
* @return K_SPP_ERROR_NULL_POINTER if @p p_packet or @p p_data is NULL.
104
* @return K_SPP_ERROR_INVALID_PARAMETER if @p dataLen exceeds K_SPP_PKT_PAYLOAD_MAX.
105
*/
106
SPP_RetVal_t
SPP_SERVICES_DATABANK_packetData
(
SPP_Packet_t
*p_packet,
spp_uint16_t
apid,
spp_uint16_t
seq,
107
const
void
*p_data,
spp_uint16_t
dataLen);
108
109
#endif
/* SPP_DATABANK_H */
SPP_SERVICES_DATABANK_getPacket
SPP_Packet_t * SPP_SERVICES_DATABANK_getPacket(void)
Acquire a free packet from the pool.
Definition
databank.c:53
SPP_SERVICES_DATABANK_returnPacket
SPP_RetVal_t SPP_SERVICES_DATABANK_returnPacket(SPP_Packet_t *p_packet)
Return a packet to the pool after processing.
Definition
databank.c:64
SPP_SERVICES_DATABANK_init
SPP_RetVal_t SPP_SERVICES_DATABANK_init(void)
Initialise the packet pool.
Definition
databank.c:33
SPP_SERVICES_DATABANK_freeCount
spp_uint32_t SPP_SERVICES_DATABANK_freeCount(void)
Return the number of free packets currently available.
Definition
databank.c:96
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.
Definition
databank.c:117
macros.h
Compile-time configuration flags and utility macros for SPP.
K_SPP_DATABANK_SIZE
#define K_SPP_DATABANK_SIZE
Number of packets in the static databank pool.
Definition
macros.h:47
packet.h
Solaris Packet Protocol (SPP) packet structure definitions.
SPP_Packet_t
SPP_Packet_t
Definition
packet.h:79
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
SPP_Databank_t
Internal databank control structure.
Definition
databank.h:38
SPP_Databank_t::p_freePackets
SPP_Packet_t * p_freePackets[K_SPP_DATABANK_SIZE]
Definition
databank.h:39
SPP_Databank_t::freeCount
spp_uint32_t freeCount
Definition
databank.h:40
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint16_t
uint16_t spp_uint16_t
Definition
types.h:29
spp_uint32_t
uint32_t spp_uint32_t
Definition
types.h:31
solaris-v2
spp
services
databank
databank.h
Generated by
1.18.0