This commit is contained in:
2021-03-09 18:38:56 +01:00
parent c27cd94e7e
commit 7fa6fe176c
4 changed files with 49 additions and 0 deletions

View File

@ -1,4 +1,5 @@
idf_component_register(SRCS "app_main.c"
"network_mngr.c"
"gpio.c"
"timer.c"
INCLUDE_DIRS ".")

View File

@ -14,6 +14,7 @@
#include <nvs_flash.h>
#include "gpio.h"
#include "timer.h"
@ -38,6 +39,7 @@ void app_main(void)
gpioInit();
networkInit(isGpioForceProv());
timerInit();
/* Start main application now */
while (1) {

38
src/main/timer.c Normal file
View File

@ -0,0 +1,38 @@
#include <stdint.h>
#include "timer.h"
#include <driver/timer.h>
#include <esp_log.h>
#include <esp_types.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
static const char *TAG = "tm";
static void timer_task(void *arg) {
while (1) {
uint64_t counterValue;
timer_get_counter_value(TIMER_GROUP_0, 0, &counterValue);
ESP_LOGI(TAG, "timer value: %08x %08x", (uint32_t)(counterValue >> 32), (uint32_t)(counterValue));
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void timerInit() {
timer_config_t config = {
.divider = 80,
.counter_dir = TIMER_COUNT_UP,
.counter_en = TIMER_PAUSE,
.alarm_en = TIMER_ALARM_DIS,
.auto_reload = TIMER_AUTORELOAD_EN
};
timer_init(TIMER_GROUP_0, 0, &config);
timer_set_counter_value(TIMER_GROUP_0, 0, 0);
timer_start(TIMER_GROUP_0, 0);
xTaskCreate(timer_task, "timer_task", 2048, NULL, 5, NULL);
}

8
src/main/timer.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _PCNT_H_
#define _PCNT_H_
void timerInit();
#endif // _PCNT_H_