Timer, SysTick and timer-peripheral helpers for STM32F4 (Cortex-M4). More...
#include "core/cortex-m4/timer.h"
#include "core/cortex-m4/clock.h"
#include "core/cortex-m4/interrupt.h"
#include "core/cortex-m4/uart.h"
#include "utils/timer_types.h"
#include <stdint.h>
Functions | |
void | systick_init (uint32_t tick_us) |
Initialize the SysTick timer to generate periodic ticks. | |
void | delay_us (uint64_t us) |
Busy-wait for the specified number of microseconds. | |
void | delay_ms (uint32_t ms) |
Busy-wait for the specified number of milliseconds. | |
uint64_t | hal_get_tick (void) |
Return the current system tick count. | |
uint32_t | hal_get_tick_duration_us (void) |
Return the configured tick duration in microseconds. | |
uint32_t | hal_get_tick_reload_value (void) |
Return the SysTick reload value (24-bit truncated). | |
uint32_t | hal_get_millis (void) |
Return system uptime in milliseconds. | |
uint32_t | hal_get_micros (void) |
Return system uptime in microseconds. | |
void | SysTick_Handler (void) |
SysTick interrupt handler increments the global tick counter. | |
uint32_t | _get_timer_base (hal_timer_t timer) |
void | _enable_timer_rcc (hal_timer_t timer) |
void | _timer_gp1_init (hal_timer_t timer, uint32_t prescaler, uint32_t auto_reload) |
void | _timer_gp2_init (hal_timer_t timer, uint32_t prescaler, uint32_t auto_reload) |
void | _timer_adv_init (hal_timer_t timer, uint32_t prescaler, uint32_t auto_reload) |
void | timer_init (hal_timer_t timer, uint32_t prescaler, uint32_t auto_reload) |
Initialize a timer based on its type (advanced / gp1 / gp2). | |
void | timer_start (hal_timer_t timer) |
Start the specified timer. | |
void | timer_stop (hal_timer_t timer) |
Stop the specified timer. | |
void | timer_reset (hal_timer_t timer) |
Reset timer counter to zero. | |
uint32_t | timer_get_count (hal_timer_t timer) |
Get the current counter value for a timer. | |
uint32_t | timer_get_frequency (hal_timer_t timer) |
Calculate the timer's current base frequency using PSC and ARR. | |
void | timer_set_arr (hal_timer_t timer, uint32_t channel, uint32_t arr) |
void | timer_clear_interrupt_flag (hal_timer_t timer) |
void | TIM2_IRQHandler () |
IRQ handler wrapper for TIM2. | |
void | TIM3_IRQHandler () |
IRQ handler wrapper for TIM3. | |
void | TIM4_IRQHandler () |
IRQ handler wrapper for TIM4. | |
void | TIM5_IRQHandler () |
IRQ handler wrapper for TIM5. | |
void | TIM1BRK_TIM9_IRQHandler () |
IRQ handler for TIM1 BRK and TIM9 shared vector. | |
void | _set_interrupt_enable_bit (hal_timer_t timer) |
void | timer_enable_interrupt (hal_timer_t timer) |
Enable timer interrupts (NVIC + DIER UIE) for supported timers. | |
void | timer_attach_callback (hal_timer_t timer, void(*callback)(void)) |
Attach a callback to the timer's HAL interrupt table. | |
void | timer_detach_callback (hal_timer_t timer) |
Detach a previously attached callback for the given timer. | |
void | timer_set_compare (hal_timer_t timer, uint8_t channel, uint32_t compare_value) |
Set the compare (CCR) register for a timer channel and configure CCMR. | |
uint32_t | timer_get_compare (hal_timer_t timer, uint32_t channel) |
uint32_t | timer_get_arr (hal_timer_t timer, uint32_t channel) |
void | timer_enable_channel (hal_timer_t timer, uint32_t channel) |
void | timer_disable_channel (hal_timer_t timer, uint32_t channel) |
Disable output on the specified timer channel (CCxE = 0). |
Timer, SysTick and timer-peripheral helpers for STM32F4 (Cortex-M4).
This translation unit implements:
All logic is intentionally low-level (direct register access) and matches the STM32F4 register layout / behavior expected by the rest of the HAL.
void _enable_timer_rcc | ( | hal_timer_t | timer | ) |
uint32_t _get_timer_base | ( | hal_timer_t | timer | ) |
void _set_interrupt_enable_bit | ( | hal_timer_t | timer | ) |
void _timer_adv_init | ( | hal_timer_t | timer, |
uint32_t | prescaler, | ||
uint32_t | auto_reload ) |
void _timer_gp1_init | ( | hal_timer_t | timer, |
uint32_t | prescaler, | ||
uint32_t | auto_reload ) |
void _timer_gp2_init | ( | hal_timer_t | timer, |
uint32_t | prescaler, | ||
uint32_t | auto_reload ) |
void delay_ms | ( | uint32_t | ms | ) |
Busy-wait for the specified number of milliseconds.
ms | Number of milliseconds to delay. |
void delay_us | ( | uint64_t | us | ) |
Busy-wait for the specified number of microseconds.
us | Number of microseconds to delay. |
uint32_t hal_get_micros | ( | void | ) |
Return system uptime in microseconds.
uint32_t hal_get_millis | ( | void | ) |
Return system uptime in milliseconds.
uint64_t hal_get_tick | ( | void | ) |
Return the current system tick count.
uint32_t hal_get_tick_duration_us | ( | void | ) |
Return the configured tick duration in microseconds.
uint32_t hal_get_tick_reload_value | ( | void | ) |
Return the SysTick reload value (24-bit truncated).
void SysTick_Handler | ( | void | ) |
SysTick interrupt handler increments the global tick counter.
void systick_init | ( | uint32_t | tick_us | ) |
Initialize the SysTick timer to generate periodic ticks.
tick_us | Tick period in microseconds. |
void TIM1BRK_TIM9_IRQHandler | ( | ) |
IRQ handler for TIM1 BRK and TIM9 shared vector.
void TIM2_IRQHandler | ( | void | ) |
IRQ handler wrapper for TIM2.
Clears the flag and dispatches to the HAL interrupt handler table.
void TIM3_IRQHandler | ( | void | ) |
IRQ handler wrapper for TIM3.
void TIM4_IRQHandler | ( | void | ) |
IRQ handler wrapper for TIM4.
void TIM5_IRQHandler | ( | void | ) |
IRQ handler wrapper for TIM5.
void timer_attach_callback | ( | hal_timer_t | timer, |
void(* | callback )(void) ) |
Attach a callback to the timer's HAL interrupt table.
timer | Timer identifier. |
callback | Function pointer to call when the timer IRQ fires. |
void timer_clear_interrupt_flag | ( | hal_timer_t | timer | ) |
void timer_detach_callback | ( | hal_timer_t | timer | ) |
Detach a previously attached callback for the given timer.
timer | Timer identifier. |
void timer_disable_channel | ( | hal_timer_t | timer, |
uint32_t | channel ) |
Disable output on the specified timer channel (CCxE = 0).
timer | Timer identifier. |
channel | Channel number (1-4). |
void timer_enable_channel | ( | hal_timer_t | timer, |
uint32_t | channel ) |
void timer_enable_interrupt | ( | hal_timer_t | timer | ) |
Enable timer interrupts (NVIC + DIER UIE) for supported timers.
timer | Timer identifier. |
uint32_t timer_get_arr | ( | hal_timer_t | timer, |
uint32_t | channel ) |
uint32_t timer_get_compare | ( | hal_timer_t | timer, |
uint32_t | channel ) |
uint32_t timer_get_count | ( | hal_timer_t | timer | ) |
Get the current counter value for a timer.
timer | Timer identifier. |
uint32_t timer_get_frequency | ( | hal_timer_t | timer | ) |
Calculate the timer's current base frequency using PSC and ARR.
timer | Timer identifier. |
void timer_init | ( | hal_timer_t | timer, |
uint32_t | prescaler, | ||
uint32_t | auto_reload ) |
Initialize a timer based on its type (advanced / gp1 / gp2).
timer | Timer identifier. |
prescaler | Prescaler value. |
auto_reload | Auto-reload value. |
void timer_reset | ( | hal_timer_t | timer | ) |
Reset timer counter to zero.
timer | Timer identifier. |
void timer_set_arr | ( | hal_timer_t | timer, |
uint32_t | channel, | ||
uint32_t | arr ) |
void timer_set_compare | ( | hal_timer_t | timer, |
uint8_t | channel, | ||
uint32_t | compare_value ) |
Set the compare (CCR) register for a timer channel and configure CCMR.
timer | Timer identifier. |
channel | Channel number (1-4). |
compare_value | Value to write into CCRx. |
void timer_start | ( | hal_timer_t | timer | ) |
Start the specified timer.
timer | Timer identifier. |
void timer_stop | ( | hal_timer_t | timer | ) |
Stop the specified timer.
timer | Timer identifier. |