./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
18 / 62
29.0%
Branches:
2 / 6
33.3%
Functions:
3 / 13
23.1%

kfsw-services/src/hk-parameters/hk_table.c
Line Branch Exec Source
1 #include <stdint.h>
2
3 #include <zephyr/sys/util.h>
4
5 #include <kfsw/services/hk.h>
6 #include <kfsw/services/parameter.h>
7
8 /* Definition metadata, indexed by report; 255 marks an undefined report. */
9 static uint8_t hk_classes[CONFIG_KFSW_HK_REPORTS];
10
11 ✗ static void sample_classes(void *value)
12 {
13 ✗ uint8_t *classes = value;
14
15
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (uint8_t report = 0; report < CONFIG_KFSW_HK_REPORTS; report++) {
16 ✗ classes[report] = UINT8_MAX;
17 ✗ (void)kfsw_hk_get_class(report, &classes[report]);
18 }
19 ✗ }
20
21 /* Housekeeping counters and settings. */
22 static uint8_t hk_reports;
23 static uint8_t hk_enabled = 1U;
24 static uint32_t hk_collections;
25 static uint32_t hk_failures;
26 static uint32_t hk_entries_failed;
27 static uint32_t hk_overwritten;
28 static uint32_t hk_last_seconds;
29 static uint32_t hk_period_floor_ms = CONFIG_KFSW_HK_PERIOD_FLOOR_MS;
30 static uint8_t hk_history = CONFIG_KFSW_HK_HISTORY;
31 static uint8_t hk_max_entries = CONFIG_KFSW_HK_ENTRIES;
32 static uint8_t hk_clock_valid;
33 #if CONFIG_KFSW_HK_BEACON
34 static uint32_t hk_beacons_sent;
35 static uint32_t hk_beacons_skipped;
36 #endif
37
38 2 static void sample_stats(void)
39 {
40 struct kfsw_hk_stats stats;
41
42 2 kfsw_hk_get_stats(&stats);
43 2 hk_reports = stats.reports;
44 2 hk_collections = stats.collections;
45 2 hk_failures = stats.failures;
46 2 hk_entries_failed = stats.entries_failed;
47 2 hk_overwritten = stats.overwritten;
48 2 hk_last_seconds = stats.last_seconds;
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 hk_clock_valid = stats.clock_valid ? 1U : 0U;
50
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 hk_enabled = stats.enabled ? 1U : 0U;
51 #if CONFIG_KFSW_HK_BEACON
52 ✗ hk_beacons_sent = stats.beacons_sent;
53 ✗ hk_beacons_skipped = stats.beacons_skipped;
54 #endif
55 2 }
56
57 ✗ static void sample_reports(void *value)
58 {
59 ✗ sample_stats();
60 ✗ *(uint8_t *)value = hk_reports;
61 ✗ }
62
63 2 static void sample_collections(void *value)
64 {
65 2 sample_stats();
66 2 *(uint32_t *)value = hk_collections;
67 2 }
68
69 ✗ static void sample_failures(void *value)
70 {
71 ✗ sample_stats();
72 ✗ *(uint32_t *)value = hk_failures;
73 ✗ }
74
75 ✗ static void sample_entries_failed(void *value)
76 {
77 ✗ sample_stats();
78 ✗ *(uint32_t *)value = hk_entries_failed;
79 ✗ }
80
81 ✗ static void sample_overwritten(void *value)
82 {
83 ✗ sample_stats();
84 ✗ *(uint32_t *)value = hk_overwritten;
85 ✗ }
86
87 ✗ static void sample_last_seconds(void *value)
88 {
89 ✗ sample_stats();
90 ✗ *(uint32_t *)value = hk_last_seconds;
91 ✗ }
92
93 2 static void apply_enabled(const union kfsw_param_scalar *value)
94 {
95 2 kfsw_hk_set_enabled(value->u8 != 0U);
96 2 }
97
98 ✗ static void sample_enabled(void *value)
99 {
100 ✗ sample_stats();
101 ✗ *(uint8_t *)value = hk_enabled;
102 ✗ }
103
104 ✗ static void sample_clock_valid(void *value)
105 {
106 ✗ sample_stats();
107 ✗ *(uint8_t *)value = hk_clock_valid;
108 ✗ }
109
110 #if CONFIG_KFSW_HK_BEACON
111 ✗ static void sample_beacons_sent(void *value)
112 {
113 ✗ sample_stats();
114 ✗ *(uint32_t *)value = hk_beacons_sent;
115 ✗ }
116
117 ✗ static void sample_beacons_skipped(void *value)
118 {
119 ✗ sample_stats();
120 ✗ *(uint32_t *)value = hk_beacons_skipped;
121 ✗ }
122 #endif
123
124 static const struct kfsw_param_definition hk_param_definitions[] = {
125 {
126 .offset = 0x30,
127 .type = KFSW_PARAM_DATA,
128 .capacity = CONFIG_KFSW_HK_REPORTS,
129 .flags = KFSW_PARAM_FLAG_READ_ONLY,
130 .name = "hk_classes",
131 .description = "Definition classes by report; 255 undefined; define to change",
132 .value = hk_classes,
133 .sample = sample_classes,
134 },
135 {
136 .offset = 0x00,
137 .type = KFSW_PARAM_U8,
138 .flags = KFSW_PARAM_FLAG_READ_ONLY,
139 .name = "hk_reports",
140 .description = "Reports currently defined",
141 .value = &hk_reports,
142 .sample = sample_reports,
143 },
144 {
145 .offset = 0x01,
146 .type = KFSW_PARAM_U8,
147 .flags = KFSW_PARAM_FLAG_CONFIGURATION,
148 .name = "hk_enabled",
149 /* Turning collection off keeps definitions and samples. */
150 .description = "Collect periodic reports",
151 .value = &hk_enabled,
152 .default_value.u8 = 1U,
153 .changed = apply_enabled,
154 .sample = sample_enabled,
155 },
156 {
157 .offset = 0x02,
158 .type = KFSW_PARAM_U32,
159 .flags = KFSW_PARAM_FLAG_READ_ONLY,
160 .name = "hk_collections",
161 .description = "Reports collected since boot",
162 .value = &hk_collections,
163 .sample = sample_collections,
164 },
165 {
166 .offset = 0x06,
167 .type = KFSW_PARAM_U32,
168 .flags = KFSW_PARAM_FLAG_READ_ONLY,
169 .name = "hk_failures",
170 .description = "Collections that produced nothing",
171 .value = &hk_failures,
172 .sample = sample_failures,
173 },
174 {
175 .offset = 0x0a,
176 .type = KFSW_PARAM_U32,
177 .flags = KFSW_PARAM_FLAG_READ_ONLY,
178 .name = "hk_entries_failed",
179 .description = "Values that could not be read and were left absent",
180 .value = &hk_entries_failed,
181 .sample = sample_entries_failed,
182 },
183 {
184 .offset = 0x0e,
185 .type = KFSW_PARAM_U32,
186 .flags = KFSW_PARAM_FLAG_READ_ONLY,
187 .name = "hk_overwritten",
188 .description = "Samples the ring dropped to make room",
189 .value = &hk_overwritten,
190 .sample = sample_overwritten,
191 },
192 {
193 .offset = 0x12,
194 .type = KFSW_PARAM_U32,
195 .flags = KFSW_PARAM_FLAG_READ_ONLY,
196 .unit = "s",
197 .name = "hk_last_seconds",
198 .description = "When the last collection started, UTC",
199 .value = &hk_last_seconds,
200 .sample = sample_last_seconds,
201 },
202 {
203 .offset = 0x16,
204 .type = KFSW_PARAM_U8,
205 .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE,
206 .name = "hk_clock_valid",
207 /* Periodic collection waits until the clock is set. */
208 .description = "Whether the node has a clock, and so collects on its period",
209 .value = &hk_clock_valid,
210 .sample = sample_clock_valid,
211 },
212 #if CONFIG_KFSW_HK_BEACON
213 {
214 .offset = 0x20,
215 .type = KFSW_PARAM_U32,
216 .flags = KFSW_PARAM_FLAG_READ_ONLY,
217 .name = "hk_beacons_sent",
218 .description = "Samples put on the link without being asked",
219 .value = &hk_beacons_sent,
220 .sample = sample_beacons_sent,
221 },
222 {
223 .offset = 0x24,
224 .type = KFSW_PARAM_U32,
225 .flags = KFSW_PARAM_FLAG_READ_ONLY,
226 /* Beacons skipped because CSP buffers were short. */
227 .name = "hk_beacons_skipped",
228 .description = "Beacons not sent because CSP buffers were short",
229 .value = &hk_beacons_skipped,
230 .sample = sample_beacons_skipped,
231 },
232 #endif
233 {
234 .offset = 0x1a,
235 .type = KFSW_PARAM_U32,
236 .flags = KFSW_PARAM_FLAG_READ_ONLY,
237 .unit = "ms",
238 .name = "hk_period_floor_ms",
239 .description = "Shortest period a report may be given",
240 .value = &hk_period_floor_ms,
241 .default_value.u32 = CONFIG_KFSW_HK_PERIOD_FLOOR_MS,
242 },
243 {
244 .offset = 0x1e,
245 .type = KFSW_PARAM_U8,
246 .flags = KFSW_PARAM_FLAG_READ_ONLY,
247 .name = "hk_history",
248 .description = "Samples each report keeps",
249 .value = &hk_history,
250 .default_value.u8 = CONFIG_KFSW_HK_HISTORY,
251 },
252 {
253 .offset = 0x1f,
254 .type = KFSW_PARAM_U8,
255 .flags = KFSW_PARAM_FLAG_READ_ONLY,
256 .name = "hk_max_entries",
257 .description = "Values one report may name",
258 .value = &hk_max_entries,
259 .default_value.u8 = CONFIG_KFSW_HK_ENTRIES,
260 },
261 };
262
263 KFSW_PARAM_TABLE_FITS_THE_LINK(hk_param_definitions);
264
265 const struct kfsw_param_definition_set kfsw_hk_param_definitions = {
266 .table = KFSW_HK_PARAM_TABLE_ID,
267 .name = KFSW_HK_PARAM_TABLE_NAME,
268 .description = "Housekeeping reports and counters",
269 .definitions = hk_param_definitions,
270 .count = ARRAY_SIZE(hk_param_definitions),
271 };
272