Merge branch 'feature/esp_driver_gptimer' into 'master'

refactor(gptimer): refactor gptimer driver into a component

Closes IDF-8375

See merge request espressif/esp-idf!26716
This commit is contained in:
morris 2023-11-07 01:17:29 +08:00
commit 5f9d8a77ed
47 changed files with 152 additions and 55 deletions

View File

@ -63,8 +63,8 @@ endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
# Requires "driver" for GPTimer in "SEGGER_SYSVIEW_Config_FreeRTOS.c"
PRIV_REQUIRES soc driver esp_driver_gpio
PRIV_REQUIRES soc esp_driver_gptimer esp_driver_gpio
driver # TODO: replace with esp_driver_uart (IDF-8384)
REQUIRES esp_timer
LDFRAGMENTS linker.lf)

View File

@ -15,7 +15,7 @@ entries:
SEGGER_SYSVIEW_FreeRTOS (noflash)
[mapping:app_trace_driver]
archive: libdriver.a
archive: libesp_driver_gptimer.a
entries:
if APPTRACE_SV_TS_SOURCE_GPTIMER = y:
gptimer (noflash)

View File

@ -1,4 +1,4 @@
idf_component_register(SRCS "test_app_trace_main.c" "test_trace.c"
INCLUDE_DIRS "."
PRIV_REQUIRES app_trace unity driver
PRIV_REQUIRES app_trace unity esp_driver_gptimer
WHOLE_ARCHIVE)

View File

@ -13,7 +13,6 @@ set(includes "include"
"deprecated"
"analog_comparator/include"
"dac/include"
"gptimer/include"
"i2c/include"
"i2s/include"
"ledc/include"
@ -66,17 +65,9 @@ if(CONFIG_SOC_PARLIO_SUPPORTED)
list(APPEND srcs "parlio/parlio_common.c" "parlio/parlio_tx.c")
endif()
# GPTimer related source files
# GPTimer legacy driver
if(CONFIG_SOC_GPTIMER_SUPPORTED)
list(APPEND srcs "gptimer/gptimer.c"
"gptimer/gptimer_priv.c"
"deprecated/timer_legacy.c")
list(APPEND ldfragments "gptimer/linker.lf")
endif()
if(CONFIG_SOC_TIMER_SUPPORT_ETM)
list(APPEND srcs "gptimer/gptimer_etm.c")
list(APPEND srcs "deprecated/timer_legacy.c")
endif()
# I2C related source files
@ -226,7 +217,7 @@ else()
REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support
# for backward compatibility, the driver component needs to
# have a public dependency on other "esp_driver_foo" components
esp_driver_gpio esp_driver_pcnt
esp_driver_gpio esp_driver_pcnt esp_driver_gptimer
LDFRAGMENTS ${ldfragments}
)
endif()

View File

@ -207,10 +207,6 @@ menu "Driver Configurations"
Note that, this option only controls the Analog Comparator driver log, won't affect other drivers.
endmenu # Analog Comparator Configuration
orsource "./gptimer/Kconfig.gptimer"
orsource "../esp_driver_pcnt/Kconfig.pcnt"
orsource "./rmt/Kconfig.rmt"
orsource "./mcpwm/Kconfig.mcpwm"

View File

@ -16,10 +16,6 @@ components/driver/test_apps/dac_test_apps/legacy_dac_driver:
disable:
- if: SOC_DAC_SUPPORTED != 1
components/driver/test_apps/gptimer:
disable:
- if: SOC_GPTIMER_SUPPORTED != 1
components/driver/test_apps/i2c_test_apps:
disable:
- if: SOC_I2C_SUPPORTED != 1 # TODO: IDF-8070

View File

@ -9,5 +9,5 @@ set(srcs "test_app_main.c"
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs}
PRIV_REQUIRES driver esp_wifi nvs_flash esp_adc test_utils efuse
PRIV_REQUIRES esp_driver_gptimer esp_driver_gpio esp_wifi nvs_flash esp_adc test_utils efuse
WHOLE_ARCHIVE)

View File

@ -0,0 +1,16 @@
set(srcs)
set(public_include "include")
if(CONFIG_SOC_GPTIMER_SUPPORTED)
list(APPEND srcs "src/gptimer.c"
"src/gptimer_priv.c")
endif()
if(CONFIG_SOC_TIMER_SUPPORT_ETM)
list(APPEND srcs "src/gptimer_etm.c")
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,4 +1,4 @@
menu "GPTimer Configuration"
menu "ESP-Driver:GPTimer Configurations"
depends on SOC_GPTIMER_SUPPORTED
config GPTIMER_ISR_HANDLER_IN_IRAM
bool "Place GPTimer ISR handler into IRAM"
@ -36,4 +36,4 @@ menu "GPTimer Configuration"
help
Wether to enable the debug log message for GPTimer driver.
Note that, this option only controls the GPTimer driver log, won't affect other drivers.
endmenu # GPTimer Configuration
endmenu

View File

