5#include "sw/device/lib/base/status.h"
12const uint32_t MODULE_ID = 0;
14static const char *basename(
const char *file) {
20 while (f > file && f[-1] !=
'/' && f[-1] !=
'\\')
25status_t status_create(absl_status_t code, uint32_t module_id,
const char *file,
29 return (status_t){.value = arg};
50 const char *f = basename(file);
51 module_id = MAKE_MODULE_ID(f[0], f[1], f[2]);
55 .value = (int32_t)(module_id |
56 bitfield_bit32_write(0, STATUS_BIT_ERROR,
true) |
57 bitfield_field32_write(0, STATUS_FIELD_CODE, code) |
58 bitfield_field32_write(0, STATUS_FIELD_ARG,
62const char *status_codes[] = {
101bool status_extract(status_t s,
const char **code, int32_t *arg,
char *mod_id) {
102 size_t err = (size_t)status_err(s);
103 if (s.value < 0 && err == 0) {
104 err =
sizeof(status_codes) /
sizeof(status_codes[0]) - 1;
106 *code = status_codes[err];
108 *arg = (int32_t)bitfield_field32_read((uint32_t)s.value, STATUS_FIELD_ARG);
110 bitfield_field32_read((uint32_t)s.value, STATUS_FIELD_MODULE_ID);
111 *mod_id++ =
'@' + ((module_id >> 0) & 0x1F);
112 *mod_id++ =
'@' + ((module_id >> 5) & 0x1F);
113 *mod_id++ =
'@' + ((module_id >> 10) & 0x1F);
121extern bool status_ok(status_t s);
122extern absl_status_t status_err(status_t s);
128void status_report(status_t value) { (void)value; }