./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
4 / 52
7.7%
Branches:
0 / 12
0.0%
Functions:
2 / 22
9.1%

kfsw-services/src/fbo-parameters/fbo_table.c
Line Branch Exec Source
1 #include <stdint.h>
2
3 #include <zephyr/sys/util.h>
4
5 #include <kfsw/services/fbo.h>
6 #include <kfsw/services/parameter.h>
7
8 #include "../fbo/fbo_internal.h"
9
10 /* Procedure counters and state. */
11
12 static char fbo_name[KFSW_FBO_NAME_MAX];
13 static uint8_t fbo_running;
14 static uint32_t fbo_runs;
15 static uint32_t fbo_lines_run;
16 static uint32_t fbo_lines_failed;
17 static uint32_t fbo_lines_skipped;
18 static uint16_t fbo_line;
19 static uint16_t fbo_lines_max = CONFIG_KFSW_FBO_LINES_MAX;
20
21 /* Queue state and counters. */
22
23 static uint16_t sched_entries;
24 static uint16_t sched_scheduled;
25 static uint16_t sched_overdue;
26 static uint8_t sched_clock_set;
27 static uint32_t sched_next_due_s;
28 static uint32_t sched_releases;
29 static uint32_t sched_refusals;
30 static uint32_t sched_overdues;
31 static uint32_t sched_hash;
32 static uint32_t sched_latency_s = CONFIG_KFSW_FBO_SCHEDULE_LATENCY_S;
33 static int64_t sched_next_due_utc;
34
35 ✗ static void sample_status(void)
36 {
37 struct kfsw_fbo_status status;
38
39
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ if (kfsw_fbo_get_status(&status) != 0) {
40 ✗ return;
41 }
42
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (size_t index = 0U; index < sizeof(fbo_name); index++) {
43 ✗ fbo_name[index] = status.name[index];
44 }
45 ✗ fbo_name[sizeof(fbo_name) - 1U] = '\0';
46
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ fbo_running = status.running ? 1U : 0U;
47 ✗ fbo_runs = status.runs;
48 ✗ fbo_lines_run = status.lines_run;
49 ✗ fbo_lines_failed = status.lines_failed;
50 ✗ fbo_lines_skipped = status.lines_skipped;
51 ✗ fbo_line = status.line;
52 }
53
54 ✗ static void sample_schedule(void)
55 {
56 struct kfsw_fbo_schedule_status status;
57
58
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ if (kfsw_fbo_schedule_get_status(&status) != 0) {
59 ✗ return;
60 }
61 ✗ sched_entries = status.entries;
62 ✗ sched_scheduled = status.scheduled;
63 ✗ sched_overdue = status.overdue;
64
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ sched_clock_set = status.clock_set ? 1U : 0U;
65 ✗ sched_next_due_s = status.next_due_s;
66 ✗ sched_releases = status.releases;
67 ✗ sched_refusals = status.refusals;
68 ✗ sched_overdues = status.overdues;
69 ✗ sched_hash = status.hash;
70 ✗ sched_latency_s = status.latency_s;
71 ✗ sched_next_due_utc = status.next_due_utc;
72 }
73
74 #define SCHED_SAMPLE(field, type) \
75 static void sample_sched_##field(void *value) \
76 { \
77 sample_schedule(); \
78 *(type *)value = sched_##field; \
79 }
80
81 ✗ SCHED_SAMPLE(entries, uint16_t)
82 ✗ SCHED_SAMPLE(scheduled, uint16_t)
83 ✗ SCHED_SAMPLE(overdue, uint16_t)
84 ✗ SCHED_SAMPLE(clock_set, uint8_t)
85 ✗ SCHED_SAMPLE(next_due_s, uint32_t)
86 ✗ SCHED_SAMPLE(releases, uint32_t)
87 ✗ SCHED_SAMPLE(refusals, uint32_t)
88 ✗ SCHED_SAMPLE(overdues, uint32_t)
89 ✗ SCHED_SAMPLE(hash, uint32_t)
90 ✗ SCHED_SAMPLE(latency_s, uint32_t)
91 ✗ SCHED_SAMPLE(next_due_utc, int64_t)
92
93 20 static int validate_latency(const union kfsw_param_scalar *value)
94 {
95 20 return kfsw_fbo_schedule_check_latency_s(value->u32);
96 }
97
98 10 static int apply_latency(const union kfsw_param_scalar *value)
99 {
100 10 return kfsw_fbo_schedule_set_latency_s(value->u32);
101 }
102
103 ✗ static void sample_name(void *value)
104 {
105 ✗ sample_status();
106
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (size_t index = 0U; index < sizeof(fbo_name); index++) {
107 ✗ ((char *)value)[index] = fbo_name[index];
108 }
109 ✗ }
110
111 #define FBO_SAMPLE(field, type) \
112 static void sample_##field(void *value) \
113 { \
114 sample_status(); \
115 *(type *)value = fbo_##field; \
116 }
117
118 ✗ FBO_SAMPLE(running, uint8_t)
119 ✗ FBO_SAMPLE(runs, uint32_t)
120 ✗ FBO_SAMPLE(lines_run, uint32_t)
121 ✗ FBO_SAMPLE(lines_failed, uint32_t)
122 ✗ FBO_SAMPLE(lines_skipped, uint32_t)
123 ✗ FBO_SAMPLE(line, uint16_t)
124
125 static const struct kfsw_param_definition fbo_param_definitions[] = {
126 {
127 .offset = 0x00U,
128 .type = KFSW_PARAM_U8,
129 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
130 .name = "fbo_running",
131 .description = "Whether a procedure is running now",
132 .value = &fbo_running,
133 .sample = sample_running,
134 },
135 {
136 .offset = 0x01U,
137 .type = KFSW_PARAM_U32,
138 .flags = KFSW_PARAM_FLAG_READ_ONLY,
139 .name = "fbo_runs",
140 .description = "Procedures started since boot",
141 .value = &fbo_runs,
142 .sample = sample_runs,
143 },
144 {
145 .offset = 0x05U,
146 .type = KFSW_PARAM_U32,
147 .flags = KFSW_PARAM_FLAG_READ_ONLY,
148 .name = "fbo_lines_run",
149 .description = "Lines carried out since boot",
150 .value = &fbo_lines_run,
151 .sample = sample_lines_run,
152 },
153 {
154 .offset = 0x09U,
155 .type = KFSW_PARAM_U32,
156 .flags = KFSW_PARAM_FLAG_READ_ONLY,
157 .name = "fbo_lines_failed",
158 .description = "Lines that reported a failure",
159 .value = &fbo_lines_failed,
160 .sample = sample_lines_failed,
161 },
162 {
163 .offset = 0x0dU,
164 .type = KFSW_PARAM_U32,
165 .flags = KFSW_PARAM_FLAG_READ_ONLY,
166 .name = "fbo_lines_skipped",
167 .description = "Lines a guard decided were not for this run",
168 .value = &fbo_lines_skipped,
169 .sample = sample_lines_skipped,
170 },
171 {
172 .offset = 0x11U,
173 .type = KFSW_PARAM_U16,
174 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
175 .name = "fbo_line",
176 .description = "Line the current or last run reached, 1-based",
177 .value = &fbo_line,
178 .sample = sample_line,
179 },
180 {
181 .offset = 0x20U,
182 .type = KFSW_PARAM_STRING,
183 .capacity = KFSW_FBO_NAME_MAX,
184 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
185 .name = "fbo_procedure",
186 .description = "Procedure running now, or the last one that ran",
187 .value = fbo_name,
188 .sample = sample_name,
189 },
190 {
191 .offset = 0x40U,
192 .type = KFSW_PARAM_U16,
193 .flags = KFSW_PARAM_FLAG_READ_ONLY,
194 .name = "fbo_lines_max",
195 .description = "Lines one procedure may carry out",
196 .value = &fbo_lines_max,
197 },
198 {
199 .offset = 0x50U,
200 .type = KFSW_PARAM_U16,
201 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
202 .name = "fbo_sched_entries",
203 .description = "Slots the queue is holding",
204 .value = &sched_entries,
205 .sample = sample_sched_entries,
206 },
207 {
208 .offset = 0x54U,
209 .type = KFSW_PARAM_U16,
210 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
211 .name = "fbo_sched_scheduled",
212 .description = "Entries still waiting for their time",
213 .value = &sched_scheduled,
214 .sample = sample_sched_scheduled,
215 },
216 {
217 .offset = 0x56U,
218 .type = KFSW_PARAM_U16,
219 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
220 .name = "fbo_sched_overdue",
221 .description = "Entries whose time passed beyond the buffer",
222 .value = &sched_overdue,
223 .sample = sample_sched_overdue,
224 },
225 {
226 .offset = 0x58U,
227 .type = KFSW_PARAM_U8,
228 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
229 .name = "fbo_sched_clock_set",
230 .description = "Whether an absolute entry can be accepted at all",
231 .value = &sched_clock_set,
232 .sample = sample_sched_clock_set,
233 },
234 {
235 .offset = 0x59U,
236 .type = KFSW_PARAM_U32,
237 .unit = "s",
238 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
239 .name = "fbo_sched_next_due_s",
240 .description = "Seconds to the earliest relative entry",
241 .value = &sched_next_due_s,
242 .sample = sample_sched_next_due_s,
243 },
244 {
245 .offset = 0x5dU,
246 .type = KFSW_PARAM_U32,
247 .flags = KFSW_PARAM_FLAG_READ_ONLY,
248 .name = "fbo_sched_releases",
249 .description = "Releases attempted since boot",
250 .value = &sched_releases,
251 .sample = sample_sched_releases,
252 },
253 {
254 .offset = 0x61U,
255 .type = KFSW_PARAM_U32,
256 .flags = KFSW_PARAM_FLAG_READ_ONLY,
257 .name = "fbo_sched_refusals",
258 .description = "Entries refused when they were added",
259 .value = &sched_refusals,
260 .sample = sample_sched_refusals,
261 },
262 {
263 .offset = 0x65U,
264 .type = KFSW_PARAM_U32,
265 .flags = KFSW_PARAM_FLAG_READ_ONLY,
266 .name = "fbo_sched_overdues",
267 .description = "Entries that went overdue since boot",
268 .value = &sched_overdues,
269 .sample = sample_sched_overdues,
270 },
271 {
272 .offset = 0x69U,
273 .type = KFSW_PARAM_U32,
274 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
275 .name = "fbo_sched_hash",
276 .description = "CRC32 over the queue, to compare against what was uploaded",
277 .value = &sched_hash,
278 .sample = sample_sched_hash,
279 },
280 {
281 .offset = 0x6dU,
282 .type = KFSW_PARAM_U32,
283 .unit = "s",
284 .flags = KFSW_PARAM_FLAG_CONFIGURATION,
285 .name = "fbo_sched_latency_s",
286 .description = "An entry later than this reports overdue instead of running",
287 .value = &sched_latency_s,
288 .default_value = {.u32 = CONFIG_KFSW_FBO_SCHEDULE_LATENCY_S},
289 .validate = validate_latency,
290 .apply = apply_latency,
291 .sample = sample_sched_latency_s,
292 },
293 {
294 .offset = 0x71U,
295 .type = KFSW_PARAM_I64,
296 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
297 .name = "fbo_sched_next_due_utc",
298 .description = "UTC second of the earliest absolute entry, 0 for none",
299 .value = &sched_next_due_utc,
300 .sample = sample_sched_next_due_utc,
301 },
302 };
303
304 KFSW_PARAM_TABLE_FITS_THE_LINK(fbo_param_definitions);
305
306 const struct kfsw_param_definition_set kfsw_fbo_param_definitions = {
307 .table = KFSW_FBO_PARAM_TABLE_ID,
308 .name = KFSW_FBO_PARAM_TABLE_NAME,
309 .description = "Procedure runs, progress and the time-tagged queue",
310 .definitions = fbo_param_definitions,
311 .count = ARRAY_SIZE(fbo_param_definitions),
312 };
313