esp_rom: patch systimer driver for esp32c2

This commit is contained in:
morris 2022-07-25 11:27:42 +08:00
parent d94432fea8
commit 783e1781bd
5 changed files with 81 additions and 7 deletions

View File

@ -28,6 +28,10 @@ if(CONFIG_IDF_TARGET_ARCH_XTENSA)
list(APPEND sources "patches/esp_rom_longjmp.S") list(APPEND sources "patches/esp_rom_longjmp.S")
endif() endif()
if(CONFIG_SOC_SYSTIMER_SUPPORTED)
list(APPEND sources "patches/esp_rom_systimer.c")
endif()
idf_component_register(SRCS ${sources} idf_component_register(SRCS ${sources}
INCLUDE_DIRS ${include_dirs} INCLUDE_DIRS ${include_dirs}
PRIV_REQUIRES ${private_required_comp} PRIV_REQUIRES ${private_required_comp}

View File

@ -211,20 +211,21 @@ PROVIDE( wdt_hal_handle_intr = 0x40000298 );
PROVIDE( wdt_hal_feed = 0x4000029c ); PROVIDE( wdt_hal_feed = 0x4000029c );
PROVIDE( wdt_hal_set_flashboot_en = 0x400002a0 ); PROVIDE( wdt_hal_set_flashboot_en = 0x400002a0 );
PROVIDE( wdt_hal_is_enabled = 0x400002a4 ); PROVIDE( wdt_hal_is_enabled = 0x400002a4 );
PROVIDE( systimer_hal_init = 0x400002a8 );
PROVIDE( systimer_hal_get_counter_value = 0x400002ac ); PROVIDE( systimer_hal_get_counter_value = 0x400002ac );
PROVIDE( systimer_hal_get_time = 0x400002b0 );
PROVIDE( systimer_hal_set_alarm_target = 0x400002b4 );
PROVIDE( systimer_hal_set_alarm_period = 0x400002b8 );
PROVIDE( systimer_hal_get_alarm_value = 0x400002bc ); PROVIDE( systimer_hal_get_alarm_value = 0x400002bc );
PROVIDE( systimer_hal_enable_alarm_int = 0x400002c0 ); PROVIDE( systimer_hal_enable_alarm_int = 0x400002c0 );
PROVIDE( systimer_hal_on_apb_freq_update = 0x400002c4 );
PROVIDE( systimer_hal_counter_value_advance = 0x400002c8 );
PROVIDE( systimer_hal_enable_counter = 0x400002cc ); PROVIDE( systimer_hal_enable_counter = 0x400002cc );
PROVIDE( systimer_hal_select_alarm_mode = 0x400002d0 ); PROVIDE( systimer_hal_select_alarm_mode = 0x400002d0 );
PROVIDE( systimer_hal_connect_alarm_counter = 0x400002d4 ); PROVIDE( systimer_hal_connect_alarm_counter = 0x400002d4 );
PROVIDE( systimer_hal_counter_can_stall_by_cpu = 0x400002d8 ); PROVIDE( systimer_hal_counter_can_stall_by_cpu = 0x400002d8 );
/* The following ROM functions are commented out because they're patched in the esp_rom_systimer.c */
/* PROVIDE( systimer_hal_init = 0x400002a8 ); */
/* PROVIDE( systimer_hal_get_time = 0x400002b0 ); */
/* PROVIDE( systimer_hal_set_alarm_target = 0x400002b4 ); */
/* PROVIDE( systimer_hal_set_alarm_period = 0x400002b8 ); */
/* PROVIDE( systimer_hal_counter_value_advance = 0x400002c8 ); */
/*************************************** /***************************************
Group heap Group heap

View File

@ -3,3 +3,5 @@ archive: libesp_rom.a
entries: entries:
esp_rom_spiflash (noflash) esp_rom_spiflash (noflash)
esp_rom_regi2c (noflash) esp_rom_regi2c (noflash)
if SOC_SYSTIMER_SUPPORTED = y:
esp_rom_systimer (noflash)

View File

@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include <stddef.h>
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#if CONFIG_HAL_SYSTIMER_USE_ROM_IMPL
#if CONFIG_IDF_TARGET_ESP32C2
void systimer_hal_init(systimer_hal_context_t *hal)
{
hal->dev = &SYSTIMER;
systimer_ll_enable_clock(hal->dev, true);
}
void systimer_hal_deinit(systimer_hal_context_t *hal)
{
systimer_ll_enable_clock(hal->dev, false);
hal->dev = NULL;
}
void systimer_hal_set_tick_rate_ops(systimer_hal_context_t *hal, systimer_hal_tick_rate_ops_t *ops)
{
hal->ticks_to_us = ops->ticks_to_us;
hal->us_to_ticks = ops->us_to_ticks;
}
uint64_t systimer_hal_get_time(systimer_hal_context_t *hal, uint32_t counter_id)
{
return hal->ticks_to_us(systimer_hal_get_counter_value(hal, counter_id));
}
void systimer_hal_set_alarm_target(systimer_hal_context_t *hal, uint32_t alarm_id, uint64_t target)
{
systimer_counter_value_t alarm = {
.val = hal->us_to_ticks(target),
};
systimer_ll_enable_alarm(hal->dev, alarm_id, false);
systimer_ll_set_alarm_target(hal->dev, alarm_id, alarm.val);
systimer_ll_apply_alarm_value(hal->dev, alarm_id);
systimer_ll_enable_alarm(hal->dev, alarm_id, true);
}
void systimer_hal_set_alarm_period(systimer_hal_context_t *hal, uint32_t alarm_id, uint32_t period)
{
systimer_ll_enable_alarm(hal->dev, alarm_id, false);
systimer_ll_set_alarm_period(hal->dev, alarm_id, hal->us_to_ticks(period));
systimer_ll_apply_alarm_value(hal->dev, alarm_id);
systimer_ll_enable_alarm(hal->dev, alarm_id, true);
}
void systimer_hal_counter_value_advance(systimer_hal_context_t *hal, uint32_t counter_id, int64_t time_us)
{
systimer_counter_value_t new_count = {
.val = systimer_hal_get_counter_value(hal, counter_id) + hal->us_to_ticks(time_us),
};
systimer_ll_set_counter_value(hal->dev, counter_id, new_count.val);
systimer_ll_apply_counter_value(hal->dev, counter_id);
}
#endif // CONFIG_IDF_TARGET_ESP32C2
#endif // CONFIG_HAL_SYSTIMER_USE_ROM_IMPL

View File

@ -67,7 +67,7 @@ menu "Hardware Abstraction Layer (HAL) and Low Level (LL)"
config HAL_SYSTIMER_USE_ROM_IMPL config HAL_SYSTIMER_USE_ROM_IMPL
bool "Use ROM implementation of SysTimer HAL driver" bool "Use ROM implementation of SysTimer HAL driver"
depends on ESP_ROM_HAS_HAL_SYSTIMER && !ESP32C2_XTAL_FREQ_26 depends on ESP_ROM_HAS_HAL_SYSTIMER
default y default y
help help
Enable this flag to use HAL functions from ROM instead of ESP-IDF. Enable this flag to use HAL functions from ROM instead of ESP-IDF.