mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-12-17 00:58:02 +00:00
added profiler and updated delay implementation
This commit is contained in:
@@ -52,6 +52,7 @@ namespace sta
|
||||
|
||||
// Calculate TIM clock frequency
|
||||
uint32_t clkFreq = pclkMul * STA_STM32_GET_HANDLE_PCLK_FREQ_FN(STA_STM32_DELAY_US_TIM)();
|
||||
|
||||
// Calculate update frequency based on prescaler value
|
||||
uint32_t prescaler = (STA_STM32_DELAY_US_TIM.Init.Prescaler) ? STA_STM32_DELAY_US_TIM.Init.Prescaler : 1;
|
||||
uint32_t updateFreq = clkFreq / prescaler;
|
||||
@@ -66,10 +67,29 @@ namespace sta
|
||||
{
|
||||
// Check if the specified timer is usable for microsecond delays.
|
||||
STA_ASSERT(isValidDelayUsTIM());
|
||||
STA_ASSERT(us < 1000);
|
||||
|
||||
__HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);
|
||||
// Use millisecond delays for us > 1000 and use microseconds delay for the remainder.
|
||||
delayMs(us / 1000);
|
||||
us = us % 1000;
|
||||
|
||||
// __HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
|
||||
|
||||
uint32_t startTime = __HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM);
|
||||
|
||||
// Check if an overflow is expected during the delay time.
|
||||
if (startTime < __HAL_TIM_GET_AUTORELOAD(&STA_STM32_DELAY_US_TIM) - us * gDelayUsMul)
|
||||
{
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < startTime + us * gDelayUsMul);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t overflowTime = __HAL_TIM_GET_AUTORELOAD(&STA_STM32_DELAY_US_TIM) - startTime;
|
||||
// Wait until the overflow happens
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) > startTime);
|
||||
|
||||
// Wait the remaining time after the overflow.
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul - overflowTime);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
|
||||
Reference in New Issue
Block a user