Skip to content

Commit

Permalink
change to hexadecimal representation to include multiple flags
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Nov 22, 2024
1 parent df40cc8 commit ddaaa77
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void motor_hardware_seal_switch_interrupt();
* reset of the software.
* @return a string describing the reason for reset.
* */
char* motor_hardware_reset_reason();
uint16_t motor_hardware_reset_reason();

#ifdef __cplusplus
} // extern "C"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class MotorPolicy {
* reset of the software.
* @return a string describing the reason for reset.
* */
[[nodiscard]] auto last_reset_reason() const -> char*;
[[nodiscard]] auto last_reset_reason() const -> uint16_t;

/**
* @brief Call the seal callback function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ struct GetResetReason {
template <typename InputIt, typename InLimit>
requires std::forward_iterator<InputIt> &&
std::sized_sentinel_for<InputIt, InLimit>
static auto write_response_into(InputIt buf, InLimit limit, char* reason)
static auto write_response_into(InputIt buf, InLimit limit, uint16_t reason)
-> InputIt {
int res = 0;
res = snprintf(&*buf, (limit - buf),
"M114 Last Reset Reason: %s OK\n", reason);
// print a hexadecimal representation of the reset flags
res = snprintf(&*buf, (limit - buf), "M114 Last Reset Reason: %X OK\n",
reason);
if (res <= 0) {
return buf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ class HostCommsTask {
return errors::write_into(tx_into, tx_limit,
msg.with_error);
} else {
return cache_element.write_response_into(
tx_into, tx_limit);
return cache_element.write_response_into(tx_into, tx_limit);
}
},
cache_entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ struct GetResetReasonMessage {

struct GetResetReasonResponse {
uint32_t responding_to_id;
char* reason;
uint16_t reason;
};

struct OpenLidMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ static motor_hardware_t _motor_hardware = {
}
};

enum RCC_FLAGS {
NONE,
// high speed internal clock ready
HSIRDY, // = 1
// high speed external clock ready
HSERDY, // = 2
// main phase-locked loop clock ready
PLLRDY, // = 3
// hsi48 clock ready
HSI48RDY, // = 4
// low-speed external clock ready
LSERDY, // = 5
// lse clock security system failure
LSECSSD, // = 6
// low-speed internal clock ready
LSIRDY, // = 7
// brown out
BORRST, // = 8
// option byte-loader reset
OBLRST, // = 9
// pin reset
PINRST, // = 10
// software reset
SFTRST, // = 11
// independent watchdog
IWDGRST, // = 12
// window watchdog
WWDGRST, // = 13
// low power reset
LPWRRST, // = 14
};

// ----------------------------------------------------------------------------
// Local function declaration

Expand All @@ -194,7 +226,8 @@ static void init_tim2(TIM_HandleTypeDef* htim);
static void init_tim6(TIM_HandleTypeDef* htim);
static bool lid_active();
static void save_reset_reason();
static char* reset_reason;
//static char* reset_reason;
uint16_t reset_reason;

// ----------------------------------------------------------------------------
// Public function implementation
Expand Down Expand Up @@ -410,7 +443,7 @@ void motor_hardware_seal_switch_set_disarmed() {
_motor_hardware.seal.retraction_switch_armed = false;
}

char* motor_hardware_reset_reason() {
uint16_t motor_hardware_reset_reason() {
return reset_reason;
}

Expand Down Expand Up @@ -633,62 +666,63 @@ static bool lid_active() {
static void save_reset_reason() {
// check various reset flags to see if the HAL RCC
// reset flag matches any of them
reset_reason = 0;

// high speed internal clock ready
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) {
reset_reason = "hsi clock ready";
reset_reason |= HSIRDY;
}
// high speed external clock ready
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) {
reset_reason = "hse clock ready";
reset_reason |= HSERDY;
}
// main phase-locked loop clock ready
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY)) {
reset_reason = "pll clock ready";
reset_reason |= PLLRDY;
}
// hsi48 clock ready if applicable ?
// hsi48 clock ready
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY)) {
reset_reason = "hsi 48 clock ready";
reset_reason |= HSI48RDY;
}
// low-speed external clock ready
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY)) {
reset_reason = "lsi clock ready";
reset_reason |= LSERDY;
}
// lse clock security system failure
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSECSSD)) {
reset_reason = "lse security failure";
reset_reason |= LSECSSD;
}
// low-speed internal clock ready
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY)) {
reset_reason = "lsi clock ready";
reset_reason |= LSIRDY;
}
// brown out
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST)) {
reset_reason = "brown out";
reset_reason |= BORRST;
}
// option byte-loader reset
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_OBLRST)) {
reset_reason = "oblrst";
reset_reason |= OBLRST;
}
// pin reset ?
// pin reset
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) {
reset_reason = "pin reset";
reset_reason |= PINRST;
}
// software reset
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) {
reset_reason = "software reset";
reset_reason |= SFTRST;
}
// independent watchdog
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) {
reset_reason = "independent watchdog";
reset_reason |= IWDGRST;
}
// window watchdog
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)) {
reset_reason = "window watchdog";
reset_reason |= WWDGRST;
}
// low power reset
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST)) {
reset_reason = "low power";
reset_reason |= LPWRRST;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ auto MotorPolicy::seal_switch_set_disarmed() -> void {
}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
[[nodiscard]] auto MotorPolicy::last_reset_reason() const -> char* {
[[nodiscard]] auto MotorPolicy::last_reset_reason() const -> uint16_t {
return motor_hardware_reset_reason();
}

0 comments on commit ddaaa77

Please sign in to comment.