Skip to content

Commit 45c5776

Browse files
committed
feat: error codes as a list
1 parent bb85369 commit 45c5776

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

include/esp-stub-lib/err.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66

77
#pragma once
88

9-
typedef int stub_lib_err_t;
9+
// Limit error code range for stub-lib
10+
#define STUB_LIB_ERR_END 0x100000
1011

11-
#define STUB_LIB_OK 0 // stub_lib_err_t value indicating success (no error)
12-
#define STUB_LIB_FAIL -1 // Generic stub_lib_err_t code indicating failure
12+
#define STUB_LIB_ERROR_CODE_LIST \
13+
X(STUB_LIB_OK, 0, "Operation esp-stub-lib success") \
14+
X(STUB_LIB_FAIL, (STUB_LIB_ERR_END - 1), "Generic esp-stub-lib failure") \
15+
\
16+
X(STUB_LIB_ERR_FLASH_INIT_UNKNOWN_FLASH_ID, 0x1000, "Unknown flash size, unknown flash id") \
17+
18+
// Only numerical values, used in esp-stub-lib sources
19+
20+
#define X(code_, value_, info_) code_ = value_,
21+
typedef enum stub_lib_err_codes {
22+
STUB_LIB_ERROR_CODE_LIST
23+
} stub_lib_err_t;
24+
#undef X

src/flash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ stub_lib_err_t stub_lib_flash_init(void **state)
1616
uint32_t flash_id = stub_target_flash_get_flash_id();
1717
uint32_t flash_size = stub_target_flash_id_to_flash_size(flash_id);
1818
if (flash_size == 0) {
19-
STUB_LOGE("Invalid flash size: 0\n");
20-
return STUB_LIB_FAIL;
19+
return STUB_LIB_ERR_FLASH_INIT_UNKNOWN_FLASH_ID;
2120
}
2221
STUB_LOG_TRACEF("Flash size: %d MB\n", flash_size / (1024 * 1024));
2322

src/target/common/src/flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ uint32_t stub_target_flash_id_to_flash_size(uint32_t flash_id)
4545
return 32 * 1024 * 1024;
4646
}
4747

48-
STUB_LOGE("Unknown flash_id: 0x%x", flash_id);
48+
STUB_LOGE("Unknown flash_id: 0x%x\n", flash_id);
4949
return 0;
5050
}

0 commit comments

Comments
 (0)