2021-11-06 05:26:37 -04:00
|
|
|
/*
|
2022-01-05 03:17:12 -05:00
|
|
|
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
2021-11-06 05:26:37 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-09-22 11:26:09 -04:00
|
|
|
|
|
|
|
|
2019-03-21 00:21:01 -04:00
|
|
|
#include "esp_private/pm_trace.h"
|
2017-09-22 11:26:09 -04:00
|
|
|
#include "driver/gpio.h"
|
2022-01-05 03:17:12 -05:00
|
|
|
#include "soc/soc.h"
|
|
|
|
#include "soc/gpio_reg.h"
|
2017-09-22 11:26:09 -04:00
|
|
|
|
|
|
|
/* GPIOs to use for tracing of esp_pm events.
|
|
|
|
* Two entries in the array for each type, one for each CPU.
|
|
|
|
* Feel free to change when debugging.
|
|
|
|
*/
|
|
|
|
static const int DRAM_ATTR s_trace_io[] = {
|
2022-01-17 21:32:56 -05:00
|
|
|
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32C2)
|
2022-01-05 03:17:12 -05:00
|
|
|
BIT(4), BIT(5), // ESP_PM_TRACE_IDLE
|
|
|
|
BIT(16), BIT(17), // ESP_PM_TRACE_TICK
|
|
|
|
BIT(18), BIT(18), // ESP_PM_TRACE_FREQ_SWITCH
|
|
|
|
BIT(19), BIT(19), // ESP_PM_TRACE_CCOMPARE_UPDATE
|
|
|
|
BIT(25), BIT(26), // ESP_PM_TRACE_ISR_HOOK
|
|
|
|
BIT(27), BIT(27), // ESP_PM_TRACE_SLEEP
|
2020-12-03 21:19:39 -05:00
|
|
|
#else
|
2022-01-05 03:17:12 -05:00
|
|
|
BIT(2), BIT(3), // ESP_PM_TRACE_IDLE
|
|
|
|
BIT(4), BIT(5), // ESP_PM_TRACE_TICK
|
|
|
|
BIT(6), BIT(6), // ESP_PM_TRACE_FREQ_SWITCH
|
|
|
|
BIT(7), BIT(7), // ESP_PM_TRACE_CCOMPARE_UPDATE
|
|
|
|
BIT(8), BIT(9), // ESP_PM_TRACE_ISR_HOOK
|
|
|
|
BIT(18), BIT(18), // ESP_PM_TRACE_SLEEP
|
2020-12-03 21:19:39 -05:00
|
|
|
#endif
|
2017-09-22 11:26:09 -04:00
|
|
|
};
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_pm_trace_init(void)
|
2017-09-22 11:26:09 -04:00
|
|
|
{
|
2022-01-05 03:17:12 -05:00
|
|
|
for (size_t i = 0; i < sizeof(s_trace_io) / sizeof(s_trace_io[0]); ++i) {
|
2017-09-22 11:26:09 -04:00
|
|
|
int io = __builtin_ffs(s_trace_io[i]);
|
|
|
|
if (io == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
gpio_set_direction(io - 1, GPIO_MODE_OUTPUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IRAM_ATTR esp_pm_trace_enter(esp_pm_trace_event_t event, int core_id)
|
|
|
|
{
|
|
|
|
REG_WRITE(GPIO_OUT_W1TS_REG, s_trace_io[2 * event + core_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IRAM_ATTR esp_pm_trace_exit(esp_pm_trace_event_t event, int core_id)
|
|
|
|
{
|
|
|
|
REG_WRITE(GPIO_OUT_W1TC_REG, s_trace_io[2 * event + core_id]);
|
2020-11-10 02:40:01 -05:00
|
|
|
}
|