Files
TX/source/soft_timer.h
2025-06-20 18:02:50 -05:00

39 lines
855 B
C

#ifndef SOFT_TIMER_H
#define SOFT_TIMER_H
#include <stdint.h>
#include <stdbool.h>
#define MAX_TIMERS 8
typedef enum {
TIMER_MODE_ONE_SHOT,
TIMER_MODE_PERIODIC
} timer_mode_t;
typedef void (*timer_callback_t)(void* context);
typedef struct {
uint32_t timeout_ticks;
uint32_t remaining_ticks;
bool active;
bool inUse;
bool fired;
timer_mode_t mode;
timer_callback_t callback;
void* callback_context;
} soft_timer_t;
void stimer_init(void);
int stimer_start(uint32_t timeout_ticks, timer_mode_t mode, timer_callback_t cb, void* ctx);
void stimer_stop(int timer_id);
void stimer_end(int timer_id);
bool stimer_fired(int timer_id);
bool stimer_clearFired(int timer_id);
void stimer_update(void); // Should be called from timer ISR
bool stimer_is_active(int timer_id);
void stimer_delay(uint32_t ticks);
#endif