/*定时器组例子:有两组定时器,每组有两个
*/
#include <stdio.h>
#include "esp_types.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "soc/timer_group_struct.h"
#include "driver/periph_ctrl.h"
#include "driver/timer.h"
#define TIMER_DIVIDER 16 // 分频
#define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) // 转换为秒计数
#define TIMER_INTERVAL0_SEC (3.4179) // 定时器1时间间隔
#define TIMER_INTERVAL1_SEC (5.78) // 定时器2时间间隔
#define TEST_WITHOUT_RELOAD 0 // 不进行重装载
#define TEST_WITH_RELOAD 1 // 进行重装载
/*
* A sample structure to pass events
* from the timer interrupt handler to the main program.
*/
typedef struct {
int type; // the type of timer's event
int timer_group;
int timer_idx;
uint64_t timer_counter_value;
} timer_event_t;
xQueueHandle timer_queue;
/*
* A simple helper function to print the raw timer counter value
* and the counter value converted to seconds
*/
static void inline print_timer_counter(uint64_t counter_value)
{
printf("Counter: 0x%08x%08x\n", (uint32_t) (counter_value >> 32),
(uint32_t) (counter_value));
printf("Time : %.8f s\n", (double) counter_value / TIMER_SCALE);
}