./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
21 / 29
72.4%
Branches:
4 / 6
66.7%
Functions:
7 / 12
58.3%

kfsw-services/src/command-parameters/command_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/command.h>
7 #include <kfsw/services/parameter.h>
8
9 static uint32_t command_invoked;
10 static uint32_t command_failed;
11 static uint32_t command_unknown;
12 static uint32_t command_rejected;
13 #if CONFIG_KFSW_COMMAND_CSP
14 static uint32_t command_timeout_ms = CONFIG_KFSW_COMMAND_TIMEOUT_MS;
15 #endif
16 static uint16_t command_registered;
17 static uint8_t command_echo_enabled;
18
19 4 static void sample_stats(void)
20 {
21 struct kfsw_command_stats stats;
22
23
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (kfsw_command_get_stats(&stats) != 0) {
24 ✗ return;
25 }
26 4 command_invoked = stats.invoked;
27 4 command_failed = stats.failed;
28 4 command_unknown = stats.unknown;
29 4 command_rejected = stats.rejected;
30 4 command_registered = stats.registered;
31 }
32
33 #define COMMAND_SAMPLE(field, type) \
34 static void sample_##field(void *value) \
35 { \
36 sample_stats(); \
37 *(type *)value = command_##field; \
38 }
39
40 4 COMMAND_SAMPLE(invoked, uint32_t)
41 ✗ COMMAND_SAMPLE(failed, uint32_t)
42 ✗ COMMAND_SAMPLE(unknown, uint32_t)
43 ✗ COMMAND_SAMPLE(rejected, uint32_t)
44 ✗ COMMAND_SAMPLE(registered, uint16_t)
45
46 2 static void sample_echo(void *value)
47 {
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 *(uint8_t *)value = kfsw_command_echo_enabled() ? 1U : 0U;
49 2 }
50
51 10 static int validate_echo(const union kfsw_param_scalar *value)
52 {
53
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 return (value->u8 > 1U) ? -ERANGE : 0;
54 }
55
56 8 static void apply_echo(const union kfsw_param_scalar *value)
57 {
58 8 kfsw_command_set_echo(value->u8 != 0U);
59 8 }
60
61 /* Only with the remote path: without it there is no invocation to time out. */
62 #if CONFIG_KFSW_COMMAND_CSP
63 ✗ static void sample_timeout(void *value)
64 {
65 ✗ *(uint32_t *)value = kfsw_command_get_timeout_ms();
66 ✗ }
67
68 8 static int validate_timeout(const union kfsw_param_scalar *value)
69 {
70 8 return kfsw_command_check_timeout_ms(value->u32);
71 }
72
73 6 static void apply_timeout(const union kfsw_param_scalar *value)
74 {
75 6 (void)kfsw_command_set_timeout_ms(value->u32);
76 6 }
77 #endif
78
79 static const struct kfsw_param_definition command_param_definitions[] = {
80 {
81 .offset = 0x00U,
82 .type = KFSW_PARAM_U32,
83 .flags = KFSW_PARAM_FLAG_READ_ONLY,
84 .name = "cmd_invoked",
85 .description = "Recorded dispatch outcomes since boot; wraps at 2^32",
86 .value = &command_invoked,
87 .sample = sample_invoked,
88 },
89 {
90 .offset = 0x04U,
91 .type = KFSW_PARAM_U32,
92 .flags = KFSW_PARAM_FLAG_READ_ONLY,
93 .name = "cmd_failed",
94 .description = "Outcomes other than OK, UNKNOWN, DENIED; wraps at 2^32",
95 .value = &command_failed,
96 .sample = sample_failed,
97 },
98 {
99 .offset = 0x08U,
100 .type = KFSW_PARAM_U32,
101 .flags = KFSW_PARAM_FLAG_READ_ONLY,
102 .name = "cmd_unknown",
103 .description = "UNKNOWN outcomes since boot; wraps at 2^32",
104 .value = &command_unknown,
105 .sample = sample_unknown,
106 },
107 {
108 .offset = 0x0cU,
109 .type = KFSW_PARAM_U32,
110 .flags = KFSW_PARAM_FLAG_READ_ONLY,
111 .name = "cmd_rejected",
112 .description = "DENIED outcomes since boot; wraps at 2^32",
113 .value = &command_rejected,
114 .sample = sample_rejected,
115 },
116 {
117 .offset = 0x10U,
118 .type = KFSW_PARAM_U16,
119 .flags = KFSW_PARAM_FLAG_READ_ONLY,
120 .name = "cmd_registered",
121 .description = "Commands in the frozen registry",
122 .value = &command_registered,
123 .sample = sample_registered,
124 },
125 #if CONFIG_KFSW_COMMAND_CSP
126 {
127 .offset = 0x14U,
128 .type = KFSW_PARAM_U32,
129 .flags = KFSW_PARAM_FLAG_CONFIGURATION,
130 .name = "cmd_timeout_ms",
131 .unit = "ms",
132 .description = "Timeout for new remote invocations",
133 .value = &command_timeout_ms,
134 .default_value = {.u32 = CONFIG_KFSW_COMMAND_TIMEOUT_MS},
135 .validate = validate_timeout,
136 .changed = apply_timeout,
137 .sample = sample_timeout,
138 },
139 #endif
140 {
141 .offset = 0x18U,
142 .type = KFSW_PARAM_U8,
143 /* Off by default so scripted sessions don't show every command twice. */
144 .flags = KFSW_PARAM_FLAG_CONFIGURATION,
145 .name = "echo_enabled",
146 .description = "Console repeats what is typed at it",
147 .value = &command_echo_enabled,
148 .default_value = {.u8 = 0U},
149 .validate = validate_echo,
150 .changed = apply_echo,
151 .sample = sample_echo,
152 },
153 };
154
155 KFSW_PARAM_TABLE_FITS_THE_LINK(command_param_definitions);
156
157 const struct kfsw_param_definition_set kfsw_command_param_definitions = {
158 .table = KFSW_COMMAND_PARAM_TABLE_ID,
159 .name = KFSW_COMMAND_PARAM_TABLE_NAME,
160 .description = "Command counters, timeout and echo",
161 .definitions = command_param_definitions,
162 .count = ARRAY_SIZE(command_param_definitions),
163 };
164