25#ifndef HF_TIMESTAMP_US_T_DEFINED
26#define HF_TIMESTAMP_US_T_DEFINED
45#define HF_TIMER_ERR_LIST(X) \
47 X(TIMER_SUCCESS, 0, "Success") \
49 X(TIMER_ERR_FAILURE, 1, "General failure") \
50 X(TIMER_ERR_NOT_INITIALIZED, 2, "Not initialized") \
51 X(TIMER_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
52 X(TIMER_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
53 X(TIMER_ERR_NULL_POINTER, 5, "Null pointer") \
54 X(TIMER_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
56 X(TIMER_ERR_ALREADY_RUNNING, 7, "Timer already running") \
57 X(TIMER_ERR_NOT_RUNNING, 8, "Timer not running") \
58 X(TIMER_ERR_INVALID_PERIOD, 9, "Invalid period") \
59 X(TIMER_ERR_RESOURCE_BUSY, 10, "Timer resource busy") \
60 X(TIMER_ERR_HARDWARE_FAULT, 11, "Timer hardware fault") \
61 X(TIMER_ERR_UNSUPPORTED_OPERATION, 12, "Unsupported operation") \
62 X(TIMER_ERR_UNKNOWN, 13, "Unknown error")
66#define X(name, value, desc) name = value,
78#define X(NAME, VALUE, DESC) \
79 case hf_timer_err_t::NAME: \
hf_timer_err_t
Definition BasePeriodicTimer.h:65
@ TIMER_ERR_UNSUPPORTED_OPERATION
@ TIMER_ERR_ALREADY_RUNNING
void(*)(void *user_data) hf_timer_callback_t
Timer callback function type.
Definition BasePeriodicTimer.h:146
constexpr std::string_view HfTimerErrToString(hf_timer_err_t err) noexcept
Convert timer error code to string view.
Definition BasePeriodicTimer.h:76
#define HF_TIMER_ERR_LIST(X)
HardFOC Timer error codes.
Definition BasePeriodicTimer.h:45
hf_u64_t hf_timestamp_us_t
Definition BasePeriodicTimer.h:27
#define X(name, value, desc)
Definition BasePeriodicTimer.h:66
Platform-agnostic hardware type definitions for the HardFOC system.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
int32_t hf_i32_t
Platform-agnostic 32-bit signed integer type.
Definition HardwareTypes.h:76
uint64_t hf_u64_t
Platform-agnostic 64-bit unsigned integer type.
Definition HardwareTypes.h:58
Abstract base class for periodic timer operations.
Definition BasePeriodicTimer.h:168
virtual hf_timer_err_t GetStatistics(hf_timer_statistics_t &statistics) const noexcept
Get timer operation statistics.
Definition BasePeriodicTimer.h:334
hf_timer_err_t SetCallback(hf_timer_callback_t callback, void *user_data=nullptr) noexcept
Set new callback function.
Definition BasePeriodicTimer.h:288
virtual hf_timer_err_t SetPeriod(hf_u64_t period_us) noexcept=0
Change the timer period while running.
BasePeriodicTimer(hf_timer_callback_t callback, void *user_data=nullptr) noexcept
Protected constructor with callback specification.
Definition BasePeriodicTimer.h:355
void SetRunning(bool running) noexcept
Set the running state.
Definition BasePeriodicTimer.h:371
hf_timer_diagnostics_t diagnostics_
Timer diagnostic information.
Definition BasePeriodicTimer.h:397
virtual hf_timer_err_t GetDiagnostics(hf_timer_diagnostics_t &diagnostics) const noexcept
Get timer diagnostic information.
Definition BasePeriodicTimer.h:344
bool initialized_
Initialization state flag.
Definition BasePeriodicTimer.h:394
virtual hf_u64_t GetResolution() const noexcept=0
Get timer resolution.
bool IsRunning() const noexcept
Check if timer is currently running.
Definition BasePeriodicTimer.h:254
void SetInitialized(bool initialized) noexcept
Set the initialized state.
Definition BasePeriodicTimer.h:363
virtual hf_timer_err_t Stop() noexcept=0
Stop the periodic timer.
virtual hf_timer_err_t GetPeriod(hf_u64_t &period_us) noexcept=0
Get the current timer period.
virtual hf_timer_err_t ResetStats() noexcept=0
Reset timer statistics.
bool IsInitialized() const noexcept
Check if timer is initialized.
Definition BasePeriodicTimer.h:246
virtual hf_timer_err_t Deinitialize() noexcept=0
Deinitialize the timer and free resources.
hf_timer_statistics_t statistics_
Timer operation statistics.
Definition BasePeriodicTimer.h:396
bool running_
Running state flag.
Definition BasePeriodicTimer.h:395
void * GetUserData() const noexcept
Get current user data pointer.
Definition BasePeriodicTimer.h:301
virtual hf_timer_err_t GetStats(hf_u64_t &callback_count, hf_u64_t &missed_callbacks, hf_timer_err_t &last_error) noexcept=0
Get timer statistics and status information.
virtual hf_timer_err_t ResetDiagnostics() noexcept
Reset timer diagnostic information.
Definition BasePeriodicTimer.h:324
void ExecuteCallback() noexcept
Execute the timer callback (called by implementations).
Definition BasePeriodicTimer.h:378
virtual hf_u64_t GetMaxPeriod() const noexcept=0
Get minimum supported timer period.
virtual hf_timer_err_t Initialize() noexcept=0
Initialize the timer hardware/resources.
virtual ~BasePeriodicTimer() noexcept=default
Virtual destructor to ensure proper cleanup.
hf_timer_callback_t callback_
Timer callback function.
Definition BasePeriodicTimer.h:392
virtual hf_timer_err_t ResetStatistics() noexcept
Reset timer operation statistics.
Definition BasePeriodicTimer.h:314
virtual const char * GetDescription() const noexcept=0
Get description of this timer implementation.
virtual hf_u64_t GetMinPeriod() const noexcept=0
Get maximum supported timer period.
virtual hf_timer_err_t Start(hf_u64_t period_us) noexcept=0
Start the periodic timer with specified period.
void * user_data_
User data passed to callback.
Definition BasePeriodicTimer.h:393
bool HasValidCallback() const noexcept
Check if callback is valid.
Definition BasePeriodicTimer.h:388
Timer diagnostic information.
Definition BasePeriodicTimer.h:126
hf_timer_diagnostics_t()
Definition BasePeriodicTimer.h:136
hf_u64_t currentPeriodUs
Current timer period in microseconds.
Definition BasePeriodicTimer.h:133
hf_timer_err_t lastErrorCode
Last error code.
Definition BasePeriodicTimer.h:128
bool timerHealthy
Overall timer health status.
Definition BasePeriodicTimer.h:127
bool timerRunning
Timer running status.
Definition BasePeriodicTimer.h:132
hf_u32_t consecutiveErrors
Consecutive error count.
Definition BasePeriodicTimer.h:130
hf_u32_t lastErrorTimestamp
Last error timestamp.
Definition BasePeriodicTimer.h:129
bool timerInitialized
Timer initialization status.
Definition BasePeriodicTimer.h:131
hf_u64_t timerResolutionUs
Timer resolution in microseconds.
Definition BasePeriodicTimer.h:134
Timer operation statistics.
Definition BasePeriodicTimer.h:107
hf_u32_t minCallbackTimeUs
Minimum callback execution time.
Definition BasePeriodicTimer.h:114
hf_u32_t maxCallbackTimeUs
Maximum callback execution time.
Definition BasePeriodicTimer.h:113
hf_u32_t totalStarts
Total timer starts.
Definition BasePeriodicTimer.h:108
hf_timer_statistics_t()
Definition BasePeriodicTimer.h:117
hf_u32_t callbackExecutions
Number of callback executions.
Definition BasePeriodicTimer.h:110
hf_u32_t missedCallbacks
Number of missed callbacks.
Definition BasePeriodicTimer.h:111
hf_u64_t totalRunningTimeUs
Total running time in microseconds.
Definition BasePeriodicTimer.h:115
hf_u32_t averageCallbackTimeUs
Average callback execution time (microseconds)
Definition BasePeriodicTimer.h:112
hf_u32_t totalStops
Total timer stops.
Definition BasePeriodicTimer.h:109
Timer statistics structure.
Definition BasePeriodicTimer.h:91
hf_timer_stats_t() noexcept
Definition BasePeriodicTimer.h:99
hf_timer_err_t last_error
Definition BasePeriodicTimer.h:96
hf_u64_t callback_count
Definition BasePeriodicTimer.h:94
hf_u64_t start_count
Definition BasePeriodicTimer.h:92
hf_u64_t stop_count
Definition BasePeriodicTimer.h:93
hf_u64_t missed_callbacks
Definition BasePeriodicTimer.h:95
hf_timestamp_us_t last_start_us
Definition BasePeriodicTimer.h:97