Skip to content

Commit ee97642

Browse files
committed
replace resolution with frequency
1 parent 529f9e5 commit ee97642

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void timerWrite(hw_timer_t timer_handle, uint64_t val){
2727
gptimer_set_raw_count(timer_handle, val);
2828
}
2929

30-
void timerAlarmWrite(hw_timer_t timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count){
30+
void timerAlarm(hw_timer_t timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count){
3131
esp_err_t err = ESP_OK;
3232
gptimer_alarm_config_t alarm_cfg = {
3333
.alarm_count = alarm_value,
@@ -40,10 +40,10 @@ void timerAlarmWrite(hw_timer_t timer, uint64_t alarm_value, bool autoreload, ui
4040
}
4141
}
4242

43-
uint32_t timerGetResolution(hw_timer_t timer_handle){
44-
uint32_t resolution;
45-
gptimer_get_resolution(timer_handle, &resolution);
46-
return resolution;
43+
uint32_t timerGetFrequency(hw_timer_t timer_handle){
44+
uint32_t frequency;
45+
gptimer_get_resolution(timer_handle, &frequency);
46+
return frequency;
4747
}
4848

4949
void timerStart(hw_timer_t timer_handle){
@@ -58,7 +58,7 @@ void timerRestart(hw_timer_t timer_handle){
5858
gptimer_set_raw_count(timer_handle,0);
5959
}
6060

61-
hw_timer_t timerBegin(uint32_t resolution, bool countUp){
61+
hw_timer_t timerBegin(uint32_t frequency, bool countUp){
6262

6363
esp_err_t err = ESP_OK;
6464
hw_timer_t timer_handle;
@@ -70,7 +70,7 @@ hw_timer_t timerBegin(uint32_t resolution, bool countUp){
7070
for (size_t i = 0; i < sizeof(gptimer_clks) / sizeof(gptimer_clks[0]); i++){
7171
clk = gptimer_clks[i];
7272
clk_tree_src_get_freq_hz(clk, CLK_TREE_SRC_FREQ_PRECISION_CACHED, &counter_src_hz);
73-
divider = counter_src_hz / resolution;
73+
divider = counter_src_hz / frequency;
7474
if((divider >= 2) && (divider <= 65536)){
7575
break;
7676
}
@@ -85,7 +85,7 @@ hw_timer_t timerBegin(uint32_t resolution, bool countUp){
8585
gptimer_config_t config = {
8686
.clk_src = clk,
8787
.direction = countUp,
88-
.resolution_hz = resolution,
88+
.resolution_hz = frequency,
8989
.flags.intr_shared = true,
9090
};
9191

@@ -140,18 +140,18 @@ void timerDetachInterrupt(hw_timer_t timer){
140140

141141
uint64_t timerReadMicros(hw_timer_t timer){
142142
uint64_t timer_val = timerRead(timer);
143-
uint32_t resolution = timerGetResolution(timer);
144-
return timer_val * 1000000 / resolution;
143+
uint32_t frequency = timerGetResolution(timer);
144+
return timer_val * 1000000 / frequency;
145145
}
146146

147147
uint64_t timerReadMilis(hw_timer_t timer){
148148
uint64_t timer_val = timerRead(timer);
149-
uint32_t resolution = timerGetResolution(timer);
150-
return timer_val * 1000 / resolution;
149+
uint32_t frequency = timerGetResolution(timer);
150+
return timer_val * 1000 / frequency;
151151
}
152152

153153
double timerReadSeconds(hw_timer_t timer){
154154
uint64_t timer_val = timerRead(timer);
155-
uint32_t resolution = timerGetResolution(timer);
156-
return (double)timer_val / resolution;
155+
uint32_t frequency = timerGetResolution(timer);
156+
return (double)timer_val / frequency;
157157
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "C" {
3131
*/
3232
typedef gptimer_handle_t hw_timer_t;
3333

34-
hw_timer_t timerBegin(uint32_t resolution, bool countUp);
34+
hw_timer_t timerBegin(uint32_t frequency, bool countUp);
3535
void timerEnd(hw_timer_t timer);
3636

3737
void timerAttachInterrupt(hw_timer_t timer, void (*fn)(void));
@@ -48,9 +48,9 @@ uint64_t timerReadMicros(hw_timer_t timer);
4848
uint64_t timerReadMilis(hw_timer_t timer);
4949
double timerReadSeconds(hw_timer_t timer);
5050

51-
uint32_t timerGetResolution(hw_timer_t timer);
51+
uint32_t timerGetFrequency(hw_timer_t timer);
5252

53-
void timerAlarmWrite(hw_timer_t timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count);
53+
void timerAlarm(hw_timer_t timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count);
5454

5555
#ifdef __cplusplus
5656
}

Diff for: tests/timer/timer.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void timer_clock_select_test(void){
100100
// Set timer frequency that can be achieved using XTAL clock source (autoselected)
101101
timer_XTAL = timerBegin(TIMER_FREQUENCY_XTAL_CLK, true);
102102

103-
uint32_t resolution = timerGetResolution(timer_XTAL);
103+
uint32_t resolution = timerGetFrequency(timer_XTAL);
104104
TEST_ASSERT_EQUAL(TIMER_FREQUENCY_XTAL_CLK,resolution);
105105

106106
timerEnd(timer_XTAL);

0 commit comments

Comments
 (0)