./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
21 / 39
53.8%
Branches:
3 / 6
50.0%
Functions:
4 / 8
50.0%

k-fsw/app/src/parameters/watchdog_table.c
Line Branch Exec Source
1 #include <stdint.h>
2
3 #include <zephyr/sys/util.h>
4
5 #include <kfsw/platform/watchdog.h>
6 #include <kfsw/services/parameter.h>
7
8 #include "tables.h"
9
10 /* Read-only: the timeout is installed once at init. */
11 static uint32_t watchdog_timeout_ms;
12 static uint32_t watchdog_feed_interval_ms;
13 static uint32_t watchdog_feeds;
14 static uint32_t watchdog_since_feed_ms;
15 static uint8_t watchdog_state;
16 static uint8_t watchdog_device_bound;
17 static uint8_t watchdog_keepalive_owned;
18
19 6 static void sample_watchdog(void)
20 {
21 struct kfsw_platform_watchdog_info info;
22
23
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (kfsw_platform_watchdog_get_info(&info) != 0) {
24 ✗ watchdog_device_bound = 0U;
25 ✗ return;
26 }
27 6 watchdog_timeout_ms = info.timeout_ms;
28 6 watchdog_feed_interval_ms = info.feed_interval_ms;
29 6 watchdog_feeds = info.feeds;
30 6 watchdog_since_feed_ms = info.since_feed_ms;
31 6 watchdog_state = info.state;
32
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 watchdog_device_bound = info.device_bound ? 1U : 0U;
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 watchdog_keepalive_owned = info.keepalive_owned ? 1U : 0U;
34 }
35
36 2 static void sample_timeout_ms(void *value)
37 {
38 2 sample_watchdog();
39 2 *(uint32_t *)value = watchdog_timeout_ms;
40 2 }
41
42 ✗ static void sample_feed_interval_ms(void *value)
43 {
44 ✗ sample_watchdog();
45 ✗ *(uint32_t *)value = watchdog_feed_interval_ms;
46 ✗ }
47
48 2 static void sample_feeds(void *value)
49 {
50 2 sample_watchdog();
51 2 *(uint32_t *)value = watchdog_feeds;
52 2 }
53
54 ✗ static void sample_since_feed_ms(void *value)
55 {
56 ✗ sample_watchdog();
57 ✗ *(uint32_t *)value = watchdog_since_feed_ms;
58 ✗ }
59
60 ✗ static void sample_state(void *value)
61 {
62 ✗ sample_watchdog();
63 ✗ *(uint8_t *)value = watchdog_state;
64 ✗ }
65
66 2 static void sample_device_bound(void *value)
67 {
68 2 sample_watchdog();
69 2 *(uint8_t *)value = watchdog_device_bound;
70 2 }
71
72 ✗ static void sample_keepalive_owned(void *value)
73 {
74 ✗ sample_watchdog();
75 ✗ *(uint8_t *)value = watchdog_keepalive_owned;
76 ✗ }
77
78 static const struct kfsw_param_definition watchdog_param_definitions[] = {
79 {
80 .offset = 0x00U,
81 .type = KFSW_PARAM_U32,
82 .flags = KFSW_PARAM_FLAG_READ_ONLY,
83 .name = "timeout_ms",
84 .unit = "ms",
85 .description = "Timeout installed in hardware at initialization",
86 .value = &watchdog_timeout_ms,
87 .default_value = {.u32 = 0U},
88 .sample = sample_timeout_ms,
89 },
90 {
91 .offset = 0x04U,
92 .type = KFSW_PARAM_U32,
93 .flags = KFSW_PARAM_FLAG_READ_ONLY,
94 .name = "feed_interval_ms",
95 .unit = "ms",
96 .description = "Interval the keep-alive feeds at",
97 .value = &watchdog_feed_interval_ms,
98 .default_value = {.u32 = 0U},
99 .sample = sample_feed_interval_ms,
100 },
101 {
102 .offset = 0x08U,
103 .type = KFSW_PARAM_U32,
104 .flags = KFSW_PARAM_FLAG_READ_ONLY,
105 .name = "feeds",
106 .description = "Feeds issued since boot; saturates",
107 .value = &watchdog_feeds,
108 .default_value = {.u32 = 0U},
109 .sample = sample_feeds,
110 },
111 {
112 .offset = 0x0cU,
113 .type = KFSW_PARAM_U32,
114 .flags = KFSW_PARAM_FLAG_READ_ONLY,
115 .name = "since_feed_ms",
116 .unit = "ms",
117 .description = "Milliseconds since the most recent feed",
118 .value = &watchdog_since_feed_ms,
119 .default_value = {.u32 = 0U},
120 .sample = sample_since_feed_ms,
121 },
122 {
123 .offset = 0x10U,
124 .type = KFSW_PARAM_U8,
125 .flags = KFSW_PARAM_FLAG_READ_ONLY,
126 .name = "state",
127 .description = "Watchdog lifecycle state",
128 .value = &watchdog_state,
129 .default_value = {.u8 = 0U},
130 .sample = sample_state,
131 },
132 {
133 .offset = 0x11U,
134 .type = KFSW_PARAM_U8,
135 .flags = KFSW_PARAM_FLAG_READ_ONLY,
136 .name = "device_bound",
137 .description = "Whether a watchdog device was bound at initialization",
138 .value = &watchdog_device_bound,
139 .default_value = {.u8 = 0U},
140 .sample = sample_device_bound,
141 },
142 {
143 .offset = 0x12U,
144 .type = KFSW_PARAM_U8,
145 .flags = KFSW_PARAM_FLAG_READ_ONLY,
146 .name = "keepalive_owned",
147 .description = "Whether the platform keep-alive is the one feeding",
148 .value = &watchdog_keepalive_owned,
149 .default_value = {.u8 = 0U},
150 .sample = sample_keepalive_owned,
151 },
152 };
153
154 KFSW_PARAM_TABLE_FITS_THE_LINK(watchdog_param_definitions);
155
156 const struct kfsw_param_definition_set kfsw_watchdog_param_definitions = {
157 .table = KFSW_PARAM_TABLE_WATCHDOG,
158 .name = KFSW_PARAM_TABLE_WATCHDOG_NAME,
159 .description = "Hardware watchdog timing and feeds",
160 .definitions = watchdog_param_definitions,
161 .count = ARRAY_SIZE(watchdog_param_definitions),
162 };
163