Solaris Software
Loading...
Searching...
No Matches
custom.c
Go to the documentation of this file.
1/**
2 * @file custom.c
3 * @brief Custom definitions for the Solaris Packet Protocol
4 */
5
6
7/* ----------------------------------------------------------------
8 * INCLUDES
9 * ---------------------------------------------------------------- */
10#include "custom.h"
11
12#include "spp/core/core.h"
13#include "spp/core/commonbit.h"
15
18#include "spp/services/kpid.h"
20
22#include "spp/hal/hal.h"
23#include "spp/hal/time/time.h"
24/* ----------------------------------------------------------------
25 * STATIC FUNCTIONS DECLARATIONS
26 * ---------------------------------------------------------------- */
28static spp_bool_t CUSTOM_initCheck(void);
30static void action_emitTelemetry(void);
31static void statefunction_bmpPerformanceLoop(void);
32
33/* ----------------------------------------------------------------
34 * VARIABLES
35 * ---------------------------------------------------------------- */
37 {
38 .fromState = FSM_STATE_INIT,
39 .fromSubState = FSM_SUBSTATE_NONE,
40 .toState = FSM_STATE_READY,
41 .toSubState = FSM_SUBSTATE_NONE,
43 .action = action_emitTelemetry,
44 .stateFunction = NULL,
45 },
46 {
47 .fromState = FSM_STATE_READY,
48 .fromSubState = FSM_SUBSTATE_NONE,
49 .toState = FSM_STATE_READY,
50 .toSubState = FSM_SUBSTATE_NONE,
51 .guard = NULL,
52 .action = NULL,
53 .stateFunction = statefunction_bmpPerformanceLoop,
54 },
55};
56
59
62
63/* ----------------------------------------------------------------
64 * PUBLIC FUNCTIONS
65 * ---------------------------------------------------------------- */
70
75
80
81/* ----------------------------------------------------------------
82 * PRIVATE FUNCTIONS
83 * ---------------------------------------------------------------- */
84
85/* Guards */
86
88{
90 if (registered == false)
91 {
92 return false;
93 }
94
96
97 spp_bool_t initCheck = CUSTOM_initCheck();
98
99 if (ret != K_SPP_OK)
100 {
101 return false;
102 }
103
104 if (initCheck == false)
105 {
106 return false;
107 }
108 return true;
109}
110
111/* Actions*/
112
113static void action_emitTelemetry(void)
114{
117 if (p_commonBit == NULL)
118 {
119 return;
120 }
121
122 spp_uint16_t errorBitPayload[2] = {s_fsmErrors.errors, p_commonBit->errors};
123 SPP_RetVal_t ret = SPP_SERVICES_DATABANK_packetData(p_packet, K_SPP_KPID_FSM, 0U, errorBitPayload,
124 (spp_uint16_t)sizeof(errorBitPayload));
125 if (ret != K_SPP_OK)
126 {
127 return;
128 }
129
130 // Publish the packet to the PUBSUB service
131 ret = SPP_SERVICES_PUBSUB_publish(p_packet);
132 if (ret != K_SPP_OK)
133 {
134 return;
135 }
136
137 // Call the consumers (to force the telemetry to be sent)
138 //(void)SPP_SERVICES_PUBSUB_callConsumers();
139
140 return;
141}
142
143/* State functions */
144
165
166
167/**
168* @brief Register consumers and producers.
169* @return K_SPP_OK on success.
170*/
172{
173 SPP_Kpid_t bmp390Kpid = {0};
174 // SPP_Kpid_t icm20948Kpid = {0};
175 // SPP_Kpid_t m10mKpid = {0};
176
177 // SPP_Kpid_t sdSubscription = {0};
178 // SPP_Kpid_t e22mbl01Subscription = {0};
179
181
183 if (s_p_bmpProducerContract == NULL)
184 {
185 s_fsmErrors.bmpPubsubError = 1;
186 }
187 else
188 {
190 if (ret != K_SPP_OK)
191 {
192 s_fsmErrors.bmpPubsubError = 1;
193 }
194 }
195
196 // const SPP_SERVICE_ProducerContract_t *p_icmProducerContract = SPP_SERVICES_ICM20948_getProducerContract();
197 // if (p_icmProducerContract == NULL)
198 // {
199 // s_fsmErrors.icmPubsubError = 1;
200 // }
201 // ret = SPP_SERVICES_PUBSUB_registerProducer(p_icmProducerContract, &icm20948Kpid);
202 // if (ret != K_SPP_OK)
203 // {
204 // s_fsmErrors.icmPubsubError = 1;
205 // }
206
207 // const SPP_SERVICE_ProducerContract_t *p_m10mProducerContract = SPP_SERVICES_M10M_getProducerContract();
208 // if (p_m10mProducerContract == NULL)
209 // {
210 // s_fsmErrors.m10mPubsubError = 1;
211 // }
212 // ret = SPP_SERVICES_PUBSUB_registerProducer(p_m10mProducerContract, &m10mKpid);
213 // if (ret != K_SPP_OK)
214 // {
215 // s_fsmErrors.m10mPubsubError = 1;
216 // }
217
218 // sdSubscription.value = bmp390Kpid.value | icm20948Kpid.value | m10mKpid.value;
219
220 // const SPP_SERVICE_ConsumerContract_t *p_sdConsumerContract = SPP_SERVICES_DATALOGGER_getConsumerContract();
221 // ret = SPP_SERVICES_PUBSUB_registerConsumer(p_sdConsumerContract, sdSubscription);
222 // if (ret != K_SPP_OK)
223 // {
224 // s_fsmErrors.datalogggerPubsubError = 1;
225 // }
226
227 // e22mbl01Subscription.value = bmp390Kpid.value | icm20948Kpid.value | K_SPP_KPID_FSM;
228 // const SPP_SERVICE_ConsumerContract_t *p_e22mbl01ConsumerContract = SPP_SERVICES_E22MBL01_getConsumerContract();
229 // ret = SPP_SERVICES_PUBSUB_registerConsumer(p_e22mbl01ConsumerContract, e22mbl01Subscription);
230 // if (ret != K_SPP_OK)
231 // {
232 // s_fsmErrors.e22mbl01PubsubError = 1;
233 // }
234
235 // spp_bool_t producersFailed =
236 // (s_fsmErrors.bmpPubsubError && s_fsmErrors.icmPubsubError && s_fsmErrors.m10mPubsubError);
237 // spp_bool_t consumersFailed = (s_fsmErrors.datalogggerPubsubError && s_fsmErrors.e22mbl01PubsubError);
238
239 if (s_fsmErrors.bmpPubsubError)
240 {
241 return false;
242 }
243
244 return true;
245}
246
248{
251 if (ret != K_SPP_OK || bmpInitResult == K_SPP_ERROR_NOT_INITIALIZED)
252 {
253 return false;
254 }
255
256 if (bmpInitResult != K_SPP_OK)
257 {
258 s_fsmErrors.bmpInitError = 1;
259 return false;
260 }
261
262 return true;
263}
const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract(void)
Definition bmp390.c:87
BMP390 barometric pressure sensor driver and service.
CommonBitErrors_t * SPP_CORE_COMMONBIT_getBit(void)
Get the pointer to the common bit.
Definition commonbit.c:24
SPP_RetVal_t SPP_CORE_init()
Initialise the core software stack. Must be called before any other SPP function. It starts the datab...
Definition core.c:34
SPP core initialisation and port registration API.
static spp_uint32_t s_busyTimeUs
Definition custom.c:61
static const SPP_SERVICE_ProducerContract_t * s_p_bmpProducerContract
Definition custom.c:58
static FsmErrors_t s_fsmErrors
Definition custom.c:57
static spp_bool_t guard_startInitializationOfModules(void)
Definition custom.c:87
static spp_bool_t CUSTOM_registerConsumerProducer(void)
Register consumers and producers.
Definition custom.c:171
static spp_bool_t CUSTOM_initCheck(void)
Definition custom.c:247
const FSM_Transition_t * CUSTOM_getFsmTable(void)
Definition custom.c:66
static FSM_Transition_t s_transitionTable[]
Definition custom.c:36
static void statefunction_bmpPerformanceLoop(void)
Definition custom.c:145
spp_uint16_t CUSTOM_getProcessedSamples(void)
Definition custom.c:76
spp_uint32_t CUSTOM_getBusyTimeUs(void)
Definition custom.c:71
static void action_emitTelemetry(void)
Definition custom.c:113
static spp_uint16_t s_processedSamples
Definition custom.c:60
Finite State Machine (FSM) module for the SPP core.
SPP_Packet_t * SPP_SERVICES_DATABANK_getPacket(void)
Acquire a free packet from the pool.
Definition databank.c:53
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
Static packet pool manager.
@ FSM_STATE_READY
Definition fsm.h:29
@ FSM_STATE_INIT
Definition fsm.h:28
@ FSM_SUBSTATE_NONE
Definition fsm.h:39
ESP32-S3 HAL port descriptor for SPP.
This file contains the structs that contain all the pointers to the functions that are used by the SP...
APID bitmask assignments for every SPP producer.
#define K_SPP_KPID_FSM
Definition kpid.h:18
SPP_Packet_t
Definition packet.h:79
void SPP_SERVICES_PUBSUB_callConsumers(void)
Routes all buffered packets to matching consumer mailboxes, then clears the buffer.
Definition pubsub.c:152
spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth(void)
Returns the number of packets currently held in the internal FIFO buffer.
Definition pubsub.c:172
void SPP_SERVICES_PUBSUB_callProducers(void)
Calls acquireData on every registered producer.
Definition pubsub.c:119
SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_RetVal_t *p_initResult)
Definition pubsub.c:220
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_Kpid_t *p_assignedKpid)
Definition pubsub.c:58
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.
Definition pubsub.c:128
Publish-subscribe packet router.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
@ K_SPP_ERROR_NOT_INITIALIZED
Definition returnTypes.h:31
@ K_SPP_OK
Definition returnTypes.h:25
@ K_SPP_ERROR
Definition returnTypes.h:26
SPP module descriptor and registry API.
A single row in the FSM transition table.
Definition fsm.h:49
Describes the contract of a producer module. This module needs to have:
Definition service.h:28
spp_uint32_t SPP_HAL_TIME_getTimeUs(void)
Return the current hardware time in microseconds.
Definition time.c:27
SPP HAL time API — dispatches through the registered HAL port.
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27
bool spp_bool_t
Definition types.h:36
spp_uint16_t errors
Definition commonbit.h:7
spp_uint16_t errors
Definition custom.h:24