Skip to content

Commit 9902934

Browse files
authored
Merge pull request #11629 from angelnu/patch-1
Allow calls to timer functions within ISR
2 parents 1a56a1d + e3a0a3a commit 9902934

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

cores/esp32/esp32-hal-timer.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#include "esp_clk_tree.h"
2323
#endif
2424

25+
#if CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
26+
#define TIMER_IRAM IRAM_ATTR
27+
#else
28+
#define TIMER_IRAM
29+
#endif
30+
2531
typedef void (*voidFuncPtr)(void);
2632
typedef void (*voidFuncPtrArg)(void *);
2733

@@ -36,27 +42,33 @@ struct timer_struct_t {
3642
bool timer_started;
3743
};
3844

39-
inline uint64_t timerRead(hw_timer_t *timer) {
45+
inline TIMER_IRAM uint64_t timerRead(hw_timer_t *timer) {
4046
if (timer == NULL) {
47+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
4148
log_e("Timer handle is NULL");
49+
#endif
4250
return 0;
4351
}
4452
uint64_t value;
4553
gptimer_get_raw_count(timer->timer_handle, &value);
4654
return value;
4755
}
4856

49-
void timerWrite(hw_timer_t *timer, uint64_t val) {
57+
void TIMER_IRAM timerWrite(hw_timer_t *timer, uint64_t val) {
5058
if (timer == NULL) {
59+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
5160
log_e("Timer handle is NULL");
61+
#endif
5262
return;
5363
}
5464
gptimer_set_raw_count(timer->timer_handle, val);
5565
}
5666

57-
void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
67+
void TIMER_IRAM timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
5868
if (timer == NULL) {
69+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
5970
log_e("Timer handle is NULL");
71+
#endif
6072
return;
6173
}
6274
esp_err_t err = ESP_OK;
@@ -67,7 +79,9 @@ void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64
6779
};
6880
err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg);
6981
if (err != ESP_OK) {
82+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
7083
log_e("Timer Alarm Write failed, error num=%d", err);
84+
#endif
7185
}
7286
}
7387

@@ -80,27 +94,33 @@ uint32_t timerGetFrequency(hw_timer_t *timer) {
8094
return frequency;
8195
}
8296

83-
void timerStart(hw_timer_t *timer) {
97+
void TIMER_IRAM timerStart(hw_timer_t *timer) {
8498
if (timer == NULL) {
99+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
85100
log_e("Timer handle is NULL");
101+
#endif
86102
return;
87103
}
88104
gptimer_start(timer->timer_handle);
89105
timer->timer_started = true;
90106
}
91107

92-
void timerStop(hw_timer_t *timer) {
108+
void TIMER_IRAM timerStop(hw_timer_t *timer) {
93109
if (timer == NULL) {
110+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
94111
log_e("Timer handle is NULL");
112+
#endif
95113
return;
96114
}
97115
gptimer_stop(timer->timer_handle);
98116
timer->timer_started = false;
99117
}
100118

101-
void timerRestart(hw_timer_t *timer) {
119+
void TIMER_IRAM timerRestart(hw_timer_t *timer) {
102120
if (timer == NULL) {
121+
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
103122
log_e("Timer handle is NULL");
123+
#endif
104124
return;
105125
}
106126
gptimer_set_raw_count(timer->timer_handle, 0);

0 commit comments

Comments
 (0)