Skip to content

Commit f9423ab

Browse files
authored
Fix timerAttachInterrupt() and timerDetachInterrupt() in esp32-hal-timer.c (#6763)
* Fix timerAttachInterrupt() and timerDetachInterrupt() for migration to IDF 4.4 * Fixing log messages as per request
1 parent e5913c3 commit f9423ab

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

Diff for: cores/esp32/esp32-hal-timer.c

+11-19
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ typedef union {
3232

3333
#define NUM_OF_TIMERS SOC_TIMER_GROUP_TOTAL_TIMERS
3434

35-
typedef struct {
36-
int timer_group;
37-
int timer_idx;
38-
int alarm_interval;
39-
bool auto_reload;
40-
} timer_info_t;
41-
4235
typedef struct hw_timer_s
4336
{
4437
uint8_t group;
@@ -194,7 +187,7 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb
194187
hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){
195188
if(num >= NUM_OF_TIMERS)
196189
{
197-
log_e("Timer dont have that timer number.");
190+
log_e("Timer number %u exceeds available number of Timers.", num);
198191
return NULL;
199192
}
200193

@@ -220,24 +213,23 @@ void timerEnd(hw_timer_t *timer){
220213
timer_deinit(timer->group, timer->num);
221214
}
222215

216+
bool IRAM_ATTR timerFnWrapper(void *arg){
217+
void (*fn)(void) = arg;
218+
fn();
219+
220+
// some additional logic or handling may be required here to approriately yield or not
221+
return false;
222+
}
223+
223224
void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
224225
if(edge){
225226
log_w("EDGE timer interrupt is not supported! Setting to LEVEL...");
226-
edge = false;
227227
}
228-
timer_enable_intr(timer->group, timer->num);
229-
230-
timer_info_t *timer_info = calloc(1, sizeof(timer_info_t));
231-
timer_info->timer_group = timer->group;
232-
timer_info->timer_idx = timer->num;
233-
timer_info->auto_reload = timerGetAutoReload(timer);
234-
timer_info->alarm_interval = timerAlarmRead(timer);
235-
236-
timer_isr_callback_add(timer->group, timer->num, (timer_isr_t)fn, timer_info, 0);
228+
timer_isr_callback_add(timer->group, timer->num, timerFnWrapper, fn, 0);
237229
}
238230

239231
void timerDetachInterrupt(hw_timer_t *timer){
240-
timerAttachInterrupt(timer, NULL, false);
232+
timer_isr_callback_remove(timer->group, timer->num);
241233
}
242234

243235
uint64_t timerReadMicros(hw_timer_t *timer){

0 commit comments

Comments
 (0)