You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
#include "timer_u.h"
|
|
|
|
void timer_set_pause_and_counter_zero(int group, int timer)
|
|
{
|
|
timer_pause(group, timer);
|
|
timer_set_counter_value(group, timer, 0);
|
|
}
|
|
|
|
void port_timer_delay_ms(uint64_t delay)
|
|
{
|
|
uint64_t timer_count = 0;
|
|
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
|
|
timer_start(TIMER_GROUP_0, TIMER_0);
|
|
|
|
while (timer_count < (delay * 1000))
|
|
{
|
|
timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &timer_count);
|
|
}
|
|
|
|
timer_pause(TIMER_GROUP_0, TIMER_0);
|
|
}
|
|
|
|
void timer_group_init(int group, int timer, bool auto_reload, int timer_interval, uint32_t timer_unit_time)
|
|
{
|
|
/* Select and initialize basic parameters of the timer */
|
|
timer_config_t config = {
|
|
.divider = 80,
|
|
.counter_dir = TIMER_COUNT_UP,
|
|
.counter_en = TIMER_PAUSE,
|
|
.alarm_en = TIMER_ALARM_EN,
|
|
.auto_reload = auto_reload,
|
|
}; // default clock source is APB
|
|
timer_init(group, timer, &config);
|
|
|
|
/* Timer's counter will initially start from value below.
|
|
Also, if auto_reload is set, this value will be automatically reload on alarm */
|
|
timer_set_counter_value(group, timer, 0); //指定定时器首个计数值为0
|
|
|
|
//检查定时器的当前值,调用函数 timer_get_counter_value() 或 timer_get_counter_time_sec()。
|
|
//可通过调用函数 timer_pause() 随时暂停定时器。要再次启动它,调用函数 timer_start()。
|
|
|
|
/* Configure the alarm value and the interrupt on alarm. */
|
|
timer_set_alarm_value(group, timer, timer_interval * ((80 * timer_unit_time) / 80));
|
|
|
|
timer_enable_intr(group, timer);
|
|
|
|
// timer_isr_callback_add(group, timer, timer_group_isr_callback, NULL, 0);
|
|
|
|
// timer_start(group, timer);
|
|
timer_pause(group, timer);
|
|
}
|