Skip to content

Commit e8de5b5

Browse files
committed
refactor(gptimer): clean up SOC capabilities for GPTIMER and Timer Group
- Remove GPTIMER and TIMG related definitions from soc_caps_full.h files - Move timer peripheral definitions to appropriate HAL layer files - Update references across components to use proper HAL abstractions - Consolidate timer group and GPTIMER capabilities organization - Ensure consistent timer configuration across all ESP32 variants This refactoring improves the separation of concerns between SOC capabilities and HAL implementations for timer-related functionality.
1 parent 56c3dc4 commit e8de5b5

File tree

80 files changed

+357
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+357
-331
lines changed

components/esp_driver_gptimer/src/gptimer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ static esp_err_t gptimer_register_to_group(gptimer_t *timer)
4141
{
4242
gptimer_group_t *group = NULL;
4343
int timer_id = -1;
44-
for (int i = 0; i < SOC_TIMG_ATTR(INST_NUM); i++) {
44+
for (int i = 0; i < TIMG_LL_GET(INST_NUM); i++) {
4545
group = gptimer_acquire_group_handle(i);
4646
ESP_RETURN_ON_FALSE(group, ESP_ERR_NO_MEM, TAG, "no mem for group (%d)", i);
4747
// loop to search free timer in the group
4848
portENTER_CRITICAL(&group->spinlock);
49-
for (int j = 0; j < SOC_GPTIMER_ATTR(TIMERS_PER_TIMG); j++) {
49+
for (int j = 0; j < TIMG_LL_GET(GPTIMERS_PER_INST); j++) {
5050
if (!group->timers[j]) {
5151
timer_id = j;
5252
group->timers[j] = timer;

components/esp_driver_gptimer/src/gptimer_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
typedef struct gptimer_platform_t {
1414
_lock_t mutex; // platform level mutex lock
15-
gptimer_group_t *groups[SOC_TIMG_ATTR(INST_NUM)]; // timer group pool
16-
int group_ref_counts[SOC_TIMG_ATTR(INST_NUM)]; // reference count used to protect group install/uninstall
15+
gptimer_group_t *groups[TIMG_LL_GET(INST_NUM)]; // timer group pool
16+
int group_ref_counts[TIMG_LL_GET(INST_NUM)]; // reference count used to protect group install/uninstall
1717
} gptimer_platform_t;
1818

1919
// gptimer driver platform, it's always a singleton

components/esp_driver_gptimer/src/gptimer_priv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Set the maximum log level for gptimer driver
1515
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
1616
#endif
17-
#include "soc/soc_caps_full.h"
17+
#include "soc/soc_caps.h"
1818
#include "freertos/FreeRTOS.h"
1919
#include "esp_err.h"
2020
#include "esp_log.h"
@@ -23,7 +23,7 @@
2323
#include "esp_intr_alloc.h"
2424
#include "esp_heap_caps.h"
2525
#include "esp_pm.h"
26-
#include "soc/timer_periph.h"
26+
#include "hal/timer_periph.h"
2727
#include "hal/timer_types.h"
2828
#include "hal/timer_hal.h"
2929
#include "hal/timer_ll.h"
@@ -69,7 +69,7 @@ typedef struct gptimer_t gptimer_t;
6969
typedef struct gptimer_group_t {
7070
int group_id;
7171
portMUX_TYPE spinlock; // to protect per-group register level concurrent access
72-
gptimer_t *timers[SOC_GPTIMER_ATTR(TIMERS_PER_TIMG)];
72+
gptimer_t *timers[TIMG_LL_GET(GPTIMERS_PER_INST)];
7373
} gptimer_group_t;
7474

7575
typedef enum {

components/esp_driver_gptimer/test_apps/gptimer/main/test_gptimer.c

Lines changed: 54 additions & 54 deletions
Large diffs are not rendered by default.

components/esp_gdbstub/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ idf_component_register(SRCS ${srcs}
2828
PRIV_INCLUDE_DIRS ${priv_includes}
2929
LDFRAGMENTS "linker.lf"
3030
REQUIRES "freertos"
31-
PRIV_REQUIRES "soc" "esp_rom" "esp_system")
31+
PRIV_REQUIRES esp_hal_wdt)

components/esp_gdbstub/src/gdbstub.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@
55
*/
66

77
#include <string.h>
8-
#include "sys/reent.h"
8+
#include <sys/param.h>
9+
#include <sys/reent.h>
10+
#include "sdkconfig.h"
11+
#include "freertos/FreeRTOS.h"
12+
#include "freertos/task.h"
913
#include "esp_gdbstub.h"
1014
#include "esp_gdbstub_common.h"
1115
#include "esp_gdbstub_memory_regions.h"
12-
#include "sdkconfig.h"
13-
#include <sys/param.h>
14-
15-
#include "soc/soc_caps.h"
16-
#include "soc/uart_reg.h"
17-
#include "soc/periph_defs.h"
1816
#include "esp_attr.h"
1917
#include "esp_cpu.h"
2018
#include "esp_log.h"
2119
#include "esp_intr_alloc.h"
20+
21+
#include "soc/soc_caps.h"
22+
#include "soc/interrupts.h"
2223
#include "hal/wdt_hal.h"
23-
#include "freertos/FreeRTOS.h"
24-
#include "freertos/task.h"
25-
#include "sdkconfig.h"
2624

2725
#if GDBSTUB_QXFER_FEATURES_ENABLED
2826
#define GDBSTUB_QXFER_SUPPORTED_STR ";qXfer:features:read+"
@@ -124,18 +122,18 @@ static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
124122
static bool rtc_wdt_ctx_enabled = false;
125123
static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
126124
static bool wdt0_context_enabled = false;
127-
#if SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
125+
#if TIMG_LL_GET(INST_NUM) >= 2
128126
static wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1};
129127
static bool wdt1_context_enabled = false;
130-
#endif // SOC_MODULE_ATTR(TIMG, INST_NUM)
128+
#endif // TIMG_LL_GET(INST_NUM)
131129

132130
/**
133131
* Disable all enabled WDTs
134132
*/
135133
static inline void disable_all_wdts(void)
136134
{
137135
wdt0_context_enabled = wdt_hal_is_enabled(&wdt0_context);
138-
#if SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
136+
#if TIMG_LL_GET(INST_NUM) >= 2
139137
wdt1_context_enabled = wdt_hal_is_enabled(&wdt1_context);
140138
#endif
141139
rtc_wdt_ctx_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx);
@@ -148,15 +146,15 @@ static inline void disable_all_wdts(void)
148146
wdt_hal_write_protect_enable(&wdt0_context);
149147
}
150148

151-
#if SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
149+
#if TIMG_LL_GET(INST_NUM) >= 2
152150
/* Interrupt WDT is the Main Watchdog Timer of Timer Group 1 */
153151
if (true == wdt1_context_enabled) {
154152
wdt_hal_write_protect_disable(&wdt1_context);
155153
wdt_hal_disable(&wdt1_context);
156154
wdt_hal_feed(&wdt1_context);
157155
wdt_hal_write_protect_enable(&wdt1_context);
158156
}
159-
#endif // SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
157+
#endif // TIMG_LL_GET(INST_NUM) >= 2
160158

161159
if (true == rtc_wdt_ctx_enabled) {
162160
wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -177,14 +175,14 @@ static inline void enable_all_wdts(void)
177175
wdt_hal_enable(&wdt0_context);
178176
wdt_hal_write_protect_enable(&wdt0_context);
179177
}
180-
#if SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
178+
#if TIMG_LL_GET(INST_NUM) >= 2
181179
/* Interrupt WDT is the Main Watchdog Timer of Timer Group 1 */
182180
if (false == wdt1_context_enabled) {
183181
wdt_hal_write_protect_disable(&wdt1_context);
184182
wdt_hal_enable(&wdt1_context);
185183
wdt_hal_write_protect_enable(&wdt1_context);
186184
}
187-
#endif // SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2
185+
#endif // TIMG_LL_GET(INST_NUM) >= 2
188186

189187
if (false == rtc_wdt_ctx_enabled) {
190188
wdt_hal_write_protect_disable(&rtc_wdt_ctx);

components/esp_hal_timg/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# ESP Hardware Abstraction Layer for Timer Groups (`esp_hal_timg`)
1+
# ESP Hardware Abstraction Layer for Timer Group Peripheral
22

3-
⚠️ **Notice**: This HAL component is under active development. API stability and backward-compatibility between versions are not guaranteed at this time.
3+
> [!NOTE]
4+
> This component is currently in beta. Its API, behavior, and compatibility may change at any time and without notice; backward compatibility is not guaranteed. Use caution when integrating into production systems.
45
56
## Overview
67

@@ -11,7 +12,7 @@ The `esp_hal_timg` component provides a **Hardware Abstraction Layer** for the G
1112
The HAL architecture consists of two primary layers:
1213

1314
1. **HAL Layer (Upper)**: Defines the operational sequences and data structures required to interact with timer peripherals, including:
14-
- Initialization and deinitialization
15+
- Initialization and de-initialization
1516
- Timer control operations (start, stop, reload)
1617
- Alarm and event handling
1718
- Counter operations

components/esp_hal_timg/esp32/include/hal/lact_ll.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#include "soc/timer_group_struct.h"
1414
#include "soc/dport_reg.h"
1515

16+
// Get timer group register base address with giving group number
17+
#define LACT_LL_GET_HW(group_id) ((group_id == 0) ? (&TIMERG0) : (&TIMERG1))
18+
1619
#ifdef __cplusplus
1720
extern "C" {
1821
#endif
1922

20-
// Get timer group register base address with giving group number
21-
#define LACT_LL_GET_HW(group_id) ((group_id == 0) ? (&TIMERG0) : (&TIMERG1))
22-
2323
/**
2424
* @brief Set clock prescale for LACT timer
2525
*

components/esp_hal_timg/esp32/include/hal/timer_ll.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@
1515
#include "soc/timer_group_struct.h"
1616
#include "soc/dport_reg.h"
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
18+
// Total number of general purpose timers
19+
#define TIMER_LL_GPTIMERS_TOTAL (TIMG_LL_INST_NUM * TIMG_LL_GPTIMERS_PER_INST)
2120

2221
// Get timer group register base address with giving group number
2322
#define TIMER_LL_GET_HW(group_id) ((group_id == 0) ? (&TIMERG0) : (&TIMERG1))
2423

24+
// Bit width of GPTIMER counter
25+
#define TIMER_LL_COUNTER_BIT_WIDTH 64
26+
2527
// Get alarm interrupt mask with the given timer ID
2628
#define TIMER_LL_EVENT_ALARM(timer_id) (1 << (timer_id))
2729

2830
// Support APB as function clock
2931
#define TIMER_LL_FUNC_CLOCK_SUPPORT_APB 1
3032

33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
3137
/**
3238
* @brief Set clock source for timer
3339
*

components/esp_hal_timg/esp32/include/hal/timg_ll.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
#include "soc/timer_group_struct.h"
1515
#include "soc/dport_reg.h"
1616

17+
#define TIMG_LL_GET(_attr) TIMG_LL_ ## _attr
18+
19+
// Number of Timer Group instances
20+
#define TIMG_LL_INST_NUM 2
21+
22+
// Number of general purpose timers in each Timer Group
23+
#define TIMG_LL_GPTIMERS_PER_INST 2
24+
1725
#ifdef __cplusplus
1826
extern "C" {
1927
#endif

0 commit comments

Comments
 (0)