@ -35,7 +35,7 @@ typedef struct {
* @param[in] user_ctx User data, passed from `gptimer_register_event_callbacks`
* @return Whether a high priority task has been waken up by this function
*/
typedef bool (*gptimer_alarm_cb_t) (gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx);
typedef bool (*gptimer_alarm_cb_t)(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
[mapping:gptimer_driver]
archive: libdriver.a
archive: libesp_driver_gptimer.a
entries:
if GPTIMER_ISR_HANDLER_IN_IRAM = y:
gptimer: gptimer_default_isr (noflash)

View File

@ -254,8 +254,8 @@ esp_err_t gptimer_register_event_callbacks(gptimer_handle_t timer, const gptimer
isr_flags |= 1 << (timer->intr_priority);
}
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(timer_group_periph_signals.groups[group_id].timer_irq_id[timer_id], isr_flags,
(uint32_t)timer_ll_get_intr_status_reg(timer->hal.dev), TIMER_LL_EVENT_ALARM(timer_id),
gptimer_default_isr, timer, &timer->intr), TAG, "install interrupt service failed");
(uint32_t)timer_ll_get_intr_status_reg(timer->hal.dev), TIMER_LL_EVENT_ALARM(timer_id),
gptimer_default_isr, timer, &timer->intr), TAG, "install interrupt service failed");
}
// enable/disable GPTimer interrupt events

View File

@ -0,0 +1,7 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp_driver_gptimer/test_apps/gptimer:
disable:
- if: SOC_GPTIMER_SUPPORTED != 1
depends_components:
- esp_driver_gptimer

View File

@ -10,7 +10,7 @@ project(gptimer_test)
if(CONFIG_COMPILER_DUMP_RTL_FILES)
add_custom_target(check_test_app_sections ALL
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_gptimer/,${CMAKE_BINARY_DIR}/esp-idf/hal/
--elf-file ${CMAKE_BINARY_DIR}/gptimer_test.elf
find-refs
--from-sections=.iram0.text

View File

@ -4,14 +4,8 @@ if(CONFIG_SOC_PCNT_SUPPORTED)
list(APPEND srcs "src/pulse_cnt.c")
endif()
if(BOOTLOADER_BUILD)
# Bootloader shall NOT depend on the drivers
idf_component_register()
else()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm"
"esp_driver_gpio"
LDFRAGMENTS "linker.lf"
)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
LDFRAGMENTS "linker.lf"
)

View File

@ -1,4 +1,4 @@
menu "PCNT Configuration"
menu "ESP-Driver:PCNT Configurations"
depends on SOC_PCNT_SUPPORTED
config PCNT_CTRL_FUNC_IN_IRAM
bool "Place PCNT control functions into IRAM"
@ -29,4 +29,4 @@ menu "PCNT Configuration"
help
Wether to enable the debug log message for PCNT driver.
Note that, this option only controls the PCNT driver log, won't affect other drivers.
endmenu # PCNT Configuration
endmenu

View File

@ -13,6 +13,11 @@ components/esp_hw_support/test_apps/esp_hw_support_unity_tests:
components/esp_hw_support/test_apps/etm:
disable:
- if: SOC_ETM_SUPPORTED != 1
depends_components:
- esp_driver_gptimer
- esp_driver_gpio
- esp_timer
- driver # TODO: replace with esp_driver_mcpwm, esp_driver_ana_cmpr
components/esp_hw_support/test_apps/host_test_linux:
enable:

View File

@ -29,5 +29,6 @@ endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity esp_timer driver
PRIV_REQUIRES unity esp_timer esp_driver_gptimer esp_driver_gpio
driver # TODO: replace with esp_driver_mcpwm (IDF-8379), esp_driver_ana_cmpr
WHOLE_ARCHIVE)

View File

@ -38,10 +38,9 @@ components/spi_flash/test_apps/flash_suspend:
- if: IDF_TARGET != "esp32c3"
temporary: true
reason: lack of runners
depends_filepatterns:
- components/driver/gptimer/**/*
depends_components:
- spi_flash
- esp_driver_gptimer
components/spi_flash/test_apps/mspi_test:
disable:

View File

