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/rcc_reg.h"#include "core/cortex-m4/timer_reg.h"#include "utils/timer_types.h"#include <stdint.h>
Functions | |
| <<<<<<< HEAD static volatile uint64_t systick_ticks=0;static volatile uint32_t tick_duration_us=1;static volatile uint32_t tick_reload_value=0;=======static volatile uint64_t systick_ticks=0;static volatile uint32_t tick_duration_us=1;static volatile uint32_t tick_reload_value=0;> > > > > > void | systick_init (uint32_t tick_us) |
| Initialize the SysTick timer. | |
| void | delay_us (uint64_t us) |
| Busy-wait delay in microseconds. | |
| void | delay_ms (uint32_t ms) |
| Busy-wait delay in milliseconds. | |
| uint64_t | hal_get_tick (void) |
| Get current system tick count. | |
| uint32_t | hal_get_tick_duration_us (void) |
| Get configured tick duration. | |
| uint32_t | hal_get_tick_reload_value (void) |
| Get SysTick reload value. | |
| uint32_t | hal_get_millis (void) |
| Get system uptime in milliseconds. | |
| uint32_t | hal_get_micros (void) |
| Get system uptime in microseconds. | |
| void | SysTick_Handler (void) |
| SysTick interrupt handler. | |
| void | timer_init (hal_timer_t timer, uint32_t prescaler, uint32_t auto_reload) |
| Initialize timer based on type. | |
Timer, SysTick and timer-peripheral helpers for STM32F4 (Cortex-M4)
This translation unit implements:
All logic uses direct register access matching the STM32F4 register layout.
| void delay_ms | ( | uint32_t | ms | ) |
Busy-wait delay in milliseconds.
| ms | Number of milliseconds to delay |
| void delay_us | ( | uint64_t | us | ) |
Busy-wait delay in microseconds.
| us | Number of microseconds to delay |
| uint32_t hal_get_micros | ( | void | ) |
Get system uptime in microseconds.
| uint32_t hal_get_millis | ( | void | ) |
Get system uptime in milliseconds.
| uint64_t hal_get_tick | ( | void | ) |
Get current system tick count.
| uint32_t hal_get_tick_duration_us | ( | void | ) |
Get configured tick duration.
| uint32_t hal_get_tick_reload_value | ( | void | ) |
Get SysTick reload value.
| void SysTick_Handler | ( | void | ) |
SysTick interrupt handler.
Increments the global tick counter
| <<<<<<< HEAD static volatile uint64_t systick_ticks=0; static volatile uint32_t tick_duration_us=1; static volatile uint32_t tick_reload_value=0;======= static volatile uint64_t systick_ticks=0; static volatile uint32_t tick_duration_us=1; static volatile uint32_t tick_reload_value=0; > > > > > > void systick_init | ( | uint32_t | tick_us | ) |
Initialize the SysTick timer.
| tick_us | Tick period in microseconds |
Configures SysTick to:
| void timer_init | ( | hal_timer_t | timer, |
| uint32_t | prescaler, | ||
| uint32_t | auto_reload ) |
Initialize timer based on type.
| timer | Timer identifier |
| prescaler | Prescaler value |
| auto_reload | Auto-reload value |
Start timer counter
| timer | Timer identifier |
Stop timer counter
| timer | Timer identifier |
Set timer compare value for PWM
| timer | Timer identifier |
| channel | Channel number (1-4) |
| compare_value | CCR register value |
Configures PWM mode 1 and enables the channel output
Enable timer channel output
| timer | Timer identifier |
| channel | Channel number (1-4) |
Reset timer counter to zero.
| timer | Timer identifier. |
Get the current counter value for a timer.
| timer | Timer identifier. |
Calculate the timer's current base frequency using PSC and ARR.
| timer | Timer identifier. |
IRQ handler wrapper for TIM2.
Clears the flag and dispatches to the HAL interrupt handler table.
IRQ handler wrapper for TIM3.
IRQ handler wrapper for TIM4.
IRQ handler wrapper for TIM5.
IRQ handler for TIM1 BRK and TIM9 shared vector.
Enable timer interrupts (NVIC + DIER UIE) for supported timers.
| timer | Timer identifier. |
Attach a callback to the timer's HAL interrupt table.
| timer | Timer identifier. |
| callback | Function pointer to call when the timer IRQ fires. |
Detach a previously attached callback for the given timer.
| timer | Timer identifier. |
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. |
Disable timer channel output
| timer | Timer identifier |
| channel | Channel number (1-4) |