Improve README and doxygen comments

This commit is contained in:
Henrik Stickann
2022-04-24 13:42:34 +02:00
parent 020870016c
commit ecfad2e768
8 changed files with 141 additions and 21 deletions

View File

@@ -1,7 +1,10 @@
#include <sta/hal/delay.hpp>
#ifdef STA_HAL_DELAY_ENABLE
#include <main.h>
#include <sta/assert.hpp>
#include <sta/hal.hpp>
#include <sta/lang.hpp>
#include <sta/hal/clocks.hpp>
namespace sta
@@ -24,6 +27,36 @@ namespace sta
__HAL_TIM_SET_COUNTER(&STA_HAL_DELAY_US_TIM, 0);
while (__HAL_TIM_GET_COUNTER(&STA_HAL_DELAY_US_TIM) < us);
}
bool isValidDelayUsTIM()
{
// Get PCLK multiplier for TIM clock
uint32_t pclkMul = 1;
switch (STA_HAL_DELAY_US_TIM.Init.ClockDivision)
{
case TIM_CLOCKDIVISION_DIV1:
pclkMul = 1;
break;
case TIM_CLOCKDIVISION_DIV2:
pclkMul = 2;
break;
case TIM_CLOCKDIVISION_DIV4:
pclkMul = 4;
break;
default:
STA_ASSERT(false);
STA_UNREACHABLE();
}
// Calculate TIM clock frequency
uint32_t clkFreq = pclkMul * STA_HAL_GET_HANDLE_PCLK_FREQ_FN(STA_HAL_DELAY_US_TIM)();
// Calculate update frequency based on prescaler value
uint32_t updateFreq = clkFreq / STA_HAL_DELAY_US_TIM.Init.Prescaler;
// TIM must have at least microsecond precision (>= 1 MHz frequency)
return (updateFreq == 1000000);
}
} // namespace sta
#endif // STA_HAL_DELAY_US_TIM