Merge pull request #11629 from angelnu/patch-1
Allow calls to timer functions within ISR
This commit is contained in:
commit
9902934412
1 changed files with 26 additions and 6 deletions
|
|
@ -22,6 +22,12 @@
|
||||||
#include "esp_clk_tree.h"
|
#include "esp_clk_tree.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
|
#define TIMER_IRAM IRAM_ATTR
|
||||||
|
#else
|
||||||
|
#define TIMER_IRAM
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*voidFuncPtr)(void);
|
typedef void (*voidFuncPtr)(void);
|
||||||
typedef void (*voidFuncPtrArg)(void *);
|
typedef void (*voidFuncPtrArg)(void *);
|
||||||
|
|
||||||
|
|
@ -36,9 +42,11 @@ struct timer_struct_t {
|
||||||
bool timer_started;
|
bool timer_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline uint64_t timerRead(hw_timer_t *timer) {
|
inline TIMER_IRAM uint64_t timerRead(hw_timer_t *timer) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
|
|
@ -46,17 +54,21 @@ inline uint64_t timerRead(hw_timer_t *timer) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerWrite(hw_timer_t *timer, uint64_t val) {
|
void TIMER_IRAM timerWrite(hw_timer_t *timer, uint64_t val) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gptimer_set_raw_count(timer->timer_handle, val);
|
gptimer_set_raw_count(timer->timer_handle, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
|
void TIMER_IRAM timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
@ -67,7 +79,9 @@ void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64
|
||||||
};
|
};
|
||||||
err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg);
|
err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer Alarm Write failed, error num=%d", err);
|
log_e("Timer Alarm Write failed, error num=%d", err);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,27 +94,33 @@ uint32_t timerGetFrequency(hw_timer_t *timer) {
|
||||||
return frequency;
|
return frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerStart(hw_timer_t *timer) {
|
void TIMER_IRAM timerStart(hw_timer_t *timer) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gptimer_start(timer->timer_handle);
|
gptimer_start(timer->timer_handle);
|
||||||
timer->timer_started = true;
|
timer->timer_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerStop(hw_timer_t *timer) {
|
void TIMER_IRAM timerStop(hw_timer_t *timer) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gptimer_stop(timer->timer_handle);
|
gptimer_stop(timer->timer_handle);
|
||||||
timer->timer_started = false;
|
timer->timer_started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerRestart(hw_timer_t *timer) {
|
void TIMER_IRAM timerRestart(hw_timer_t *timer) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
|
#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
|
||||||
log_e("Timer handle is NULL");
|
log_e("Timer handle is NULL");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gptimer_set_raw_count(timer->timer_handle, 0);
|
gptimer_set_raw_count(timer->timer_handle, 0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue