pm_trace.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "soc/gpio_reg.h"
  17. /* GPIOs to use for tracing of esp_pm events.
  18. * Two entries in the array for each type, one for each CPU.
  19. * Feel free to change when debugging.
  20. */
  21. static const int DRAM_ATTR s_trace_io[] = {
  22. BIT(2), 0, // ESP_PM_TRACE_IDLE
  23. BIT(3), 0, // ESP_PM_TRACE_TICK
  24. BIT(4), 0, // ESP_PM_TRACE_FREQ_SWITCH
  25. BIT(5), 0, // ESP_PM_TRACE_CCOMPARE_UPDATE
  26. BIT(6), 0, // ESP_PM_TRACE_ISR_HOOK
  27. BIT(7), 0, // ESP_PM_TRACE_SLEEP
  28. };
  29. void esp_pm_trace_init(void)
  30. {
  31. for (size_t i = 0; i < sizeof(s_trace_io)/sizeof(s_trace_io[0]); ++i) {
  32. int io = __builtin_ffs(s_trace_io[i]);
  33. if (io == 0) {
  34. continue;
  35. }
  36. gpio_set_direction(io - 1, GPIO_MODE_OUTPUT);
  37. }
  38. }
  39. void IRAM_ATTR esp_pm_trace_enter(esp_pm_trace_event_t event, int core_id)
  40. {
  41. REG_WRITE(GPIO_OUT_W1TS_REG, s_trace_io[2 * event + core_id]);
  42. }
  43. void IRAM_ATTR esp_pm_trace_exit(esp_pm_trace_event_t event, int core_id)
  44. {
  45. REG_WRITE(GPIO_OUT_W1TC_REG, s_trace_io[2 * event + core_id]);
  46. }