Esp32/Components/driver/include/driver/os_timer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * os_timer.h
8  *
9  * This implementation mimics the behaviour of the ESP8266 Non-OS SDK timers,
10  * using Timer2 as the reference. The ESP32 uses a 1MHz reference so all times
11  *
12  * The ESP32 IDF contains more sophisticated timer implementations, but also
13  * this same API which it refers to as the 'legacy' timer API.
14  */
15 
16 #pragma once
17 
18 #include <cstdint>
19 
20 // Disarmed
21 #define OS_TIMER_DEFAULT() \
22  { \
23  }
24 
31 using smg_timer_func_t = void (*)(void* arg);
32 
33 struct esp_timer;
34 
35 struct smg_timer_t {
36  struct esp_timer* handle;
38  void* timer_arg;
39 };
40 
41 /*
42  * Re-map the os_timer_* definitions to avoid conflict with the real SDK implementations.
43  * Those are provided as a 'legacy' API which seems to be used only by WiFi in the SDK.
44  */
45 #define os_timer_func_t smg_timer_func_t
46 #define os_timer_t smg_timer_t
47 
48 #define os_timer_arm smg_timer_arm
49 #define os_timer_arm_us smg_timer_arm_us
50 #define os_timer_disarm smg_timer_disarm
51 #define os_timer_setfn smg_timer_setfn
52 #define os_timer_arm_ticks smg_timer_arm_ticks
53 #define os_timer_expire smg_timer_expire
54 #define os_timer_done smg_timer_done
55 
65 void smg_timer_arm_ticks(os_timer_t* ptimer, uint32_t ticks, bool repeat_flag);
66 
67 void smg_timer_setfn(os_timer_t* ptimer, os_timer_func_t pfunction, void* parg);
68 void smg_timer_arm_us(os_timer_t* ptimer, uint32_t time_us, bool repeat_flag);
69 void smg_timer_arm(os_timer_t* ptimer, uint32_t time_ms, bool repeat_flag);
71 void smg_timer_done(os_timer_t* ptimer);
72 
73 static inline uint64_t smg_timer_expire(const os_timer_t* ptimer)
74 {
75  if(ptimer == nullptr || ptimer->handle == nullptr) {
76  return 0;
77  }
78  // First field is 'alarm': See esp_timer.c.
79  return *reinterpret_cast<uint64_t*>(ptimer->handle);
80 }
81 
void smg_timer_arm_ticks(os_timer_t *ptimer, uint32_t ticks, bool repeat_flag)
Set a software timer using the Timer2 tick value.
void smg_timer_setfn(os_timer_t *ptimer, os_timer_func_t pfunction, void *parg)
void smg_timer_arm(os_timer_t *ptimer, uint32_t time_ms, bool repeat_flag)
static uint64_t smg_timer_expire(const os_timer_t *ptimer)
Definition: Esp32/Components/driver/include/driver/os_timer.h:73
void smg_timer_arm_us(os_timer_t *ptimer, uint32_t time_us, bool repeat_flag)
void smg_timer_disarm(os_timer_t *ptimer)
void smg_timer_done(os_timer_t *ptimer)
#define os_timer_func_t
Definition: Esp32/Components/driver/include/driver/os_timer.h:45
void(*)(void *arg) smg_timer_func_t
Definition: Esp32/Components/driver/include/driver/os_timer.h:31
This is the structure used by the Espressif timer API.
Definition: Rp2040/Components/driver/include/driver/os_timer.h:28
Definition: Esp32/Components/driver/include/driver/os_timer.h:35
struct esp_timer * handle
Definition: Esp32/Components/driver/include/driver/os_timer.h:36
void * timer_arg
Definition: Esp32/Components/driver/include/driver/os_timer.h:38
smg_timer_func_t timer_func
Definition: Esp32/Components/driver/include/driver/os_timer.h:37