refactor(hal): extract assist_debug, debug_probe and trace into esp_hal_debug_assist

Move the following modules from the hal component into a new dedicated
esp_hal_debug_assist component, following the esp_hal_timg pattern:

- assist_debug (hal + target-specific LL headers)
- debug_probe (types + target-specific LL headers)
- riscv_trace (hal + types + source + target-specific LL headers)
- trace_ll (esp32/esp32s2/esp32s3 target-specific LL headers)

Update the following components to depend on esp_hal_debug_assist:
esp_system, riscv, bootloader_support, esp_hw_support, esp_riscv_trace

Remove riscv_trace_hal.c from the hal component.
This commit is contained in:
morris
2026-07-21 11:28:11 +08:00
parent e8a5192a18
commit 26a22512eb
32 changed files with 459 additions and 242 deletions
@@ -0,0 +1,265 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "soc/assist_debug_reg.h"
#ifndef __ASSEMBLER__
#include <stdbool.h>
#include <stdint.h>
#include "soc/pcr_struct.h"
#include "soc/bus_monitor_struct.h"
#include "soc/lp_clkrst_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* The bus monitor peripheral provides stack overflow/underflow monitoring.
*
*/
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_monitor_enable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_montr_ena.monitor_core_1_sp_spill_min_ena = 1;
BUS_MONITOR.monitor_core_1_montr_ena.monitor_core_1_sp_spill_max_ena = 1;
} else {
BUS_MONITOR.monitor_core_0_montr_ena.monitor_core_0_sp_spill_min_ena = 1;
BUS_MONITOR.monitor_core_0_montr_ena.monitor_core_0_sp_spill_max_ena = 1;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_monitor_disable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_montr_ena.monitor_core_1_sp_spill_min_ena = 0;
BUS_MONITOR.monitor_core_1_montr_ena.monitor_core_1_sp_spill_max_ena = 0;
} else {
BUS_MONITOR.monitor_core_0_montr_ena.monitor_core_0_sp_spill_min_ena = 0;
BUS_MONITOR.monitor_core_0_montr_ena.monitor_core_0_sp_spill_max_ena = 0;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_interrupt_enable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_intr_ena.monitor_core_1_sp_spill_min_intr_ena = 1;
BUS_MONITOR.monitor_core_1_intr_ena.monitor_core_1_sp_spill_max_intr_ena = 1;
} else {
BUS_MONITOR.monitor_core_0_intr_ena.monitor_core_0_sp_spill_min_intr_ena = 1;
BUS_MONITOR.monitor_core_0_intr_ena.monitor_core_0_sp_spill_max_intr_ena = 1;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_interrupt_disable(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_intr_ena.monitor_core_1_sp_spill_min_intr_ena = 0;
BUS_MONITOR.monitor_core_1_intr_ena.monitor_core_1_sp_spill_max_intr_ena = 0;
} else {
BUS_MONITOR.monitor_core_0_intr_ena.monitor_core_0_sp_spill_min_intr_ena = 0;
BUS_MONITOR.monitor_core_0_intr_ena.monitor_core_0_sp_spill_max_intr_ena = 0;
}
}
__attribute__((always_inline))
static inline bool assist_debug_ll_sp_spill_is_fired(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.monitor_core_1_intr_raw.monitor_core_1_sp_spill_min_raw || BUS_MONITOR.monitor_core_1_intr_raw.monitor_core_1_sp_spill_max_raw;
} else {
return BUS_MONITOR.monitor_core_0_intr_raw.monitor_core_0_sp_spill_min_raw || BUS_MONITOR.monitor_core_0_intr_raw.monitor_core_0_sp_spill_max_raw;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_interrupt_clear(uint32_t core_id)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_intr_clr.monitor_core_1_sp_spill_min_clr = 1;
BUS_MONITOR.monitor_core_1_intr_clr.monitor_core_1_sp_spill_max_clr = 1;
} else {
BUS_MONITOR.monitor_core_0_intr_clr.monitor_core_0_sp_spill_min_clr = 1;
BUS_MONITOR.monitor_core_0_intr_clr.monitor_core_0_sp_spill_max_clr = 1;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_set_min(uint32_t core_id, uint32_t min)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_sp_min.monitor_core_1_sp_min = min;
} else {
BUS_MONITOR.monitor_core_0_sp_min.monitor_core_0_sp_min = min;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_sp_spill_get_min(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.monitor_core_1_sp_min.monitor_core_1_sp_min;
} else {
return BUS_MONITOR.monitor_core_0_sp_min.monitor_core_0_sp_min;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_sp_spill_set_max(uint32_t core_id, uint32_t max)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_sp_max.monitor_core_1_sp_max = max;
} else {
BUS_MONITOR.monitor_core_0_sp_max.monitor_core_0_sp_max = max;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_sp_spill_get_max(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.monitor_core_1_sp_max.monitor_core_1_sp_max;
} else {
return BUS_MONITOR.monitor_core_0_sp_max.monitor_core_0_sp_max;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_sp_spill_get_pc(uint32_t core_id)
{
if (core_id) {
return BUS_MONITOR.monitor_core_1_sp_pc.monitor_core_1_sp_pc;
} else {
return BUS_MONITOR.monitor_core_0_sp_pc.monitor_core_0_sp_pc;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_enable_pc_recording(uint32_t core_id, bool enable)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_rcd_en.monitor_core_1_rcd_pdebugen = enable;
BUS_MONITOR.monitor_core_1_rcd_en.monitor_core_1_rcd_recorden = enable;
} else {
BUS_MONITOR.monitor_core_0_rcd_en.monitor_core_0_rcd_pdebugen = enable;
BUS_MONITOR.monitor_core_0_rcd_en.monitor_core_0_rcd_recorden = enable;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_enable_bus_clock(uint32_t core_id, bool enable)
{
if (core_id) {
PCR.assist_conf.assist1_clk_en = enable;
} else {
PCR.assist_conf.assist_clk_en = enable;
}
}
__attribute__((always_inline))
static inline void assist_debug_ll_reset_register(uint32_t core_id)
{
if (core_id) {
PCR.assist_conf.assist1_rst_en = true;
PCR.assist_conf.assist1_rst_en = false;
} else {
PCR.assist_conf.assist_rst_en = true;
PCR.assist_conf.assist_rst_en = false;
}
}
__attribute__((always_inline))
static inline bool assist_debug_ll_is_debugger_active(void)
{
return BUS_MONITOR.monitor_core_0_debug_mode.monitor_core_0_debug_module_active;
}
__attribute__((always_inline))
static inline void assist_debug_ll_lockup_monitor_enable(uint32_t core_id, bool enable)
{
if (core_id) {
BUS_MONITOR.monitor_core_1_montr_ena.monitor_core_1_trace_lockup_ena = enable;
} else {
BUS_MONITOR.monitor_core_0_montr_ena.monitor_core_0_trace_lockup_ena = enable;
}
}
// trap_idx: 0 = latest trap, 1 = previous trap
// MCause for the exception
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_lockup_get_cause(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.monitor_core_1_trace_lockup_cause_1.monitor_core_1_trace_lockup_recording_cause_1
: BUS_MONITOR.monitor_core_1_trace_lockup_cause_0.monitor_core_1_trace_lockup_recording_cause_0;
} else {
return trap_idx ? BUS_MONITOR.monitor_core_0_trace_lockup_cause_1.monitor_core_0_trace_lockup_recording_cause_1
: BUS_MONITOR.monitor_core_0_trace_lockup_cause_0.monitor_core_0_trace_lockup_recording_cause_0;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_lockup_get_tval(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.monitor_core_1_trace_lockup_tval_1.monitor_core_1_trace_lockup_recording_tval_1
: BUS_MONITOR.monitor_core_1_trace_lockup_tval_0.monitor_core_1_trace_lockup_recording_tval_0;
} else {
return trap_idx ? BUS_MONITOR.monitor_core_0_trace_lockup_tval_1.monitor_core_0_trace_lockup_recording_tval_1
: BUS_MONITOR.monitor_core_0_trace_lockup_tval_0.monitor_core_0_trace_lockup_recording_tval_0;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_lockup_get_iaddr(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.monitor_core_1_trace_lockup_iaddr_1.monitor_core_1_trace_lockup_recording_iaddr_1
: BUS_MONITOR.monitor_core_1_trace_lockup_iaddr_0.monitor_core_1_trace_lockup_recording_iaddr_0;
} else {
return trap_idx ? BUS_MONITOR.monitor_core_0_trace_lockup_iaddr_1.monitor_core_0_trace_lockup_recording_iaddr_1
: BUS_MONITOR.monitor_core_0_trace_lockup_iaddr_0.monitor_core_0_trace_lockup_recording_iaddr_0;
}
}
__attribute__((always_inline))
static inline uint32_t assist_debug_ll_lockup_get_priv(uint32_t core_id, int trap_idx)
{
if (core_id) {
return trap_idx ? BUS_MONITOR.monitor_core_1_trace_lockup_priv_1.monitor_core_1_trace_lockup_recording_priv_1
: BUS_MONITOR.monitor_core_1_trace_lockup_priv_0.monitor_core_1_trace_lockup_recording_priv_0;
} else {
return trap_idx ? BUS_MONITOR.monitor_core_0_trace_lockup_priv_1.monitor_core_0_trace_lockup_recording_priv_1
: BUS_MONITOR.monitor_core_0_trace_lockup_priv_0.monitor_core_0_trace_lockup_recording_priv_0;
}
}
/* Enable the hardware lockup reset for the given core via LP_CLKRST.
* This controls whether a CPU lockup (exception inside exception handler) triggers
* a system reset. Defaults to 1 on H4 but must be set explicitly to be safe. */
__attribute__((always_inline))
static inline void assist_debug_ll_lockup_reset_enable(uint32_t core_id)
{
if (core_id) {
LP_CLKRST.cpu_core1_reset.hpcore1_lockup_reset_en = 1;
} else {
LP_CLKRST.cpu_core0_reset.hpcore0_lockup_reset_en = 1;
}
}
#ifdef __cplusplus
}
#endif
#endif // __ASSEMBLER__