pm_trace.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. BIT(4), BIT(5), // ESP_PM_TRACE_IDLE
  22. BIT(16), BIT(17), // ESP_PM_TRACE_TICK
  23. BIT(18), BIT(18), // ESP_PM_TRACE_FREQ_SWITCH
  24. BIT(19), BIT(19), // ESP_PM_TRACE_CCOMPARE_UPDATE
  25. BIT(25), BIT(26), // ESP_PM_TRACE_ISR_HOOK
  26. BIT(27), BIT(27), // ESP_PM_TRACE_SLEEP
  27. };
  28. void esp_pm_trace_init(void)
  29. {
  30. for (size_t i = 0; i < sizeof(s_trace_io)/sizeof(s_trace_io[0]); ++i) {
  31. int io = __builtin_ffs(s_trace_io[i]);
  32. if (io == 0) {
  33. continue;
  34. }
  35. gpio_set_direction(io - 1, GPIO_MODE_OUTPUT);
  36. }
  37. }
  38. void IRAM_ATTR esp_pm_trace_enter(esp_pm_trace_event_t event, int core_id)
  39. {
  40. REG_WRITE(GPIO_OUT_W1TS_REG, s_trace_io[2 * event + core_id]);
  41. }
  42. void IRAM_ATTR esp_pm_trace_exit(esp_pm_trace_event_t event, int core_id)
  43. {
  44. REG_WRITE(GPIO_OUT_W1TC_REG, s_trace_io[2 * event + core_id]);
  45. }