@ -79,9 +79,6 @@ INPUT = \
$(PROJECT_PATH)/components/driver/dac/include/driver/dac_cosine.h \
$(PROJECT_PATH)/components/driver/dac/include/driver/dac_oneshot.h \
$(PROJECT_PATH)/components/driver/dac/include/driver/dac_types.h \
$(PROJECT_PATH)/components/driver/gptimer/include/driver/gptimer.h \
$(PROJECT_PATH)/components/driver/gptimer/include/driver/gptimer_etm.h \
$(PROJECT_PATH)/components/driver/gptimer/include/driver/gptimer_types.h \
$(PROJECT_PATH)/components/driver/i2c/include/driver/i2c.h \
$(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_common.h \
$(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_pdm.h \
@ -139,6 +136,9 @@ INPUT = \
$(PROJECT_PATH)/components/esp_driver_gpio/include/driver/gpio_filter.h \
$(PROJECT_PATH)/components/esp_driver_gpio/include/driver/lp_io.h \
$(PROJECT_PATH)/components/esp_driver_gpio/include/driver/rtc_io.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_etm.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_types.h \
$(PROJECT_PATH)/components/esp_driver_pcnt/include/driver/pulse_cnt.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_driver.h \

View File

@ -12,3 +12,4 @@ ESP-IDF 5.x Migration Guide
release-5.x/5.0/index
release-5.x/5.1/index
release-5.x/5.2/index
release-5.x/5.3/index

View File

@ -0,0 +1,9 @@
Migration from 5.2 to 5.3
-------------------------
:link_to_translation:`zh_CN:[中文]`
.. toctree::
:maxdepth: 1
peripherals

View File

@ -0,0 +1,30 @@
Peripherals
===========
:link_to_translation:`zh_CN:[中文]`
In order to control the dependence of other components on drivers at a smaller granularity, the original peripheral drivers under the `driver`` component were split into separate components:
- `esp_driver_gptimer` - Driver for general purpose timers
- `esp_driver_pcnt` - Driver for pulse counter
- `esp_driver_gpio` - Driver for GPIO
For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on.
Originally, you may have used **linker.lf** to specify the link location of some driver functions in memory space, but now, because the location of the driver files have been moved, you need to make changes your **linker.lf** file accordingly. For example, a linker.lf file with the following entries:
.. code-block:: none
[mapping:my_mapping_scheme]
archive: libdriver.a
entries:
gpio (noflash)
Should be changed to:
.. code-block:: none
[mapping:my_mapping_scheme]
archive: libesp_driver_gpio.a
entries:
gpio (noflash)

View File

@ -12,3 +12,4 @@
release-5.x/5.0/index
release-5.x/5.1/index
release-5.x/5.2/index
release-5.x/5.3/index

View File

@ -0,0 +1,9 @@
从 5.2 迁移到 5.3
-----------------
:link_to_translation:`en:[English]`
.. toctree::
:maxdepth: 1
peripherals

View File

@ -0,0 +1,30 @@
外设
====
:link_to_translation:`en:[English]`
为了细粒度地控制其他组件对外设驱动的依赖,原先位于 `driver` 组件下的驱动程序被拆分到了各自独立的组件中。这些组件包括:
- `esp_driver_gptimer` - 通用定时器驱动
- `esp_driver_pcnt` - 脉冲计数器驱动
- `esp_driver_gpio` - GPIO 驱动
为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。
原来你可能使用 **linker.lf** 指定了一些驱动函数在内存空间的链接位置,但是现在,因为驱动文件的位置发生了挪动,就需要你对 **linker.lf** 文件做出相应的改动的。假如,你的 linker.lf 文件里面有以下的条目:
.. code-block:: none
[mapping:my_mapping_scheme]
archive: libdriver.a
entries:
gpio (noflash)
现在需要修改成:
.. code-block:: none
[mapping:my_mapping_scheme]
archive: libesp_driver_gpio.a
entries:
gpio (noflash)

View File

@ -299,13 +299,23 @@ examples/peripherals/temperature_sensor/temp_sensor_monitor:
disable:
- if: SOC_TEMPERATURE_SENSOR_INTR_SUPPORT != 1
examples/peripherals/timer_group:
examples/peripherals/timer_group/gptimer:
disable:
- if: SOC_GPTIMER_SUPPORTED != 1
depends_components:
- esp_driver_gptimer
examples/peripherals/timer_group/gptimer_capture_hc_sr04:
disable:
- if: SOC_TIMER_SUPPORT_ETM != 1
depends_components:
- esp_driver_gptimer
examples/peripherals/timer_group/legacy_driver:
disable:
- if: SOC_GPTIMER_SUPPORTED != 1
depends_components:
- driver # legacy driver is still located in the "driver" component
examples/peripherals/touch_sensor:
disable:

View File

@ -81,7 +81,7 @@ examples/system/eventfd:
- if: SOC_GPTIMER_SUPPORTED != 1
depends_components:
- vfs
- driver
- esp_driver_gptimer
examples/system/flash_suspend:
enable:

View File

@ -35,7 +35,7 @@ set(extra_components_which_shouldnt_be_included
cxx
# [refactor-todo]: driver is a dependency of esp_pm, spi_flash, vfs, esp_wifi
# all of these should be removed from G1 except for spi_flash.
driver esp_driver_gpio esp_driver_pcnt
driver esp_driver_gpio esp_driver_pcnt esp_driver_gptimer
# esp_app_format is dependency of bootloader_support, app_update
esp_app_format
# esp_bootloader_format is dependency of bootloader_support, app_update

View File

@ -16,5 +16,7 @@ endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS include
REQUIRES esp_partition idf_test cmock
PRIV_REQUIRES perfmon esp_driver_pcnt driver esp_netif)
PRIV_REQUIRES perfmon esp_driver_pcnt esp_driver_gptimer esp_netif
driver # TODO: replace with esp_driver_rmt
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")