Skip to content

Commit cff71c8

Browse files
sylvioalvescarlescufi
authored andcommitted
driver: systimer: increase esp32c3 tick resolution
hal_espressif systimer HAL calls are based on 1MHz reference. This changes systimer driver to allow max clocking reference of 16MHz and increases soc tick resolution by reducing min delay interval. This also sets all ESP32-C3 socs to 16MHz hardware cycles reference. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 691322a commit cff71c8

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

boards/riscv/esp32c3_devkitm/esp32c3_devkitm_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
CONFIG_BOARD_ESP32C3_DEVKITM=y
44
CONFIG_SOC_ESP32C3=y
55
CONFIG_MAIN_STACK_SIZE=2048
6-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000
76
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
87
CONFIG_CONSOLE=y
98
CONFIG_SERIAL=y

boards/riscv/icev_wireless/icev_wireless_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
CONFIG_BOARD_ICEV_WIRELESS=y
44
CONFIG_SOC_ESP32C3=y
55
CONFIG_MAIN_STACK_SIZE=2048
6-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000
76
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
87
CONFIG_CONSOLE=y
98
CONFIG_SERIAL=y

boards/riscv/xiao_esp32c3/xiao_esp32c3_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
CONFIG_BOARD_XIAO_ESP32C3=y
44
CONFIG_SOC_ESP32C3=y
55
CONFIG_MAIN_STACK_SIZE=2048
6-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000
76
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
87
CONFIG_CONSOLE=y
98
CONFIG_SERIAL=y

drivers/timer/esp32c3_sys_timer.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/ (uint64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC))
2525
#define MAX_CYC 0xffffffffu
2626
#define MAX_TICKS ((MAX_CYC - CYC_PER_TICK) / CYC_PER_TICK)
27-
#define MIN_DELAY 1000
27+
#define MIN_DELAY 1
2828

2929
#if defined(CONFIG_TEST)
3030
const int32_t z_sys_timer_irq_for_test = DT_IRQN(DT_NODELABEL(systimer0));
@@ -43,13 +43,18 @@ static void set_systimer_alarm(uint64_t time)
4343
systimer_hal_select_alarm_mode(&systimer_hal,
4444
SYSTIMER_LL_ALARM_OS_TICK_CORE0, SYSTIMER_ALARM_MODE_ONESHOT);
4545

46-
systimer_hal_set_alarm_target(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0, time);
47-
systimer_hal_enable_alarm_int(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0);
46+
systimer_counter_value_t alarm = {.val = time};
47+
48+
systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0, false);
49+
systimer_ll_set_alarm_target(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0, alarm.val);
50+
systimer_ll_apply_alarm_value(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0);
51+
systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0, true);
52+
systimer_ll_enable_alarm_int(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0, true);
4853
}
4954

5055
static uint64_t get_systimer_alarm(void)
5156
{
52-
return systimer_hal_get_time(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK);
57+
return systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK);
5358
}
5459

5560
static void sys_timer_isr(const void *arg)

soc/riscv/esp32c3/Kconfig.defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ config ATOMIC_OPERATIONS_C
5151
config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
5252
default n
5353

54+
config SYS_CLOCK_HW_CYCLES_PER_SEC
55+
default 16000000
56+
5457
endif

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ manifest:
5757
groups:
5858
- hal
5959
- name: hal_espressif
60-
revision: 15c84e32d557545d662392e72ca86e3d88382c03
60+
revision: 1a2292632131d09549b527917cfd0ad7cd78338c
6161
path: modules/hal/espressif
6262
west-commands: west/west-commands.yml
6363
groups:

0 commit comments

Comments
 (0)