Rp2040/Components/driver/include/driver/os_timer.h
Go to the documentation of this file.
1 /*
2  * This implementation mimics the behaviour of the ESP8266 Non-OS SDK timers,
3  * using Timer2 as the reference (which is _not_ in microseconds!)
4  *
5  * The ESP32 IDF contains more sophisticated timer implementations, but also
6  * this same API which it refers to as the 'legacy' timer API.
7  */
8 
9 #pragma once
10 
11 #include <c_types.h>
12 
13 // Disarmed
14 #define OS_TIMER_DEFAULT() \
15  { \
16  .timer_next = (os_timer_t*)-1, \
17  }
18 
19 typedef void os_timer_func_t(void* timer_arg);
20 
28 struct os_timer_t {
32  uint32_t timer_expire;
34  uint32_t timer_period;
38  void* timer_arg;
39 };
40 
41 void os_timer_arm_ticks(os_timer_t* ptimer, uint32_t ticks, bool repeat_flag);
42 
43 void os_timer_arm(os_timer_t* ptimer, uint32_t time, bool repeat_flag);
44 void os_timer_arm_us(os_timer_t* ptimer, uint32_t time, bool repeat_flag);
45 
47 void os_timer_setfn(os_timer_t* ptimer, os_timer_func_t* pfunction, void* parg);
48 
49 static inline uint64_t os_timer_expire(const os_timer_t* ptimer)
50 {
51  if(ptimer == nullptr || int(ptimer->timer_next) == -1) {
52  return 0;
53  }
54  return ptimer->timer_expire;
55 }
56 
57 void os_timer_done(os_timer_t* ptimer);
static uint64_t os_timer_expire(const os_timer_t *ptimer)
Definition: Rp2040/Components/driver/include/driver/os_timer.h:49
void os_timer_arm_ticks(os_timer_t *ptimer, uint32_t ticks, bool repeat_flag)
void os_timer_setfn(os_timer_t *ptimer, os_timer_func_t *pfunction, void *parg)
void os_timer_done(os_timer_t *ptimer)
void os_timer_func_t(void *timer_arg)
Definition: Rp2040/Components/driver/include/driver/os_timer.h:19
void os_timer_arm_us(os_timer_t *ptimer, uint32_t time, bool repeat_flag)
void os_timer_disarm(os_timer_t *ptimer)
void os_timer_arm(os_timer_t *ptimer, uint32_t time, bool repeat_flag)
Time< T > time(Unit unit, T value)
Helper function to create a Time and deduce the type.
Definition: NanoTime.h:432
This is the structure used by the Espressif timer API.
Definition: Rp2040/Components/driver/include/driver/os_timer.h:28
uint32_t timer_expire
Set to the next Timer2 count value when the timer will expire.
Definition: Rp2040/Components/driver/include/driver/os_timer.h:32
uint32_t timer_period
0 if this is a one-shot timer, otherwise defines the interval in Timer2 ticks
Definition: Rp2040/Components/driver/include/driver/os_timer.h:34
os_timer_func_t * timer_func
User-provided callback function pointer.
Definition: Rp2040/Components/driver/include/driver/os_timer.h:36
struct os_timer_t * timer_next
If disarmed, set to -1, otherwise points to the next queued timer (or NULL if last in the list)
Definition: Rp2040/Components/driver/include/driver/os_timer.h:30
void * timer_arg
Argument passed to the callback function.
Definition: Rp2040/Components/driver/include/driver/os_timer.h:38