trax_init.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2020 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_err.h"
  16. #include "esp_log.h"
  17. #include "trax.h"
  18. #include "soc/dport_reg.h"
  19. #include "sdkconfig.h"
  20. #define TRACEMEM_MUX_PROBLK0_APPBLK1 0
  21. #define TRACEMEM_MUX_BLK0_ONLY 1
  22. #define TRACEMEM_MUX_BLK1_ONLY 2
  23. #define TRACEMEM_MUX_PROBLK1_APPBLK0 3
  24. static const char* __attribute__((unused)) TAG = "trax";
  25. int trax_enable(trax_ena_select_t which)
  26. {
  27. #ifndef CONFIG_ESP32_TRAX
  28. ESP_LOGE(TAG, "Trax_enable called, but trax is disabled in menuconfig!");
  29. return ESP_ERR_NO_MEM;
  30. #endif
  31. #ifndef CONFIG_ESP32_TRAX_TWOBANKS
  32. if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) return ESP_ERR_NO_MEM;
  33. #endif
  34. if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) {
  35. DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, (which == TRAX_ENA_PRO_APP_SWAP)?TRACEMEM_MUX_PROBLK1_APPBLK0:TRACEMEM_MUX_PROBLK0_APPBLK1);
  36. } else {
  37. DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK0_ONLY);
  38. }
  39. DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_PRO));
  40. DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_APP));
  41. return ESP_OK;
  42. }