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 acquire packets through @ref SPP_SERVICES_DATABANK_getPacket()
7
* and publish them through PUBSUB, which copies the data into its
8
* internal buffer and returns the original packet to the pool.
9
*
10
* The pool size is controlled by @ref K_SPP_DATABANK_SIZE (default 50).
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
* Internal state representation. Access the databank through its public API.
35
*/
36
typedef
struct
37
{
38
SPP_Packet_t
*
p_freePackets
[
K_SPP_DATABANK_SIZE
];
/**< Free packet stack. */
39
spp_uint32_t
freeCount
;
/**< Free packets count. */
40
}
SPP_Databank_t
;
41
42
/* ----------------------------------------------------------------
43
* Public API
44
* ---------------------------------------------------------------- */
45
46
/**
47
* @brief Initialise the packet pool.
48
*
49
* Zeroes all packets and rebuilds the free stack. Safe to call multiple
50
* times; subsequent calls are no-ops and return
51
* @c K_SPP_ERROR_ALREADY_INITIALIZED.
52
*
53
* @return K_SPP_OK on success, K_SPP_ERROR_ALREADY_INITIALIZED if already done.
54
*/
55
SPP_RetVal_t
SPP_SERVICES_DATABANK_init
(
void
);
56
57
/**
58
* @brief Acquire a free packet from the pool.
59
*
60
* The returned packet is removed from the free list until returned via
61
* @ref SPP_SERVICES_DATABANK_returnPacket().
62
*
63
* @return Pointer to a free @ref SPP_Packet_t, or NULL if the pool is empty.
64
*/
65
SPP_Packet_t
*
SPP_SERVICES_DATABANK_getPacket
(
void
);
66
67
/**
68
* @brief Return a packet to the pool after processing.
69
*
70
* @param[in] p_packet Pointer previously returned by @ref SPP_SERVICES_DATABANK_getPacket().
71
*
72
* @return K_SPP_OK on success.
73
* @return K_SPP_ERROR_NULL_POINTER if @p p_packet is NULL.
74
* @return K_SPP_ERROR if the pointer is outside the pool or the free list is full.
75
* @return K_SPP_ERROR_ALREADY_INITIALIZED if the packet is already in the free list.
76
*/
77
SPP_RetVal_t
SPP_SERVICES_DATABANK_returnPacket
(
SPP_Packet_t
*p_packet);
78
79
/**
80
* @brief Return the number of free packets currently available.
81
*
82
* @return Free packet count (0 … K_SPP_DATABANK_SIZE).
83
*/
84
spp_uint32_t
SPP_SERVICES_DATABANK_freeCount
(
void
);
85
86
/**
87
* @brief Fill a packet with data and compute its CRC.
88
*
89
* Initializes the packet bytes to 0xFF, writes all header
90
* fields, copies @p p_data into the payload, and computes a CRC-16/CCITT
91
* checksum over every byte of the packet except the @c crc field itself.
92
*
93
* The timestamp is captured automatically via @ref SPP_HAL_TIME_getTimeMs().
94
*
95
* @param[out] p_packet Packet previously acquired from @ref SPP_SERVICES_DATABANK_getPacket().
96
* @param[in] apid Application Process Identifier.
97
* @param[in] seq Packet sequence counter (maintained by the caller).
98
* @param[in] p_data Pointer to the payload data to copy.
99
* @param[in] dataLen Number of bytes to copy (must be ≤ K_SPP_PKT_PAYLOAD_MAX).
100
*
101
* @return K_SPP_OK on success.
102
* @return K_SPP_ERROR_NULL_POINTER if @p p_packet or @p p_data is NULL.
103
* @return K_SPP_ERROR_INVALID_PARAMETER if @p dataLen exceeds K_SPP_PKT_PAYLOAD_MAX.
104
*/
105
SPP_RetVal_t
SPP_SERVICES_DATABANK_packetData
(
SPP_Packet_t
*p_packet,
spp_uint16_t
apid,
spp_uint16_t
seq,
106
const
void
*p_data,
spp_uint16_t
dataLen);
107
108
#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:49
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:37
SPP_Databank_t::p_freePackets
SPP_Packet_t * p_freePackets[K_SPP_DATABANK_SIZE]
Definition
databank.h:38
SPP_Databank_t::freeCount
spp_uint32_t freeCount
Definition
databank.h:39
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