@@ -91,13 +91,22 @@ static int counter_esp32_get_value(const struct device *dev, uint32_t *ticks)
91
91
return 0 ;
92
92
}
93
93
94
+ static int counter_esp32_get_value_64 (const struct device * dev , uint64_t * ticks )
95
+ {
96
+ ARG_UNUSED (dev );
97
+
98
+ * ticks = rtc_cntl_ll_get_rtc_time ();
99
+
100
+ return 0 ;
101
+ }
102
+
94
103
static int counter_esp32_set_alarm (const struct device * dev , uint8_t chan_id ,
95
104
const struct counter_alarm_cfg * alarm_cfg )
96
105
{
97
106
ARG_UNUSED (chan_id );
98
107
struct counter_esp32_data * data = dev -> data ;
99
- uint32_t now ;
100
- uint32_t ticks = 0 ;
108
+ uint64_t now ;
109
+ uint64_t ticks = 0 ;
101
110
102
111
#if defined(CONFIG_SOC_SERIES_ESP32 ) || defined(CONFIG_SOC_SERIES_ESP32C2 ) || \
103
112
defined(CONFIG_SOC_SERIES_ESP32C3 )
@@ -109,15 +118,21 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,
109
118
data -> alarm_cfg .callback = alarm_cfg -> callback ;
110
119
data -> alarm_cfg .user_data = alarm_cfg -> user_data ;
111
120
112
- counter_esp32_get_value (dev , & now );
121
+ counter_esp32_get_value_64 (dev , & now );
113
122
114
- ticks = (alarm_cfg -> flags & COUNTER_ALARM_CFG_ABSOLUTE ) ? alarm_cfg -> ticks
115
- : now + alarm_cfg -> ticks ;
123
+ if (alarm_cfg -> flags & COUNTER_ALARM_CFG_ABSOLUTE ) {
124
+ ticks = (now & ~0xFFFFFFFFULL ) | alarm_cfg -> ticks ;
125
+ if (ticks < now ) {
126
+ ticks += (1ULL << 32 );
127
+ }
128
+ } else {
129
+ ticks = now + alarm_cfg -> ticks ;
130
+ }
116
131
117
132
rtc_cntl_ll_set_wakeup_timer (ticks );
118
133
119
134
/* RTC main timer set alarm value */
120
- CLEAR_PERI_REG_MASK (RTC_CNTL_SLP_TIMER1_REG , 0xffffffff );
135
+ CLEAR_PERI_REG_MASK (RTC_CNTL_SLP_TIMER1_REG , 0xFFFFFFFF );
121
136
122
137
/* RTC main timer set alarm enable */
123
138
SET_PERI_REG_MASK (RTC_CNTL_SLP_TIMER1_REG , RTC_CNTL_MAIN_TIMER_ALARM_EN );
@@ -200,6 +215,7 @@ static DEVICE_API(counter, rtc_timer_esp32_api) = {
200
215
.start = counter_esp32_start ,
201
216
.stop = counter_esp32_stop ,
202
217
.get_value = counter_esp32_get_value ,
218
+ .get_value_64 = counter_esp32_get_value_64 ,
203
219
.set_alarm = counter_esp32_set_alarm ,
204
220
.cancel_alarm = counter_esp32_cancel_alarm ,
205
221
.set_top_value = counter_esp32_set_top_value ,
0 commit comments