pm_trace.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_attr.h"
  7. #include "esp_private/pm_trace.h"
  8. #include "driver/gpio.h"
  9. #include "soc/soc.h"
  10. #include "soc/gpio_reg.h"
  11. /* GPIOs to use for tracing of esp_pm events.
  12. * Two entries in the array for each type, one for each CPU.
  13. * Feel free to change when debugging.
  14. */
  15. static const int DRAM_ATTR s_trace_io[] = {
  16. #if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32C2)
  17. BIT(4), BIT(5), // ESP_PM_TRACE_IDLE
  18. BIT(16), BIT(17), // ESP_PM_TRACE_TICK
  19. BIT(18), BIT(18), // ESP_PM_TRACE_FREQ_SWITCH
  20. BIT(19), BIT(19), // ESP_PM_TRACE_CCOMPARE_UPDATE
  21. BIT(25), BIT(26), // ESP_PM_TRACE_ISR_HOOK
  22. BIT(27), BIT(27), // ESP_PM_TRACE_SLEEP
  23. #else
  24. BIT(2), BIT(3), // ESP_PM_TRACE_IDLE
  25. BIT(4), BIT(5), // ESP_PM_TRACE_TICK
  26. BIT(6), BIT(6), // ESP_PM_TRACE_FREQ_SWITCH
  27. BIT(7), BIT(7), // ESP_PM_TRACE_CCOMPARE_UPDATE
  28. BIT(8), BIT(9), // ESP_PM_TRACE_ISR_HOOK
  29. BIT(18), BIT(18), // ESP_PM_TRACE_SLEEP
  30. #endif
  31. };
  32. void esp_pm_trace_init(void)
  33. {
  34. for (size_t i = 0; i < sizeof(s_trace_io) / sizeof(s_trace_io[0]); ++i) {
  35. int io = __builtin_ffs(s_trace_io[i]);
  36. if (io == 0) {
  37. continue;
  38. }
  39. gpio_set_direction(io - 1, GPIO_MODE_OUTPUT);
  40. }
  41. }
  42. void IRAM_ATTR esp_pm_trace_enter(esp_pm_trace_event_t event, int core_id)
  43. {
  44. REG_WRITE(GPIO_OUT_W1TS_REG, s_trace_io[2 * event + core_id]);
  45. }
  46. void IRAM_ATTR esp_pm_trace_exit(esp_pm_trace_event_t event, int core_id)
  47. {
  48. REG_WRITE(GPIO_OUT_W1TC_REG, s_trace_io[2 * event + core_id]);
  49. }