- Start the program timer.
- Stop the program timer.
- Trigger the program timer.
- Check the program timer for reaching the set value.
- Check the program timer for operation.
- Program timer handler.
To use the program timer driver in your project, follow these steps:
- Include the necessary header files in your project:
#include "universal_program_timer.h"It is necessary to place the universal_program_timer_handle() function in the interrupt handler, which is triggered every ms. The program timer is designed to handle small events (raising a flag, increasing a counter, etc.). It should not be used as a handler for large functions, as the callback is executed inside SysTick_handler, which can cause the entire system to freeze (due to the high interrupt priority)!
init_program_timer.c
#include "universal_program_timer.h"
static universal_program_timer_t _work_time = {
.counter = 0,
.interval = 1000,
.mode = eProgramTimerModeCircle,
.run = false,
.overflow = false,
.callback = callback_work_time
};
static universal_program_timer_t _control_time = {
.counter = 0,
.interval = 500,
.mode = eProgramTimerModeOneShot,
.run = false,
.overflow = false,
.callback = callback_control_time
};
static universal_program_timer_t* _program_timers[] = {&_work_time, &_control_time};
/**
* @brief Initialization of shared timers
*
* @return true Successful initialization
* @return false Failed initialization
*/
bool init_program_timer(void)
{
bool ret_val = false;
ret_val = universal_program_timer_init(_program_timers, sizeof(_program_timers) / sizeof(_program_timers[0]));
return ret_val;
}
/**
* @brief Work Timer
*
* @return drv_timer_handle_t* Pointer to the universal_program_timer_t structure
*/
universal_program_timer_t* program_timer_work_time(void)
{
return &_work_time;
}
/**
* @brief Control Timer
*
* @return drv_timer_handle_t* Pointer to the universal_program_timer_t structure
*/
universal_program_timer_t* program_timer_control_time(void)
{
return &_control_time;
}