diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-03-14 00:29:51 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-03-14 00:29:51 +0000 |
| commit | deb413e8baf96a4638c73f26fbe4de99380abaf9 (patch) | |
| tree | 411f696aa43aa55a68df5af05b3921370957fcb1 /stmhal/systick.c | |
| parent | 536dde254be99e19700a0934af38b913256475e3 (diff) | |
| parent | 9db719bb57626d72ab84ab0ccd2294bf89158762 (diff) | |
Merge pull request #345 from dhylands/stmhal-systick-cleanup
stmhal - More systick cleanup. Fix HAL_Delay
Diffstat (limited to 'stmhal/systick.c')
| -rw-r--r-- | stmhal/systick.c | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/stmhal/systick.c b/stmhal/systick.c index eda39c788..d6c914886 100644 --- a/stmhal/systick.c +++ b/stmhal/systick.c @@ -2,47 +2,15 @@ #include "misc.h" #include "systick.h" -void sys_tick_init(void) { - // SysTick_Config is now called from HAL_RCC_ClockConfig, which is called - // from SystemClock_Config - - // SysTick_Config sets the SysTick_IRQn to be the lowest priority, but - // we want it to be the highest priority, so fix things here. - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); -} - -void sys_tick_delay_ms(uint32_t delay_ms) { - sys_tick_wait_at_least(HAL_GetTick(), delay_ms); -} - -// waits until at least delay_ms milliseconds have passed from the sampling of stc -// handles overflow properl -// assumes stc was taken from HAL_GetTick() some time before calling this function -// eg stc <= HAL_GetTick() for the case of no wrap around of HAL_GetTick() -void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms) { - // stc_wait is the value of HAL_GetTick() that we wait for - uint32_t stc_wait = stc + delay_ms; - if (stc_wait < stc) { - // stc_wait wrapped around - while (stc <= HAL_GetTick() || HAL_GetTick() < stc_wait) { - __WFI(); // enter sleep mode, waiting for interrupt - } - } else { - // stc_wait did not wrap around - while (stc <= HAL_GetTick() && HAL_GetTick() < stc_wait) { - __WFI(); // enter sleep mode, waiting for interrupt - } - } +bool sys_tick_has_passed(uint32_t start_tick, uint32_t delay_ms) { + return HAL_GetTick() - start_tick >= delay_ms; } -bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { - // stc_wait is the value of HAL_GetTick() that we wait for - uint32_t stc_wait = stc + delay_ms; - if (stc_wait < stc) { - // stc_wait wrapped around - return !(stc <= HAL_GetTick() || HAL_GetTick() < stc_wait); - } else { - // stc_wait did not wrap around - return !(stc <= HAL_GetTick() && HAL_GetTick() < stc_wait); +// waits until at least delay_ms milliseconds have passed from the sampling of +// startTick. Handles overflow properly. Assumes stc was taken from +// HAL_GetTick() some time before calling this function. +void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) { + while (!sys_tick_has_passed(start_tick, delay_ms)) { + __WFI(); // enter sleep mode, waiting for interrupt } } |
