refactor(etm): move etm_periph.c to hal component

This commit is contained in:
morris
2025-11-16 22:13:30 +08:00
committed by suda-morris
parent 6c118b39c0
commit a5a355d17f
25 changed files with 104 additions and 75 deletions
@@ -28,7 +28,7 @@
static i2s_chan_handle_t s_tx_handle = NULL;
static i2s_chan_handle_t s_rx_handle = NULL;
#if ETM_LL_SUPPORT_STATUS
#if ETM_LL_SUPPORT(STATUS_REG)
static void s_i2s_etm_check_status(void)
{
i2s_dev_t *hw = I2S_LL_GET_HW(0);
@@ -44,7 +44,7 @@ static void s_i2s_etm_check_status(void)
TEST_ASSERT(is_tx_reach_thresh);
TEST_ASSERT(is_rx_reach_thresh);
}
#endif // ETM_LL_SUPPORT_STATUS
#endif // ETM_LL_SUPPORT(STATUS_REG)
static void s_i2s_init(void *buf)
{
@@ -133,11 +133,11 @@ TEST_CASE("i2s_etm_event_test", "[etm]")
TEST_ESP_OK(i2s_channel_read(s_rx_handle, buf, TEST_BUFF_SIZE, NULL, portMAX_DELAY));
#if ETM_LL_SUPPORT_STATUS
#if ETM_LL_SUPPORT(STATUS_REG)
s_i2s_etm_check_status();
#else
TEST_ASSERT(gpio_get_level(TEST_GPIO_ETM_NUM));
#endif // ETM_LL_SUPPORT_STATUS
#endif // ETM_LL_SUPPORT(STATUS_REG)
/* Test finished, free the resources */
TEST_ESP_OK(i2s_channel_disable(s_rx_handle));
+9 -9
View File
@@ -16,7 +16,7 @@
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_heap_caps.h"
@@ -46,16 +46,16 @@ typedef struct etm_group_t etm_group_t;
typedef struct esp_etm_channel_t esp_etm_channel_t;
struct etm_platform_t {
_lock_t mutex; // platform level mutex lock
etm_group_t *groups[SOC_ETM_ATTR(INST_NUM)]; // etm group pool
int group_ref_counts[SOC_ETM_ATTR(INST_NUM)]; // reference count used to protect group install/uninstall
_lock_t mutex; // platform level mutex lock
etm_group_t *groups[ETM_LL_GET(INST_NUM)]; // etm group pool
int group_ref_counts[ETM_LL_GET(INST_NUM)]; // reference count used to protect group install/uninstall
};
struct etm_group_t {
int group_id; // hardware group id
etm_hal_context_t hal; // hardware abstraction layer context
portMUX_TYPE spinlock; // to protect per-group light weight resource access
esp_etm_channel_t *chans[SOC_ETM_ATTR(CHANS_PER_INST)]; // array of channels in the group
esp_etm_channel_t *chans[ETM_LL_GET(CHANS_PER_INST)]; // array of channels in the group
};
typedef enum {
@@ -198,12 +198,12 @@ static esp_err_t etm_chan_register_to_group(esp_etm_channel_t *chan)
{
etm_group_t *group = NULL;
int chan_id = -1;
for (int i = 0; i < SOC_ETM_ATTR(INST_NUM); i++) {
for (int i = 0; i < ETM_LL_GET(INST_NUM); i++) {
group = etm_acquire_group_handle(i);
ESP_RETURN_ON_FALSE(group, ESP_ERR_NO_MEM, TAG, "no mem for group (%d)", i);
// loop to search free channel in the group
esp_os_enter_critical(&group->spinlock);
for (int j = 0; j < SOC_ETM_ATTR(CHANS_PER_INST); j++) {
for (int j = 0; j < ETM_LL_GET(CHANS_PER_INST); j++) {
if (!group->chans[j]) {
chan_id = j;
group->chans[j] = chan;
@@ -405,11 +405,11 @@ esp_err_t esp_etm_dump(FILE *out_stream)
fprintf(out_stream, "===========ETM Dump Start==========\r\n");
char line[80];
size_t len = sizeof(line);
for (int i = 0; i < SOC_ETM_ATTR(INST_NUM); i++) {
for (int i = 0; i < ETM_LL_GET(INST_NUM); i++) {
group = etm_acquire_group_handle(i);
ESP_RETURN_ON_FALSE(group, ESP_ERR_NO_MEM, TAG, "no mem for group (%d)", i);
etm_hal_context_t *hal = &group->hal;
for (int j = 0; j < SOC_ETM_ATTR(CHANS_PER_INST); j++) {
for (int j = 0; j < ETM_LL_GET(CHANS_PER_INST); j++) {
bool print_line = true;
esp_os_enter_critical(&group->spinlock);
etm_chan = group->chans[j];
@@ -10,15 +10,15 @@
#include "freertos/task.h"
#include "unity.h"
#include "esp_etm.h"
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
TEST_CASE("etm_channel_install_uninstall", "[etm]")
{
printf("install etm channels exhaustively\r\n");
esp_etm_channel_handle_t etm_chans[SOC_ETM_ATTR(INST_NUM)][SOC_ETM_ATTR(CHANS_PER_INST)];
esp_etm_channel_handle_t etm_chans[ETM_LL_GET(INST_NUM)][ETM_LL_GET(CHANS_PER_INST)];
esp_etm_channel_config_t config = {};
for (int i = 0; i < SOC_ETM_ATTR(INST_NUM); i++) {
for (int j = 0; j < SOC_ETM_ATTR(CHANS_PER_INST); j++) {
for (int i = 0; i < ETM_LL_GET(INST_NUM); i++) {
for (int j = 0; j < ETM_LL_GET(CHANS_PER_INST); j++) {
TEST_ESP_OK(esp_etm_new_channel(&config, &etm_chans[i][j]));
}
TEST_ESP_ERR(ESP_ERR_NOT_FOUND, esp_etm_new_channel(&config, &etm_chans[0][0]));
@@ -30,8 +30,8 @@ TEST_CASE("etm_channel_install_uninstall", "[etm]")
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, esp_etm_del_channel(etm_chans[0][0]));
TEST_ESP_OK(esp_etm_channel_disable(etm_chans[0][0]));
for (int i = 0; i < SOC_ETM_ATTR(INST_NUM); i++) {
for (int j = 0; j < SOC_ETM_ATTR(CHANS_PER_INST); j++) {
for (int i = 0; i < ETM_LL_GET(INST_NUM); i++) {
for (int j = 0; j < ETM_LL_GET(CHANS_PER_INST); j++) {
TEST_ESP_OK(esp_etm_del_channel(etm_chans[i][j]));
}
}
+1 -1
View File
@@ -129,7 +129,7 @@ elseif(NOT BOOTLOADER_BUILD)
endif()
if(CONFIG_SOC_ETM_SUPPORTED)
list(APPEND srcs "etm_hal.c")
list(APPEND srcs "etm_hal.c" "${target}/etm_periph.c")
endif()
if(CONFIG_SOC_PARLIO_SUPPORTED)
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+13 -3
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -14,12 +14,22 @@
#include "soc/soc_etm_struct.h"
#include "soc/pcr_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
// Support to get and clear the status of the ETM event and task
#define ETM_LL_SUPPORT_STATUS_REG 1
#ifdef __cplusplus
extern "C" {
#endif
#define ETM_LL_SUPPORT_STATUS 1 // Support to get and clear the status of the ETM event and task
/**
* @brief Enable the clock for ETM register
*
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+10 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -14,6 +14,15 @@
#include "soc/soc_etm_struct.h"
#include "soc/pcr_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
#ifdef __cplusplus
extern "C" {
#endif
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+13 -3
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -14,12 +14,22 @@
#include "soc/soc_etm_struct.h"
#include "soc/pcr_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
// Support to get and clear the status of the ETM event and task
#define ETM_LL_SUPPORT_STATUS_REG 1
#ifdef __cplusplus
extern "C" {
#endif
#define ETM_LL_SUPPORT_STATUS 1 // Support to get and clear the status of the ETM event and task
/**
* @brief Enable the clock for ETM register
*
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+10 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -14,6 +14,15 @@
#include "soc/soc_etm_struct.h"
#include "soc/pcr_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
#ifdef __cplusplus
extern "C" {
#endif
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+12 -2
View File
@@ -14,12 +14,22 @@
#include "soc/soc_etm_struct.h"
#include "soc/pcr_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
// Support to get and clear the status of the ETM event and task
#define ETM_LL_SUPPORT_STATUS_REG 1
#ifdef __cplusplus
extern "C" {
#endif
#define ETM_LL_SUPPORT_STATUS 1 // Support to get and clear the status of the ETM event and task
/**
* @brief Enable the clock for ETM register
*
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/etm_periph.h"
#include "hal/etm_periph.h"
#include "soc/soc_etm_reg.h"
/**
+12 -2
View File
@@ -14,12 +14,22 @@
#include "soc/soc_etm_struct.h"
#include "soc/hp_sys_clkrst_struct.h"
#define ETM_LL_GET(_attr) ETM_LL_ ## _attr
#define ETM_LL_SUPPORT(_feat) ETM_LL_SUPPORT_ ## _feat
// Number of ETM instances
#define ETM_LL_INST_NUM 1
// Number of channels in each ETM instance
#define ETM_LL_CHANS_PER_INST 50
// Support to get and clear the status of the ETM event and task
#define ETM_LL_SUPPORT_STATUS_REG 1
#ifdef __cplusplus
extern "C" {
#endif
#define ETM_LL_SUPPORT_STATUS 1 // Support to get and clear the status of the ETM event and task
/**
* @brief Enable the bus clock for ETM module
*
@@ -7,20 +7,22 @@
#pragma once
#include <stdint.h>
#include "soc/soc_caps_full.h"
#include "soc/soc_caps.h"
#include "soc/regdma.h"
#if SOC_HAS(ETM)
#include "hal/etm_ll.h"
#endif
#if SOC_HAS(PAU)
#include "soc/retention_periph_defs.h"
#endif
// helper macros to access module attributes
#define SOC_ETM_ATTR(_attr) SOC_MODULE_ATTR(ETM, _attr)
#ifdef __cplusplus
extern "C" {
#endif
#if SOC_HAS(ETM)
#if SOC_HAS(PAU)
typedef struct {
@@ -29,9 +31,10 @@ typedef struct {
uint32_t array_size; // Size of the regdma_entry_array
} soc_etm_retention_desc_t;
extern const soc_etm_retention_desc_t soc_etm_retention_info[SOC_ETM_ATTR(INST_NUM)];
extern const soc_etm_retention_desc_t soc_etm_retention_info[ETM_LL_GET(INST_NUM)];
#endif // SOC_HAS(PAU)
#endif // SOC_HAS(ETM)
#ifdef __cplusplus
}
-4
View File
@@ -84,10 +84,6 @@ if(CONFIG_SOC_EMAC_SUPPORTED)
list(APPEND srcs "${target_folder}/emac_periph.c")
endif()
if(CONFIG_SOC_ETM_SUPPORTED)
list(APPEND srcs "${target_folder}/etm_periph.c")
endif()
if(CONFIG_SOC_GPSPI_SUPPORTED)
list(APPEND srcs "${target_folder}/spi_periph.c")
endif()
@@ -23,10 +23,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -23,10 +23,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -13,10 +13,6 @@
#define _SOC_CAPS_DEDIC_GPIO_OUT_CHANS_PER_CPU 8 /*!< 8 outward channels on each CPU core */
#define _SOC_CAPS_DEDIC_GPIO_IN_CHANS_PER_CPU 8 /*!< 8 inward channels on each CPU core */
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*--------------------------- I2S CAPS ----------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -23,10 +23,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -19,10 +19,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
// #define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -19,10 +19,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 1 // Number of I2S instances
@@ -23,10 +23,6 @@
#define _SOC_CAPS_PCNT_CHANS_PER_UNIT 2 // Number of channels in each PCNT unit
#define _SOC_CAPS_PCNT_THRES_POINT_PER_UNIT 2 // Number of threshold points in each PCNT unit
/*--------------------------- ETM (Event Task Matrix) ----------------------------*/
#define _SOC_CAPS_ETM_INST_NUM 1 // Number of ETM instances
#define _SOC_CAPS_ETM_CHANS_PER_INST 50 // Number of channels in each ETM instance
/*------------------------------- I2S ---------------------------------------*/
// helper macros to access module attributes
#define _SOC_CAPS_I2S_INST_NUM 3 // Number of I2S instances