Skip to content

Commit

Permalink
Merge branch 'feature/esp_driver_gptimer' into 'master'
Browse files Browse the repository at this point in the history
refactor(gptimer): refactor gptimer driver into a component

Closes IDF-8375

See merge request espressif/esp-idf!26716
  • Loading branch information
suda-morris committed Nov 6, 2023
2 parents e4d70e9 + f2304a5 commit 5f9d8a7
Show file tree
Hide file tree
Showing 47 changed files with 152 additions and 55 deletions.
4 changes: 2 additions & 2 deletions components/app_trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion components/app_trace/linker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion components/app_trace/test_apps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 3 additions & 12 deletions components/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(includes "include"
"deprecated"
"analog_comparator/include"
"dac/include"
"gptimer/include"
"i2c/include"
"i2s/include"
"ledc/include"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions components/driver/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions components/driver/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/esp_adc/test_apps/adc/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions components/esp_driver_gptimer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions components/esp_driver_gptimer/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions components/esp_driver_pcnt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions components/esp_hw_support/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion components/esp_hw_support/test_apps/etm/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions components/spi_flash/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions docs/doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions docs/en/migration-guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions docs/en/migration-guides/release-5.x/5.3/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Migration from 5.2 to 5.3
-------------------------

:link_to_translation:`zh_CN:[中文]`

.. toctree::
:maxdepth: 1

peripherals
30 changes: 30 additions & 0 deletions docs/en/migration-guides/release-5.x/5.3/peripherals.rst
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions docs/zh_CN/migration-guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions docs/zh_CN/migration-guides/release-5.x/5.3/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
从 5.2 迁移到 5.3
-----------------

:link_to_translation:`en:[English]`

.. toctree::
:maxdepth: 1

peripherals
30 changes: 30 additions & 0 deletions docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 11 additions & 1 deletion examples/peripherals/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/system/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ examples/system/eventfd:
- if: SOC_GPTIMER_SUPPORTED != 1
depends_components:
- vfs
- driver
- esp_driver_gptimer

examples/system/flash_suspend:
enable:
Expand Down
2 changes: 1 addition & 1 deletion tools/test_apps/system/g1_components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tools/unit-test-app/components/test_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 5f9d8a7

Please sign in to comment.