kfsw-services/src/table-parameters/table_parameters.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <stdint.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | #include <zephyr/sys/util.h> | ||
| 5 | |||
| 6 | #include <kfsw/services/parameter.h> | ||
| 7 | #include <kfsw/services/table.h> | ||
| 8 | |||
| 9 | static uint32_t table_loads; | ||
| 10 | static uint32_t table_rejections; | ||
| 11 | static uint32_t table_reverts; | ||
| 12 | static uint16_t table_entries; | ||
| 13 | static uint8_t table_state; | ||
| 14 | static uint8_t table_table; | ||
| 15 | static char table_path[KFSW_TABLE_PATH_SIZE]; | ||
| 16 | |||
| 17 | ✗ | static void sample_state(void) | |
| 18 | { | ||
| 19 | struct kfsw_table_status status; | ||
| 20 | |||
| 21 | ✗ | (void)kfsw_table_get_status(&status); | |
| 22 | ✗ | table_loads = status.loads; | |
| 23 | ✗ | table_rejections = status.rejections; | |
| 24 | ✗ | table_reverts = status.reverts; | |
| 25 | ✗ | table_entries = status.entries; | |
| 26 | ✗ | table_state = status.state; | |
| 27 | ✗ | table_table = status.table; | |
| 28 | ✗ | (void)strncpy(table_path, status.path, sizeof(table_path) - 1U); | |
| 29 | ✗ | table_path[sizeof(table_path) - 1U] = '\0'; | |
| 30 | ✗ | } | |
| 31 | |||
| 32 | ✗ | static void sample_loads(void *value) | |
| 33 | { | ||
| 34 | ✗ | sample_state(); | |
| 35 | ✗ | *(uint32_t *)value = table_loads; | |
| 36 | ✗ | } | |
| 37 | |||
| 38 | ✗ | static void sample_rejections(void *value) | |
| 39 | { | ||
| 40 | ✗ | sample_state(); | |
| 41 | ✗ | *(uint32_t *)value = table_rejections; | |
| 42 | ✗ | } | |
| 43 | |||
| 44 | ✗ | static void sample_reverts(void *value) | |
| 45 | { | ||
| 46 | ✗ | sample_state(); | |
| 47 | ✗ | *(uint32_t *)value = table_reverts; | |
| 48 | ✗ | } | |
| 49 | |||
| 50 | ✗ | static void sample_entries(void *value) | |
| 51 | { | ||
| 52 | ✗ | sample_state(); | |
| 53 | ✗ | *(uint16_t *)value = table_entries; | |
| 54 | ✗ | } | |
| 55 | |||
| 56 | ✗ | static void sample_table_state(void *value) | |
| 57 | { | ||
| 58 | ✗ | sample_state(); | |
| 59 | ✗ | *(uint8_t *)value = table_state; | |
| 60 | ✗ | } | |
| 61 | |||
| 62 | ✗ | static void sample_table(void *value) | |
| 63 | { | ||
| 64 | ✗ | sample_state(); | |
| 65 | ✗ | *(uint8_t *)value = table_table; | |
| 66 | ✗ | } | |
| 67 | |||
| 68 | ✗ | static void sample_path(void *value) | |
| 69 | { | ||
| 70 | ✗ | sample_state(); | |
| 71 | ✗ | (void)strncpy((char *)value, table_path, sizeof(table_path) - 1U); | |
| 72 | ✗ | ((char *)value)[sizeof(table_path) - 1U] = '\0'; | |
| 73 | ✗ | } | |
| 74 | |||
| 75 | static const struct kfsw_param_definition table_param_definitions[] = { | ||
| 76 | { | ||
| 77 | .offset = 0x00U, | ||
| 78 | .type = KFSW_PARAM_U8, | ||
| 79 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 80 | .name = "table_state", | ||
| 81 | .description = "Whether a file is loaded and can still be reverted", | ||
| 82 | .value = &table_state, | ||
| 83 | .default_value = {.u8 = (uint8_t)KFSW_TABLE_EMPTY}, | ||
| 84 | .sample = sample_table_state, | ||
| 85 | }, | ||
| 86 | { | ||
| 87 | .offset = 0x01U, | ||
| 88 | .type = KFSW_PARAM_U8, | ||
| 89 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 90 | .name = "table_last", | ||
| 91 | .description = "Parameter table the last loaded file addressed", | ||
| 92 | .value = &table_table, | ||
| 93 | .default_value = {.u8 = 0U}, | ||
| 94 | .sample = sample_table, | ||
| 95 | }, | ||
| 96 | { | ||
| 97 | .offset = 0x02U, | ||
| 98 | .type = KFSW_PARAM_U16, | ||
| 99 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 100 | .name = "table_entries", | ||
| 101 | .description = "Entries the last loaded file carried", | ||
| 102 | .value = &table_entries, | ||
| 103 | .default_value = {.u16 = 0U}, | ||
| 104 | .sample = sample_entries, | ||
| 105 | }, | ||
| 106 | { | ||
| 107 | .offset = 0x04U, | ||
| 108 | .type = KFSW_PARAM_U32, | ||
| 109 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 110 | .name = "table_loads", | ||
| 111 | .description = "Files adopted since boot", | ||
| 112 | .value = &table_loads, | ||
| 113 | .default_value = {.u32 = 0U}, | ||
| 114 | .sample = sample_loads, | ||
| 115 | }, | ||
| 116 | { | ||
| 117 | .offset = 0x08U, | ||
| 118 | .type = KFSW_PARAM_U32, | ||
| 119 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 120 | .name = "table_rejections", | ||
| 121 | .description = "Files refused since boot", | ||
| 122 | .value = &table_rejections, | ||
| 123 | .default_value = {.u32 = 0U}, | ||
| 124 | .sample = sample_rejections, | ||
| 125 | }, | ||
| 126 | { | ||
| 127 | .offset = 0x0cU, | ||
| 128 | .type = KFSW_PARAM_U32, | ||
| 129 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 130 | .name = "table_reverts", | ||
| 131 | .description = "Loads undone since boot", | ||
| 132 | .value = &table_reverts, | ||
| 133 | .default_value = {.u32 = 0U}, | ||
| 134 | .sample = sample_reverts, | ||
| 135 | }, | ||
| 136 | { | ||
| 137 | .offset = 0x10U, | ||
| 138 | .type = KFSW_PARAM_STRING, | ||
| 139 | .capacity = KFSW_TABLE_PATH_SIZE, | ||
| 140 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 141 | .name = "table_path", | ||
| 142 | .description = "File of the last adopted load", | ||
| 143 | .value = table_path, | ||
| 144 | .sample = sample_path, | ||
| 145 | }, | ||
| 146 | }; | ||
| 147 | |||
| 148 | KFSW_PARAM_TABLE_FITS_THE_LINK(table_param_definitions); | ||
| 149 | |||
| 150 | const struct kfsw_param_definition_set kfsw_table_param_definitions = { | ||
| 151 | .table = KFSW_TABLE_PARAM_TABLE_ID, | ||
| 152 | .name = KFSW_TABLE_PARAM_TABLE_NAME, | ||
| 153 | .description = "Uploaded table files, adoptions and reverts", | ||
| 154 | .definitions = table_param_definitions, | ||
| 155 | .count = ARRAY_SIZE(table_param_definitions), | ||
| 156 | }; | ||
| 157 |