diff --git a/stm32-modules/include/tempdeck-gen3/firmware/thermal_hardware.h b/stm32-modules/include/tempdeck-gen3/firmware/thermal_hardware.h index 1d0e3485b..f0f473cfa 100644 --- a/stm32-modules/include/tempdeck-gen3/firmware/thermal_hardware.h +++ b/stm32-modules/include/tempdeck-gen3/firmware/thermal_hardware.h @@ -18,13 +18,6 @@ extern "C" { */ void thermal_hardware_init(); -/** - * @brief Reports the reason for the last fimrware reset, according to - * the HAL RCC flag. - * - * */ -uint16_t thermal_hardware_reset_reason(); - /** * @brief Enable the peltiers. If the peltiers are already enabled, * this will have no real effect. diff --git a/stm32-modules/include/tempdeck-gen3/firmware/thermal_policy.hpp b/stm32-modules/include/tempdeck-gen3/firmware/thermal_policy.hpp index f3ae230d4..aceb5d2aa 100644 --- a/stm32-modules/include/tempdeck-gen3/firmware/thermal_policy.hpp +++ b/stm32-modules/include/tempdeck-gen3/firmware/thermal_policy.hpp @@ -19,8 +19,6 @@ class ThermalPolicy { auto disable_peltier() -> void; - auto last_reset_reason() -> uint16_t; - auto set_peltier_heat_power(double power) -> bool; auto set_peltier_cool_power(double power) -> bool; diff --git a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/gcodes.hpp b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/gcodes.hpp index e4d620bad..d9db97200 100644 --- a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/gcodes.hpp +++ b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/gcodes.hpp @@ -101,44 +101,6 @@ struct GetSystemInfo { } }; -struct GetResetReason { - /* - * M114- GetResetReason retrieves the value of the RCC reset flag - * that was captured at the beginning of the hardware setup - * */ - using ParseResult = std::optional; - static constexpr auto prefix = std::array{'M', '1', '1', '4'}; - - template - requires std::forward_iterator && - std::sized_sentinel_for - static auto write_response_into(InputIt buf, InLimit limit, uint16_t reason) - -> InputIt { - int res = 0; - // 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; - } - return buf + res; - } - template - requires std::forward_iterator && - std::sized_sentinel_for - static auto parse(const InputIt& input, Limit limit) - -> std::pair { - auto working = prefix_matches(input, limit, prefix); - if (working == input) { - return std::make_pair(ParseResult(), input); - } - if (working != limit && !std::isspace(*working)) { - return std::make_pair(ParseResult(), input); - } - return std::make_pair(ParseResult(GetResetReason()), working); - } -}; - struct SetSerialNumber { using ParseResult = std::optional; static constexpr auto prefix = std::array{'M', '9', '9', '6'}; diff --git a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/host_comms_task.hpp b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/host_comms_task.hpp index d8b1a43dd..b179626bd 100644 --- a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/host_comms_task.hpp +++ b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/host_comms_task.hpp @@ -31,14 +31,12 @@ class HostCommsTask { using Aggregator = typename tasks::Tasks::QueueAggregator; private: - using GCodeParser = - gcode::GroupParser; + using GCodeParser = gcode::GroupParser< + gcode::GetSystemInfo, gcode::EnterBootloader, gcode::SetSerialNumber, + gcode::GetTemperatureDebug, gcode::SetTemperature, gcode::DeactivateAll, + gcode::SetPeltierDebug, gcode::SetFanManual, gcode::SetFanAutomatic, + gcode::SetPIDConstants, gcode::SetOffsetConstants, + gcode::GetOffsetConstants, gcode::GetThermalPowerDebug>; using AckOnlyCache = // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) AckCache<10, gcode::EnterBootloader, gcode::SetSerialNumber, @@ -50,7 +48,6 @@ class HostCommsTask { using GetTempDebugCache = AckCache<4, gcode::GetTemperatureDebug>; using GetOffsetConstantsCache = AckCache<4, gcode::GetOffsetConstants>; using GetThermalPowerDebugCache = AckCache<4, gcode::GetThermalPowerDebug>; - using GetResetReasonCache = AckCache<8, gcode::GetResetReason>; public: static constexpr size_t TICKS_TO_WAIT_ON_SEND = 10; @@ -67,9 +64,7 @@ class HostCommsTask { // NOLINTNEXTLINE(readability-redundant-member-init) get_offset_constants_cache(), // NOLINTNEXTLINE(readability-redundant-member-init) - get_thermal_power_debug_cache(), - // NOLINTNEXTLINE(readability-redundant-member-init) - get_reset_reason_cache() {} + get_thermal_power_debug_cache() {} HostCommsTask(const HostCommsTask& other) = delete; auto operator=(const HostCommsTask& other) -> HostCommsTask& = delete; HostCommsTask(HostCommsTask&& other) noexcept = delete; @@ -271,28 +266,6 @@ class HostCommsTask { cache_entry); } - template - requires std::forward_iterator && - std::sized_sentinel_for - auto visit_message(const messages::GetResetReasonResponse& response, - InputIt tx_into, InputLimit tx_limit) -> InputIt { - auto cache_entry = - get_reset_reason_cache.remove_if_present(response.responding_to_id); - return std::visit( - [tx_into, tx_limit, response](auto cache_element) { - using T = std::decay_t; - if constexpr (std::is_same_v) { - return errors::write_into( - tx_into, tx_limit, - errors::ErrorCode::BAD_MESSAGE_ACKNOWLEDGEMENT); - } else { - return cache_element.write_response_into(tx_into, tx_limit, - response.reason); - } - }, - cache_entry); - } - template requires std::forward_iterator && std::sized_sentinel_for @@ -425,27 +398,6 @@ class HostCommsTask { return std::make_pair(true, tx_into); } - template - requires std::forward_iterator && - std::sized_sentinel_for - auto visit_gcode(const gcode::GetResetReason& gcode, InputIt tx_into, - InputLimit tx_limit) -> std::pair { - auto id = get_reset_reason_cache.add(gcode); - if (id == 0) { - return std::make_pair( - false, errors::write_into(tx_into, tx_limit, - errors::ErrorCode::GCODE_CACHE_FULL)); - } - auto message = messages::GetResetReasonMessage{.id = id}; - if (!task_registry->send(message, TICKS_TO_WAIT_ON_SEND)) { - auto wrote_to = errors::write_into( - tx_into, tx_limit, errors::ErrorCode::INTERNAL_QUEUE_FULL); - get_reset_reason_cache.remove_if_present(id); - return std::make_pair(false, wrote_to); - } - return std::make_pair(true, tx_into); - } - template requires std::forward_iterator && std::sized_sentinel_for @@ -705,7 +657,6 @@ class HostCommsTask { GetTempDebugCache get_temp_debug_cache; GetOffsetConstantsCache get_offset_constants_cache; GetThermalPowerDebugCache get_thermal_power_debug_cache; - GetResetReasonCache get_reset_reason_cache; bool may_connect_latch = true; }; diff --git a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/messages.hpp b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/messages.hpp index 74c86360e..c6bc7d9a2 100644 --- a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/messages.hpp +++ b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/messages.hpp @@ -89,15 +89,6 @@ struct EnterBootloaderMessage { uint32_t id; }; -struct GetResetReasonMessage { - uint32_t id; -}; - -struct GetResetReasonResponse { - uint32_t responding_to_id; - uint16_t reason; -}; - struct ForceUSBDisconnect { uint32_t id; size_t return_address; @@ -183,7 +174,7 @@ using HostCommsMessage = ::std::variant; + GetThermalPowerDebugResponse>; using SystemMessage = ::std::variant; @@ -194,5 +185,5 @@ using ThermalMessage = SetFanAutomaticMessage, DeactivateAllMessage, SetTemperatureMessage, SetPIDConstantsMessage, GetOffsetConstantsMessage, SetOffsetConstantsMessage, - GetThermalPowerDebugMessage, GetResetReasonMessage>; + GetThermalPowerDebugMessage>; }; // namespace messages diff --git a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/thermal_task.hpp b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/thermal_task.hpp index 40b4f8e4b..2360bbddb 100644 --- a/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/thermal_task.hpp +++ b/stm32-modules/include/tempdeck-gen3/tempdeck-gen3/thermal_task.hpp @@ -448,17 +448,6 @@ class ThermalTask { _task_registry->send_to_address(response, Queues::HostAddress)); } - template - auto visit_message(const messages::GetResetReasonMessage& msg, - Policy& policy) -> void { - auto reason = policy.last_reset_reason(); - - auto response = messages::GetResetReasonResponse{ - .responding_to_id = msg.id, .reason = reason}; - static_cast( - _task_registry->send_to_address(response, Queues::HostAddress)); - } - /** * @brief Updates control of the peltier and fan based off of the current * state of the system. diff --git a/stm32-modules/include/tempdeck-gen3/test/test_thermal_policy.hpp b/stm32-modules/include/tempdeck-gen3/test/test_thermal_policy.hpp index caf6a101d..b30289284 100644 --- a/stm32-modules/include/tempdeck-gen3/test/test_thermal_policy.hpp +++ b/stm32-modules/include/tempdeck-gen3/test/test_thermal_policy.hpp @@ -34,12 +34,6 @@ struct TestThermalPolicy : public m24128_test_policy::TestM24128Policy { return true; } - auto last_reset_reason() -> uint16_t { return _reset_reason; } - - auto set_last_reset_reason(uint16_t sim_reason) { - _reset_reason = sim_reason; - } - auto get_fan_rpm() -> double { return _fan_rpm; } // Test integration functions @@ -54,5 +48,4 @@ struct TestThermalPolicy : public m24128_test_policy::TestM24128Policy { double _power = 0.0F; // Positive for heat, negative for cool double _fans = 0.0F; double _fan_rpm = 0.0F; // Should be manually set by the test code - uint16_t _reset_reason = 0; }; diff --git a/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_hardware.c b/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_hardware.c index 9aa6f17f8..5861dd46b 100644 --- a/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_hardware.c +++ b/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_hardware.c @@ -80,38 +80,6 @@ static struct thermal_hardware hardware = { .hot_side_power = 0.0F, }; -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 -}; - // *************************************************************************** // Static function declaration @@ -128,13 +96,10 @@ static void init_fan_timer(); */ static void init_gpio(); -static void save_reset_reason(); - // *************************************************************************** // Public function implementation void thermal_hardware_init() { - save_reset_reason(); if(!hardware.initialized) { init_gpio(); init_peltier_timer(); @@ -148,12 +113,6 @@ void thermal_hardware_init() { } } -uint16_t reset_reason; - -uint16_t thermal_hardware_reset_reason() { - return reset_reason; -} - void thermal_hardware_enable_peltiers() { if(!hardware.initialized) { return; @@ -389,66 +348,3 @@ static void init_gpio() { init.Pin = EEPROM_WP_PIN; HAL_GPIO_Init(EEPROM_WP_PORT, &init); } - -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 |= HSIRDY; - } - // high speed external clock ready - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) { - reset_reason |= HSERDY; - } - // main phase-locked loop clock ready - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY)) { - reset_reason |= PLLRDY; - } - // hsi48 clock ready - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) { - reset_reason |= HSI48RDY; - } - // low-speed external clock ready - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY)) { - reset_reason |= LSERDY; - } - // lse clock security system failure - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY)) { - reset_reason |= LSECSSD; - } - // low-speed internal clock ready - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY)) { - reset_reason |= LSIRDY; - } - // brown out - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST)) { - reset_reason |= BORRST; - } - // option byte-loader reset - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_OBLRST)) { - reset_reason |= OBLRST; - } - // pin reset - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) { - reset_reason |= PINRST; - } - // software reset - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) { - reset_reason |= SFTRST; - } - // independent watchdog - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) { - reset_reason |= IWDGRST; - } - // window watchdog - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)) { - reset_reason |= WWDGRST; - } - // low power reset - else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST)) { - reset_reason |= LPWRRST; - } -} diff --git a/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_policy.cpp b/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_policy.cpp index 4e603cb35..9581facb4 100644 --- a/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_policy.cpp +++ b/stm32-modules/tempdeck-gen3/firmware/thermal_control/thermal_policy.cpp @@ -15,11 +15,6 @@ auto ThermalPolicy::disable_peltier() -> void { thermal_hardware_disable_peltiers(); } -// NOLINTNEXTLINE(readability-convert-member-functions-to-static) -auto ThermalPolicy::last_reset_reason() -> uint16_t { - return thermal_hardware_reset_reason(); -} - // NOLINTNEXTLINE(readability-convert-member-functions-to-static) auto ThermalPolicy::set_peltier_heat_power(double power) -> bool { return thermal_hardware_set_peltier_heat(power);