./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
32 / 56
57.1%
Branches:
7 / 10
70.0%
Functions:
7 / 13
53.8%

kfsw-services/src/gndwdt-parameters/gndwdt_table.c
Line Branch Exec Source
1 #include <errno.h>
2 #include <stdint.h>
3
4 #include <zephyr/sys/util.h>
5
6 #include <kfsw/services/gndwdt.h>
7 #include <kfsw/services/parameter.h>
8
9 static uint8_t gndwdt_enabled = IS_ENABLED(CONFIG_KFSW_GNDWDT_ENABLED_AT_START);
10 static uint8_t gndwdt_running;
11 static uint32_t ground_wtd_timeout = CONFIG_KFSW_GNDWDT_TIMEOUT_S;
12 static uint32_t gndwdt_since_s;
13 static uint32_t ground_wtd_cnt;
14 static uint32_t gndwdt_contacts;
15 static uint32_t gndwdt_expiries;
16 static uint16_t gndwdt_last_node;
17
18 40 static void sample_status(void)
19 {
20 struct kfsw_gndwdt_status status;
21
22 40 kfsw_gndwdt_get_status(&status);
23
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 gndwdt_enabled = status.enabled ? 1U : 0U;
24
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 gndwdt_running = status.running ? 1U : 0U;
25 40 ground_wtd_timeout = status.timeout_s;
26 40 gndwdt_since_s = status.since_contact_s;
27 40 ground_wtd_cnt = status.remaining_s;
28 40 gndwdt_contacts = status.contacts;
29 40 gndwdt_expiries = status.expiries;
30 40 gndwdt_last_node = status.last_node;
31 40 }
32
33 ✗ static void sample_enabled(void *value)
34 {
35 ✗ sample_status();
36 ✗ *(uint8_t *)value = gndwdt_enabled;
37 ✗ }
38
39 ✗ static void sample_running(void *value)
40 {
41 ✗ sample_status();
42 ✗ *(uint8_t *)value = gndwdt_running;
43 ✗ }
44
45 16 static void sample_timeout(void *value)
46 {
47 16 sample_status();
48 16 *(uint32_t *)value = ground_wtd_timeout;
49 16 }
50
51 ✗ static void sample_since(void *value)
52 {
53 ✗ sample_status();
54 ✗ *(uint32_t *)value = gndwdt_since_s;
55 ✗ }
56
57 24 static void sample_countdown(void *value)
58 {
59 24 sample_status();
60 24 *(uint32_t *)value = ground_wtd_cnt;
61 24 }
62
63 ✗ static void sample_contacts(void *value)
64 {
65 ✗ sample_status();
66 ✗ *(uint32_t *)value = gndwdt_contacts;
67 ✗ }
68
69 ✗ static void sample_expiries(void *value)
70 {
71 ✗ sample_status();
72 ✗ *(uint32_t *)value = gndwdt_expiries;
73 ✗ }
74
75 ✗ static void sample_last_node(void *value)
76 {
77 ✗ sample_status();
78 ✗ *(uint16_t *)value = gndwdt_last_node;
79 ✗ }
80
81 8 static int validate_enabled(const union kfsw_param_scalar *value)
82 {
83
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 return (value->u8 <= 1U) ? 0 : -EINVAL;
84 }
85
86 8 static void apply_enabled(const union kfsw_param_scalar *value)
87 {
88 8 kfsw_gndwdt_set_enabled(value->u8 != 0U);
89 8 }
90
91 56 static int validate_timeout(const union kfsw_param_scalar *value)
92 {
93
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
56 if ((value->u32 < CONFIG_KFSW_GNDWDT_TIMEOUT_MIN_S) ||
94
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 24 times.
40 (value->u32 > CONFIG_KFSW_GNDWDT_TIMEOUT_MAX_S)) {
95 32 return -ERANGE;
96 }
97 24 return 0;
98 }
99
100 24 static void apply_timeout(const union kfsw_param_scalar *value)
101 {
102 24 (void)kfsw_gndwdt_set_timeout_s(value->u32);
103 24 }
104
105 static const struct kfsw_param_definition gndwdt_param_definitions[] = {
106 {
107 .offset = 0x00U,
108 .type = KFSW_PARAM_U8,
109 .name = "gndwdt_enabled",
110 .description = "Whether the countdown is armed",
111 .value = &gndwdt_enabled,
112 .default_value = {.u8 = IS_ENABLED(CONFIG_KFSW_GNDWDT_ENABLED_AT_START)},
113 .validate = validate_enabled,
114 .changed = apply_enabled,
115 .sample = sample_enabled,
116 },
117 {
118 .offset = 0x04U,
119 .type = KFSW_PARAM_U32,
120 .unit = "s",
121 .name = "ground_wtd_timeout",
122 .description = "Timeout in seconds, 7200 to 432000",
123 .value = &ground_wtd_timeout,
124 .default_value = {.u32 = CONFIG_KFSW_GNDWDT_TIMEOUT_S},
125 .validate = validate_timeout,
126 .changed = apply_timeout,
127 .sample = sample_timeout,
128 },
129 {
130 .offset = 0x08U,
131 .type = KFSW_PARAM_U32,
132 .unit = "s",
133 .flags = KFSW_PARAM_FLAG_READ_ONLY,
134 .name = "gndwdt_since_s",
135 .description = "Seconds since the last contact",
136 .value = &gndwdt_since_s,
137 .default_value = {.u32 = 0U},
138 .sample = sample_since,
139 },
140 {
141 .offset = 0x0cU,
142 .type = KFSW_PARAM_U32,
143 .flags = KFSW_PARAM_FLAG_READ_ONLY,
144 .name = "gndwdt_contacts",
145 .description = "Valid ground_wtd feeds since boot",
146 .value = &gndwdt_contacts,
147 .default_value = {.u32 = 0U},
148 .sample = sample_contacts,
149 },
150 {
151 .offset = 0x10U,
152 .type = KFSW_PARAM_U32,
153 .flags = KFSW_PARAM_FLAG_READ_ONLY,
154 .name = "gndwdt_expiries",
155 .description = "Times the timeout passed since start",
156 .value = &gndwdt_expiries,
157 .default_value = {.u32 = 0U},
158 .sample = sample_expiries,
159 },
160 {
161 .offset = 0x14U,
162 .type = KFSW_PARAM_U16,
163 .flags = KFSW_PARAM_FLAG_READ_ONLY,
164 .name = "gndwdt_last_node",
165 .description = "Node of the most recent contact",
166 .value = &gndwdt_last_node,
167 .default_value = {.u16 = 0U},
168 .sample = sample_last_node,
169 },
170 {
171 .offset = 0x16U,
172 .type = KFSW_PARAM_U8,
173 .flags = KFSW_PARAM_FLAG_READ_ONLY,
174 .name = "gndwdt_running",
175 .description = "Whether the service has been started",
176 .value = &gndwdt_running,
177 .default_value = {.u8 = 0U},
178 .sample = sample_running,
179 },
180 {
181 .offset = 0x18U,
182 .type = KFSW_PARAM_U32,
183 .unit = "s",
184 .flags = KFSW_PARAM_FLAG_READ_ONLY,
185 .name = "ground_wtd_cnt",
186 .description = "Seconds remaining on the ground watchdog",
187 .value = &ground_wtd_cnt,
188 .default_value = {.u32 = 0U},
189 .sample = sample_countdown,
190 },
191 };
192
193 KFSW_PARAM_TABLE_FITS_THE_LINK(gndwdt_param_definitions);
194
195 const struct kfsw_param_definition_set kfsw_gndwdt_param_definitions = {
196 .table = KFSW_GNDWDT_PARAM_TABLE_ID,
197 .name = KFSW_GNDWDT_PARAM_TABLE_NAME,
198 .description = "Ground watchdog countdown",
199 .definitions = gndwdt_param_definitions,
200 .count = ARRAY_SIZE(gndwdt_param_definitions),
201 };
202