trax.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. //
  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 <stdio.h>
  15. #include "esp_log.h"
  16. #include "esp_err.h"
  17. #include "xtensa-debug-module.h"
  18. #include "eri.h"
  19. #include "trax.h"
  20. #include "sdkconfig.h"
  21. #if defined(CONFIG_ESP32_TRAX) || defined(CONFIG_ESP32S2_TRAX)
  22. #define WITH_TRAX 1
  23. #endif
  24. static const char* TAG = "trax";
  25. int trax_start_trace(trax_downcount_unit_t units_until_stop)
  26. {
  27. #if !WITH_TRAX
  28. ESP_LOGE(TAG, "Trax_start_trace called, but trax is disabled in menuconfig!");
  29. return ESP_ERR_NO_MEM;
  30. #endif
  31. uint32_t v;
  32. if (eri_read(ERI_TRAX_TRAXSTAT)&TRAXSTAT_TRACT) {
  33. ESP_LOGI(TAG, "Stopping active trace first.");
  34. //Trace is active. Stop trace.
  35. eri_write(ERI_TRAX_DELAYCNT, 0);
  36. eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
  37. //ToDo: This will probably trigger a trace done interrupt. ToDo: Fix, but how? -JD
  38. eri_write(ERI_TRAX_TRAXCTRL, 0);
  39. }
  40. eri_write(ERI_TRAX_PCMATCHCTRL, 31); //do not stop at any pc match
  41. v=TRAXCTRL_TREN | TRAXCTRL_TMEN | TRAXCTRL_PTOWS | (1<<TRAXCTRL_SMPER_SHIFT);
  42. if (units_until_stop == TRAX_DOWNCOUNT_INSTRUCTIONS) v|=TRAXCTRL_CNTU;
  43. //Enable trace. This trace has no stop condition and will just keep on running.
  44. eri_write(ERI_TRAX_TRAXCTRL, v);
  45. return ESP_OK;
  46. }
  47. int trax_trigger_traceend_after_delay(int delay)
  48. {
  49. #if !WITH_TRAX
  50. ESP_LOGE(TAG, "Trax_trigger_traceend_after_delay called, but trax is disabled in menuconfig!");
  51. return ESP_ERR_NO_MEM;
  52. #endif
  53. eri_write(ERI_TRAX_DELAYCNT, delay);
  54. eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
  55. return ESP_OK;
  56. }