feat: enhance error handling and add device error reporting for radio operations

This commit is contained in:
2025-08-07 15:36:20 +08:00
parent 72299b62ce
commit 7637906efe
6 changed files with 101 additions and 47 deletions

View File

@ -6,6 +6,7 @@
#define LLCC68_DEFINITIONS_H
#include <cstdint>
#include <optional>
#include <sstream>
#include <string>
#include <format>
#include <tuple>
@ -348,20 +349,60 @@ union packet_status_t {
};
struct __attribute__((packed)) op_error_t {
bool RC64K_CALIB_ERR : 1; // RC64k calibration failed
bool RC13M_CALIB_ERR : 1; // RC13M calibration failed
bool PLL_CALIB_ERR : 1; // PLL calibration failed
bool ADC_CALIB_ERR : 1; // ADC calibration failed
bool IMG_CALIB_ERR : 1; // IMG calibration failed
bool XOSC_START_ERR : 1; // XOSC failed to start
bool PLL_LOCK_ERR : 1; // PLL failed to lock
uint8_t rfu_1 : 1; // RFU
bool PA_RAMP_ERR : 1; // PA ramping failed
uint8_t rfu_2 : 7; // RFU
};
struct __attribute__((packed)) DeviceErrors {
// LSB
static_assert(sizeof(op_error_t) == 2);
bool RC64K_CALIB_ERR : 1; // [0] RC64k calibration failed
bool RC13M_CALIB_ERR : 1; // [1] RkC13M calibration failed
bool PLL_CALIB_ERR : 1; // [2] PLL calibration failed
bool ADC_CALIB_ERR : 1; // [3] ADC calibration failed
bool IMG_CALIB_ERR : 1; // [4] IMG calibration failed
bool XOSC_START_ERR : 1; // [5] XOSC failed to start
bool PLL_LOCK_ERR : 1; // [6] PLL failed to lock
uint8_t rfu_1 : 1; // [7] RFU
bool PA_RAMP_ERR : 1; // [8] PA ramping failed
uint8_t rfu_2 : 7; // [15:9] RFU
// MSB
std::string to_string() const {
auto ss = std::stringstream();
ss << "DeviceErrors{";
if (RC64K_CALIB_ERR) {
ss << "RC64K_CALIB_ERR(0) ";
}
if (RC13M_CALIB_ERR) {
ss << "RC13M_CALIB_ERR(1) ";
}
if (PLL_CALIB_ERR) {
ss << "PLL_CALIB_ERR(2) ";
}
if (ADC_CALIB_ERR) {
ss << "ADC_CALIB_ERR(3) ";
}
if (IMG_CALIB_ERR) {
ss << "IMG_CALIB_ERR(4) ";
}
if (XOSC_START_ERR) {
ss << "XOSC_START_ERR(5) ";
}
if (PLL_LOCK_ERR) {
ss << "PLL_LOCK_ERR(6) ";
}
if (PA_RAMP_ERR) {
ss << "PA_RAMP_ERR(8) ";
}
ss << "}";
return ss.str();
}
[[nodiscard]]
bool has_any_error() const {
return RC64K_CALIB_ERR || RC13M_CALIB_ERR || PLL_CALIB_ERR || ADC_CALIB_ERR ||
IMG_CALIB_ERR || XOSC_START_ERR || PLL_LOCK_ERR || PA_RAMP_ERR;
}
};
static_assert(sizeof(DeviceErrors) == 2);
constexpr bool in_range(const auto v, const auto min, const auto max) {
return v >= min && v <= max;