pm_trace.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2016-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "esp_private/pm_trace.h"
  15. #include "driver/gpio.h"
  16. /* GPIOs to use for tracing of esp_pm events.
  17. * Two entries in the array for each type, one for each CPU.
  18. * Feel free to change when debugging.
  19. */
  20. static const int DRAM_ATTR s_trace_io[] = {
  21. #if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32H2)
  22. BIT(4), BIT(5), // ESP_PM_TRACE_IDLE
  23. BIT(16), BIT(17), // ESP_PM_TRACE_TICK
  24. BIT(18), BIT(18), // ESP_PM_TRACE_FREQ_SWITCH
  25. BIT(19), BIT(19), // ESP_PM_TRACE_CCOMPARE_UPDATE
  26. BIT(25), BIT(26), // ESP_PM_TRACE_ISR_HOOK
  27. BIT(27), BIT(27), // ESP_PM_TRACE_SLEEP
  28. #else
  29. BIT(2), BIT(3), // ESP_PM_TRACE_IDLE
  30. BIT(4), BIT(5), // ESP_PM_TRACE_TICK
  31. BIT(6), BIT(6), // ESP_PM_TRACE_FREQ_SWITCH
  32. BIT(7), BIT(7), // ESP_PM_TRACE_CCOMPARE_UPDATE
  33. BIT(8), BIT(9), // ESP_PM_TRACE_ISR_HOOK
  34. BIT(18), BIT(18), // ESP_PM_TRACE_SLEEP
  35. #endif
  36. };
  37. void esp_pm_trace_init(void)
  38. {
  39. for (size_t i = 0; i < sizeof(s_trace_io)/sizeof(s_trace_io[0]); ++i) {
  40. int io = __builtin_ffs(s_trace_io[i]);
  41. if (io == 0) {
  42. continue;
  43. }
  44. gpio_set_direction(io - 1, GPIO_MODE_OUTPUT);
  45. }
  46. }
  47. void IRAM_ATTR esp_pm_trace_enter(esp_pm_trace_event_t event, int core_id)
  48. {
  49. REG_WRITE(GPIO_OUT_W1TS_REG, s_trace_io[2 * event + core_id]);
  50. }
  51. void IRAM_ATTR esp_pm_trace_exit(esp_pm_trace_event_t event, int core_id)
  52. {
  53. REG_WRITE(GPIO_OUT_W1TC_REG, s_trace_io[2 * event + core_id]);
  54. }