From ca7229bb45901a7abc2f7acf9294fc884f6968f2 Mon Sep 17 00:00:00 2001 From: Cantonplas Date: Sun, 15 Feb 2026 12:00:29 +0100 Subject: [PATCH 1/3] No more time_get_global_tick --- Inc/HALAL/Services/Time/Scheduler.hpp | 4 ++-- Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp | 4 ++-- Src/HALAL/Services/Communication/SPI/SPI.cpp | 5 +++-- Src/HALAL/Services/Time/Time.cpp | 14 +------------- Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp | 9 +++++---- Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp | 3 ++- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Inc/HALAL/Services/Time/Scheduler.hpp b/Inc/HALAL/Services/Time/Scheduler.hpp index 74c5759a2..4f8459e80 100644 --- a/Inc/HALAL/Services/Time/Scheduler.hpp +++ b/Inc/HALAL/Services/Time/Scheduler.hpp @@ -9,7 +9,7 @@ /* Uso del scheduler, descrito en la wiki: * https://wiki.hyperloopupv.com/es/firmware/Timing/Scheduler */ -#include "stm32h7xx_ll_tim_wrapper.h" +#include "stm32h7xx_ll_tim_wrapper.h" #include #include @@ -39,7 +39,7 @@ struct Scheduler { static void start(); static void update(); - static inline uint64_t get_global_tick(); + static inline uint64_t get_global_tick() { return global_tick_us_; } static uint16_t register_task(uint32_t period_us, callback_t func); static bool unregister_task(uint16_t id); diff --git a/Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp b/Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp index 392bbee9c..6428e6101 100644 --- a/Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp +++ b/Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp @@ -7,8 +7,8 @@ #pragma once -// #include "Protections/Protection.hpp" -// #include "Protections/ProtectionManager.hpp" +#include "Protections/Protection.hpp" +#include "Protections/ProtectionManager.hpp" #include "Control/ControlBlock.hpp" #include "Control/FeedbackControlBlock.hpp" #include "Control/SplitterBlock.hpp" diff --git a/Src/HALAL/Services/Communication/SPI/SPI.cpp b/Src/HALAL/Services/Communication/SPI/SPI.cpp index 9b498b12b..208990baa 100644 --- a/Src/HALAL/Services/Communication/SPI/SPI.cpp +++ b/Src/HALAL/Services/Communication/SPI/SPI.cpp @@ -6,6 +6,7 @@ */ #include "HALAL/Services/Communication/SPI/SPI.hpp" +#include "HALAL/Services/Time/Scheduler.hpp" #include "HALAL/Models/MPUManager/MPUManager.hpp" @@ -461,12 +462,12 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef* hspi) { spi->try_count++; switch (*(spi->available_end)) { case NO_ORDER_ID: { - spi->last_end_check = Time::get_global_tick(); + spi->last_end_check = Scheduler::get_global_tick(); SPI::turn_on_chip_select(spi); } break; default: case ERROR_ORDER_ID: { - spi->last_end_check = Time::get_global_tick(); + spi->last_end_check = Scheduler::get_global_tick(); spi->error_count++; SPI::turn_on_chip_select(spi); } break; diff --git a/Src/HALAL/Services/Time/Time.cpp b/Src/HALAL/Services/Time/Time.cpp index 7700a2db0..8737284af 100644 --- a/Src/HALAL/Services/Time/Time.cpp +++ b/Src/HALAL/Services/Time/Time.cpp @@ -126,19 +126,7 @@ void Time::hal_enable_timer(TIM_HandleTypeDef* tim) { } } -// PUBLIC SERVICE METHODS - -uint64_t Time::get_global_tick() { - if (global_timer == nullptr) { - ErrorHandler( - "tried to use global tick without global timer configured"); - return 0; - } - uint64_t current_tick = Time::global_tick + global_timer->Instance->CNT; - uint32_t apb1_tim_freq = HAL_RCC_GetPCLK1Freq() * 2; - double to_nanoseconds = 1.0 / apb1_tim_freq * 1000000000.0; - return current_tick * to_nanoseconds; -} +// PUBLIC SERVICE METHOD void Time::start_timer(TIM_HandleTypeDef* handle, uint32_t prescaler, uint32_t arr) { diff --git a/Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp b/Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp index 0f93b1378..5bef4da79 100644 --- a/Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp +++ b/Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp @@ -1,6 +1,7 @@ #include "Protections/ProtectionManager.hpp" #include "HALAL/Services/Communication/FDCAN/FDCAN.hpp" +#include "HALAL/Services/Time/Scheduler.hpp" #include "Protections/Notification.hpp" @@ -86,9 +87,9 @@ void ProtectionManager::check_protections() { ProtectionManager::to_fault(); } Global_RTC::update_rtc_data(); - if(Time::get_global_tick() > protection.get_last_notify_tick() + notify_delay_in_nanoseconds) { + if(Scheduler::get_global_tick() > protection.get_last_notify_tick() + notify_delay_in_nanoseconds) { ProtectionManager::notify(protection); - protection.update_last_notify_tick(Time::get_global_tick()); + protection.update_last_notify_tick(Scheduler::get_global_tick()); } } } @@ -106,9 +107,9 @@ void ProtectionManager::check_high_frequency_protections() { ProtectionManager::to_fault(); } Global_RTC::update_rtc_data(); - if(Time::get_global_tick() > protection.get_last_notify_tick() + notify_delay_in_nanoseconds) { + if(Scheduler::get_global_tick() > protection.get_last_notify_tick() + notify_delay_in_nanoseconds) { ProtectionManager::notify(protection); - protection.update_last_notify_tick(Time::get_global_tick()); + protection.update_last_notify_tick(Scheduler::get_global_tick()); } } } diff --git a/Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp b/Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp index 93ccc0300..18e44ed91 100644 --- a/Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp +++ b/Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp @@ -6,6 +6,7 @@ */ #include "ErrorHandler/ErrorHandler.hpp" +#include "HALAL/Services/Time/Scheduler.hpp" string ErrorHandlerModel::description = "Error-No-Description-Found"; string ErrorHandlerModel::line = "Error-No-Line-Found"; @@ -48,7 +49,7 @@ void ErrorHandlerModel::ErrorHandlerTrigger(string format, ... ){ + " Function: '" + ErrorHandlerModel::func + "' File: " + ErrorHandlerModel::file ; #ifdef HAL_TIM_MODULE_ENABLED - description += " | TimeStamp: " + to_string(Time::get_global_tick()); + description += " | TimeStamp: " + to_string(Scheduler::get_global_tick()); #endif } From ceed6c91710a281a9aa651f900f19a54a47df951 Mon Sep 17 00:00:00 2001 From: victhor Date: Sun, 15 Feb 2026 14:16:29 +0100 Subject: [PATCH 2/3] Add eof whitespace (?) --- Inc/HALAL/Services/EXTI/EXTI.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Inc/HALAL/Services/EXTI/EXTI.hpp b/Inc/HALAL/Services/EXTI/EXTI.hpp index 77daaefd2..83bef263d 100644 --- a/Inc/HALAL/Services/EXTI/EXTI.hpp +++ b/Inc/HALAL/Services/EXTI/EXTI.hpp @@ -149,4 +149,4 @@ struct EXTIDomain { } // namespace ST_LIB -#endif // EXTI_HPP \ No newline at end of file +#endif // EXTI_HPP From 6f859993560c0a68c50a89ba3a8a9988bc4dc692 Mon Sep 17 00:00:00 2001 From: victhor Date: Sun, 15 Feb 2026 14:18:55 +0100 Subject: [PATCH 3/3] NewEncoder -> Encoder --- Inc/HALAL/HALAL.hpp | 2 +- Inc/HALAL/Services/Encoder/{NewEncoder.hpp => Encoder.hpp} | 0 Inc/HALAL/Services/Time/TimerWrapper.hpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename Inc/HALAL/Services/Encoder/{NewEncoder.hpp => Encoder.hpp} (100%) diff --git a/Inc/HALAL/HALAL.hpp b/Inc/HALAL/HALAL.hpp index 0d0d7c9de..bd26e7d0d 100644 --- a/Inc/HALAL/HALAL.hpp +++ b/Inc/HALAL/HALAL.hpp @@ -27,7 +27,7 @@ // #include "HALAL/Services/Encoder/Encoder.hpp" #include "HALAL/Services/EXTI/EXTI.hpp" -#include "HALAL/Services/Encoder/NewEncoder.hpp" +#include "HALAL/Services/Encoder/Encoder.hpp" // #include "HALAL/Services/InputCapture/InputCapture.hpp" // To be implemented #include "HALAL/Services/Communication/FDCAN/FDCAN.hpp" diff --git a/Inc/HALAL/Services/Encoder/NewEncoder.hpp b/Inc/HALAL/Services/Encoder/Encoder.hpp similarity index 100% rename from Inc/HALAL/Services/Encoder/NewEncoder.hpp rename to Inc/HALAL/Services/Encoder/Encoder.hpp diff --git a/Inc/HALAL/Services/Time/TimerWrapper.hpp b/Inc/HALAL/Services/Time/TimerWrapper.hpp index 70a13f5f5..0a81056a9 100644 --- a/Inc/HALAL/Services/Time/TimerWrapper.hpp +++ b/Inc/HALAL/Services/Time/TimerWrapper.hpp @@ -12,7 +12,7 @@ #ifdef HAL_TIM_MODULE_ENABLED #include "HALAL/Models/TimerDomain/TimerDomain.hpp" -#include "HALAL/Services/Encoder/NewEncoder.hpp" +#include "HALAL/Services/Encoder/Encoder.hpp" #include "HALAL/Services/PWM/DualPWM.hpp" #include "HALAL/Services/PWM/PWM.hpp" #include "HALAL/Models/GPIO.hpp"