trax.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stdio.h>
  14. #include "soc/dport_reg.h"
  15. #include "sdkconfig.h"
  16. #include "esp_err.h"
  17. #include "eri.h"
  18. #include "xtensa-debug-module.h"
  19. #include "trax.h"
  20. #include "esp_log.h"
  21. #define TRACEMEM_MUX_PROBLK0_APPBLK1 0
  22. #define TRACEMEM_MUX_BLK0_ONLY 1
  23. #define TRACEMEM_MUX_BLK1_ONLY 2
  24. #define TRACEMEM_MUX_PROBLK1_APPBLK0 3
  25. static const char* TAG = "trax";
  26. int trax_enable(trax_ena_select_t which)
  27. {
  28. #if !CONFIG_ESP32_TRAX
  29. ESP_LOGE(TAG, "Trax_enable called, but trax is disabled in menuconfig!");
  30. return ESP_ERR_NO_MEM;
  31. #endif
  32. #if !CONFIG_ESP32_TRAX_TWOBANKS
  33. if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) return ESP_ERR_NO_MEM;
  34. #endif
  35. if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) {
  36. DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, (which == TRAX_ENA_PRO_APP_SWAP)?TRACEMEM_MUX_PROBLK1_APPBLK0:TRACEMEM_MUX_PROBLK0_APPBLK1);
  37. } else {
  38. DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK0_ONLY);
  39. }
  40. DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_PRO));
  41. DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_APP));
  42. return ESP_OK;
  43. }
  44. int trax_start_trace(trax_downcount_unit_t units_until_stop)
  45. {
  46. #if !CONFIG_ESP32_TRAX
  47. ESP_LOGE(TAG, "Trax_start_trace called, but trax is disabled in menuconfig!");
  48. return ESP_ERR_NO_MEM;
  49. #endif
  50. uint32_t v;
  51. if (eri_read(ERI_TRAX_TRAXSTAT)&TRAXSTAT_TRACT) {
  52. ESP_LOGI(TAG, "Stopping active trace first.");
  53. //Trace is active. Stop trace.
  54. eri_write(ERI_TRAX_DELAYCNT, 0);
  55. eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
  56. //ToDo: This will probably trigger a trace done interrupt. ToDo: Fix, but how? -JD
  57. eri_write(ERI_TRAX_TRAXCTRL, 0);
  58. }
  59. eri_write(ERI_TRAX_PCMATCHCTRL, 31); //do not stop at any pc match
  60. v=TRAXCTRL_TREN | TRAXCTRL_TMEN | TRAXCTRL_PTOWS | (1<<TRAXCTRL_SMPER_SHIFT);
  61. if (units_until_stop == TRAX_DOWNCOUNT_INSTRUCTIONS) v|=TRAXCTRL_CNTU;
  62. //Enable trace. This trace has no stop condition and will just keep on running.
  63. eri_write(ERI_TRAX_TRAXCTRL, v);
  64. return ESP_OK;
  65. }
  66. int trax_trigger_traceend_after_delay(int delay)
  67. {
  68. #if !CONFIG_ESP32_TRAX
  69. ESP_LOGE(TAG, "Trax_trigger_traceend_after_delay called, but trax is disabled in menuconfig!");
  70. return ESP_ERR_NO_MEM;
  71. #endif
  72. eri_write(ERI_TRAX_DELAYCNT, delay);
  73. eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
  74. return ESP_OK;
  75. }