./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
23 / 25
92.0%
Branches:
16 / 20
80.0%
Functions:
3 / 3
100.0%

kfsw-services/src/hk/hk_thread.c
Line Branch Exec Source
1 #include <errno.h>
2 #include <zephyr/kernel.h>
3 #include <kfsw/services/hk.h>
4 #include "hk_internal.h"
5
6 static K_MUTEX_DEFINE(start_lock);
7 static K_SEM_DEFINE(schedule_wake, 0, 1);
8 static bool running;
9
10 2382 void kfsw_hk_wake(void)
11 {
12 2382 k_sem_give(&schedule_wake);
13 2382 }
14
15 2 static void hk_collector(void *a, void *b, void *c)
16 {
17 ARG_UNUSED(a);
18 ARG_UNUSED(b);
19 ARG_UNUSED(c);
20 172 for (;;) {
21
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 94 times.
362 for (uint8_t index = 0; index < CONFIG_KFSW_HK_REPORTS; index++) {
22 struct kfsw_hk_due due;
23
24
4/4
✓ Branch 1 taken 254 times.
✓ Branch 2 taken 14 times.
✓ Branch 4 taken 188 times.
✓ Branch 5 taken 66 times.
268 if (!kfsw_hk_enabled() || !kfsw_hk_clock_valid()) {
25 break;
26 }
27
2/2
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 112 times.
188 if (kfsw_hk_schedule_take(index, k_uptime_get(), &due)) {
28 76 (void)kfsw_hk_collect(index);
29 76 kfsw_hk_schedule_finish(index, &due, k_uptime_get());
30 }
31 #if CONFIG_KFSW_HK_BEACON
32
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ if (kfsw_hk_enabled() && kfsw_hk_clock_valid()) {
33 ✗ kfsw_hk_beacon_tick(index, k_uptime_get());
34 }
35 #endif
36 }
37 /* Clock changes have no wake hook yet. Poll at most every 200 ms. */
38
2/2
✓ Branch 2 taken 94 times.
✓ Branch 3 taken 66 times.
334 int64_t wait = (kfsw_hk_enabled() && kfsw_hk_clock_valid())
39 94 ? kfsw_hk_schedule_wait(k_uptime_get())
40
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 14 times.
240 : 200;
41
42 174 (void)k_sem_take(&schedule_wake, K_MSEC(wait));
43 }
44 }
45
46 K_THREAD_DEFINE(kfsw_hk_thread, CONFIG_KFSW_HK_STACK_SIZE, hk_collector, NULL, NULL, NULL,
47 CONFIG_KFSW_HK_PRIORITY, 0, SYS_FOREVER_MS);
48
49 12 int kfsw_hk_start(void)
50 {
51
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 4 times.
12 if (!kfsw_hk_is_ready()) {
52 8 return -EACCES;
53 }
54 4 k_mutex_lock(&start_lock, K_FOREVER);
55
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (!running) {
56 2 running = true;
57 2 k_thread_start(kfsw_hk_thread);
58 }
59 4 k_mutex_unlock(&start_lock);
60 4 return 0;
61 }
62