Skip to content

Commit 0a11047

Browse files
committed
feat(modem_etm): support modem etm on h4
1 parent 026370e commit 0a11047

File tree

5 files changed

+243
-0
lines changed

5 files changed

+243
-0
lines changed

components/esp_hw_support/include/esp_private/etm_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef enum {
2929
ETM_TRIG_PERIPH_TSENS, /*!< ETM trigger source: Temperature Sensor */
3030
ETM_TRIG_PERIPH_I2S, /*!< ETM trigger source: I2S */
3131
ETM_TRIG_PERIPH_LP_CORE, /*!< ETM trigger source: Low-Power Core */
32+
ETM_TRIG_PERIPH_MODEM, /*!< ETM trigger source: Modem */
3233
} etm_trigger_peripheral_t;
3334

3435
/**
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/**
16+
* @brief Modem ETM event type
17+
*
18+
* @note The event type is used to identify the event type.
19+
*/
20+
typedef enum {
21+
MODEM_ETM_EVENT_G0 = 0, /*!< Modem ETM event group 0 */
22+
MODEM_ETM_EVENT_G1 = 1, /*!< Modem ETM event group 1 */
23+
MODEM_ETM_EVENT_G2 = 2, /*!< Modem ETM event group 2 */
24+
MODEM_ETM_EVENT_G3 = 3, /*!< Modem ETM event group 3 */
25+
MODEM_ETM_EVENT_MAX,
26+
} modem_etm_event_type_t;
27+
28+
/**
29+
* @brief Modem ETM task type
30+
*
31+
* @note The task type is used to identify the task type.
32+
*/
33+
typedef enum {
34+
MODEM_ETM_TASK_G0 = 0, /*!< Modem ETM task group 0 */
35+
MODEM_ETM_TASK_G1 = 1, /*!< Modem ETM task group 1 */
36+
MODEM_ETM_TASK_G2 = 2, /*!< Modem ETM task group 2 */
37+
MODEM_ETM_TASK_G3 = 3, /*!< Modem ETM task group 3 */
38+
MODEM_ETM_TASK_MAX,
39+
} modem_etm_task_type_t;
40+
41+
/**
42+
* @brief Modem ETM event configuration
43+
*
44+
* @note The event configuration is used to configure the event.
45+
*/
46+
typedef struct {
47+
modem_etm_event_type_t event_type; /*!< Modem ETM event type */
48+
} modem_etm_event_config_t;
49+
50+
/**
51+
* @brief Modem ETM task configuration
52+
*
53+
* @note The task configuration is used to configure the task.
54+
*/
55+
typedef struct {
56+
modem_etm_task_type_t task_type; /*!< Modem ETM task type */
57+
} modem_etm_task_config_t;
58+
59+
60+
/**
61+
* @brief Create a new modem ETM event
62+
*
63+
* @param config The modem ETM event configuration
64+
* @param out_event The output modem ETM event handle
65+
* @return
66+
* - ESP_OK: Success
67+
* - ESP_ERR_INVALID_ARG: Invalid argument
68+
* - ESP_ERR_NO_MEM: No memory
69+
*/
70+
esp_err_t modem_new_etm_event(const modem_etm_event_config_t *config, esp_etm_event_handle_t *out_event);
71+
72+
/**
73+
* @brief Create a new modem ETM task
74+
*
75+
* @param config The modem ETM task configuration
76+
* @param out_task The output modem ETM task handle
77+
* @return
78+
* - ESP_OK: Success
79+
* - ESP_ERR_INVALID_ARG: Invalid argument
80+
* - ESP_ERR_NO_MEM: No memory
81+
*/
82+
esp_err_t modem_new_etm_task(const modem_etm_task_config_t *config, esp_etm_task_handle_t *out_task);
83+
84+
#ifdef __cplusplus
85+
}
86+
#endif
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdlib.h>
8+
#include <sys/cdefs.h>
9+
#include "sdkconfig.h"
10+
#include "esp_log.h"
11+
#include "esp_check.h"
12+
#include "esp_heap_caps.h"
13+
#include "modem/modem_etm.h"
14+
#include "hal/modem_ll.h"
15+
#include "esp_private/etm_interface.h"
16+
17+
#define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
18+
19+
static const char *TAG = "modem-etm";
20+
21+
static esp_err_t s_modem_del_etm_event(esp_etm_event_t *event)
22+
{
23+
free(event);
24+
return ESP_OK;
25+
}
26+
27+
static esp_err_t s_modem_del_etm_task(esp_etm_task_t *task)
28+
{
29+
free(task);
30+
return ESP_OK;
31+
}
32+
33+
esp_err_t modem_new_etm_event(const modem_etm_event_config_t *config, esp_etm_event_handle_t *out_event)
34+
{
35+
ESP_RETURN_ON_FALSE(config && out_event, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
36+
ESP_RETURN_ON_FALSE(config->event_type < MODEM_ETM_EVENT_MAX, ESP_ERR_INVALID_ARG, TAG, "invalid event type");
37+
esp_etm_event_t *event = heap_caps_calloc(1, sizeof(esp_etm_event_t), ETM_MEM_ALLOC_CAPS);
38+
ESP_RETURN_ON_FALSE(event, ESP_ERR_NO_MEM, TAG, "no memory for ETM event");
39+
40+
// Get the event id from the modem ETM event table
41+
uint32_t event_id = MODEM_LL_ETM_EVENT_TABLE((uint32_t)config->event_type);
42+
43+
// fill the ETM event object
44+
event->event_id = event_id;
45+
event->trig_periph = ETM_TRIG_PERIPH_MODEM;
46+
event->del = s_modem_del_etm_event;
47+
*out_event = event;
48+
49+
return ESP_OK;
50+
}
51+
52+
esp_err_t modem_new_etm_task(const modem_etm_task_config_t *config, esp_etm_task_handle_t *out_task)
53+
{
54+
ESP_RETURN_ON_FALSE(config && out_task, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
55+
ESP_RETURN_ON_FALSE(config->task_type < MODEM_ETM_TASK_MAX, ESP_ERR_INVALID_ARG, TAG, "invalid task type");
56+
esp_etm_task_t *task = heap_caps_calloc(1, sizeof(esp_etm_task_t), ETM_MEM_ALLOC_CAPS);
57+
ESP_RETURN_ON_FALSE(task, ESP_ERR_NO_MEM, TAG, "no memory for ETM task");
58+
59+
// Get the task id from the modem ETM task table
60+
uint32_t task_id = MODEM_LL_ETM_TASK_TABLE((uint32_t)config->task_type);
61+
62+
// fill the ETM task object
63+
task->task_id = task_id;
64+
task->trig_periph = ETM_TRIG_PERIPH_MODEM;
65+
task->del = s_modem_del_etm_task;
66+
*out_task = task;
67+
68+
return ESP_OK;
69+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdlib.h>
10+
#include <stdbool.h>
11+
#include "soc/soc.h"
12+
#include "hal/assert.h"
13+
#include "soc/soc_etm_struct.h"
14+
#include "soc/soc_etm_reg.h"
15+
#include "soc/soc_etm_source.h"
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
#define MODEM_LL_ETM_EVENT_TABLE(event_type) \
22+
(uint32_t[4]){ \
23+
[0] = MODEM_EVT_G0, \
24+
[1] = MODEM_EVT_G1, \
25+
[2] = MODEM_EVT_G2, \
26+
[3] = MODEM_EVT_G3, \
27+
}[event_type]
28+
29+
#define MODEM_LL_ETM_TASK_TABLE(task_type) \
30+
(uint32_t[4]){ \
31+
[0] = MODEM_TASK_G0, \
32+
[1] = MODEM_TASK_G1, \
33+
[2] = MODEM_TASK_G2, \
34+
[3] = MODEM_TASK_G3, \
35+
}[task_type]
36+
37+
static inline bool modem_etm_ll_get_group_event_status(int group_id)
38+
{
39+
switch (group_id) {
40+
case 0:
41+
return SOC_ETM.etm_evt_st6.etm_modem_evt_g0_st;
42+
case 1:
43+
return SOC_ETM.etm_evt_st6.etm_modem_evt_g1_st;
44+
case 2:
45+
return SOC_ETM.etm_evt_st6.etm_modem_evt_g2_st;
46+
case 3:
47+
return SOC_ETM.etm_evt_st6.etm_modem_evt_g3_st;
48+
default:
49+
HAL_ASSERT(false);
50+
}
51+
return false;
52+
}
53+
54+
static inline bool modem_etm_ll_get_group_task_status(int group_id)
55+
{
56+
switch (group_id) {
57+
case 0:
58+
return SOC_ETM.etm_task_st5.etm_modem_task_g0_st;
59+
case 1:
60+
return SOC_ETM.etm_task_st5.etm_modem_task_g1_st;
61+
case 2:
62+
return SOC_ETM.etm_task_st5.etm_modem_task_g2_st;
63+
case 3:
64+
return SOC_ETM.etm_task_st5.etm_modem_task_g3_st;
65+
default:
66+
HAL_ASSERT(false);
67+
}
68+
return false;
69+
}
70+
71+
static inline void modem_etm_ll_clear_group_event_status(int group_id)
72+
{
73+
SOC_ETM.etm_evt_st6_clr.val = SOC_ETM_MODEM_EVT_G0_ST_CLR << group_id;
74+
}
75+
76+
static inline void modem_etm_ll_clear_group_task_status(int group_id)
77+
{
78+
SOC_ETM.etm_task_st5_clr.val = SOC_ETM_MODEM_TASK_G0_ST_CLR << group_id;
79+
}
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif

components/soc/esp32h4/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ config SOC_SYSTIMER_ALARM_MISS_COMPENSATE
491491
bool
492492
default y
493493

494+
config SOC_SYSTIMER_SUPPORT_ETM
495+
bool
496+
default y
497+
494498
config SOC_LP_TIMER_BIT_WIDTH_LO
495499
int
496500
default 32

0 commit comments

Comments
 (0)