Skip to content

Commit 7640ded

Browse files
authored
Allow calls to timer functions within ISR
See https://github.com/espressif/esp-idf/blob/master/components/esp_driver_gptimer/linker.lf for what functions are running in ram.
1 parent c369dca commit 7640ded

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

cores/esp32/esp32-hal-timer.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,23 @@ struct timer_struct_t {
3636
bool timer_started;
3737
};
3838

39-
inline uint64_t timerRead(hw_timer_t *timer) {
39+
inline IRAM_ATTR uint64_t timerRead(hw_timer_t *timer) {
4040
if (timer == NULL) {
41-
log_e("Timer handle is NULL");
4241
return 0;
4342
}
4443
uint64_t value;
4544
gptimer_get_raw_count(timer->timer_handle, &value);
4645
return value;
4746
}
4847

49-
void timerWrite(hw_timer_t *timer, uint64_t val) {
48+
void IRAM_ATTR timerWrite(hw_timer_t *timer, uint64_t val) {
5049
if (timer == NULL) {
51-
log_e("Timer handle is NULL");
5250
return;
5351
}
5452
gptimer_set_raw_count(timer->timer_handle, val);
5553
}
5654

57-
void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
55+
void IRAM_ATTR timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
5856
if (timer == NULL) {
5957
log_e("Timer handle is NULL");
6058
return;
@@ -67,7 +65,7 @@ void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64
6765
};
6866
err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg);
6967
if (err != ESP_OK) {
70-
log_e("Timer Alarm Write failed, error num=%d", err);
68+
; // Ignore
7169
}
7270
}
7371

@@ -80,18 +78,16 @@ uint32_t timerGetFrequency(hw_timer_t *timer) {
8078
return frequency;
8179
}
8280

83-
void timerStart(hw_timer_t *timer) {
81+
void IRAM_ATTR timerStart(hw_timer_t *timer) {
8482
if (timer == NULL) {
85-
log_e("Timer handle is NULL");
8683
return;
8784
}
8885
gptimer_start(timer->timer_handle);
8986
timer->timer_started = true;
9087
}
9188

92-
void timerStop(hw_timer_t *timer) {
89+
void IRAM_ATTR timerStop(hw_timer_t *timer) {
9390
if (timer == NULL) {
94-
log_e("Timer handle is NULL");
9591
return;
9692
}
9793
gptimer_stop(timer->timer_handle);
@@ -100,7 +96,6 @@ void timerStop(hw_timer_t *timer) {
10096

10197
void timerRestart(hw_timer_t *timer) {
10298
if (timer == NULL) {
103-
log_e("Timer handle is NULL");
10499
return;
105100
}
106101
gptimer_set_raw_count(timer->timer_handle, 0);

0 commit comments

Comments
 (0)