From 7fa6fe176c90b1f8167a60c9f40ea2ca09dab31d Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 9 Mar 2021 18:38:56 +0100 Subject: [PATCH] timer --- src/main/CMakeLists.txt | 1 + src/main/app_main.c | 2 ++ src/main/timer.c | 38 ++++++++++++++++++++++++++++++++++++++ src/main/timer.h | 8 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 src/main/timer.c create mode 100644 src/main/timer.h diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index e21c32e..84f3e82 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -1,4 +1,5 @@ idf_component_register(SRCS "app_main.c" "network_mngr.c" "gpio.c" + "timer.c" INCLUDE_DIRS ".") diff --git a/src/main/app_main.c b/src/main/app_main.c index 3bd5e5b..064b4cd 100644 --- a/src/main/app_main.c +++ b/src/main/app_main.c @@ -14,6 +14,7 @@ #include #include "gpio.h" +#include "timer.h" @@ -38,6 +39,7 @@ void app_main(void) gpioInit(); networkInit(isGpioForceProv()); + timerInit(); /* Start main application now */ while (1) { diff --git a/src/main/timer.c b/src/main/timer.c new file mode 100644 index 0000000..b22fe61 --- /dev/null +++ b/src/main/timer.c @@ -0,0 +1,38 @@ +#include + +#include "timer.h" + +#include +#include +#include +#include +#include +#include + +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); +} diff --git a/src/main/timer.h b/src/main/timer.h new file mode 100644 index 0000000..ecc23e8 --- /dev/null +++ b/src/main/timer.h @@ -0,0 +1,8 @@ +#ifndef _PCNT_H_ +#define _PCNT_H_ + +void timerInit(); + + + +#endif // _PCNT_H_ \ No newline at end of file