cpu_util.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_attr.h"
  7. #include "soc/cpu.h"
  8. #include "soc/soc.h"
  9. #include "soc/rtc_periph.h"
  10. #include "sdkconfig.h"
  11. #include "hal/cpu_hal.h"
  12. #include "hal/cpu_types.h"
  13. #include "hal/mpu_hal.h"
  14. #include "esp_cpu.h"
  15. #include "hal/soc_hal.h"
  16. #include "soc/soc_caps.h"
  17. #include "sdkconfig.h"
  18. void IRAM_ATTR esp_cpu_stall(int cpu_id)
  19. {
  20. #if SOC_CPU_CORES_NUM > 1
  21. soc_hal_stall_core(cpu_id);
  22. #endif
  23. }
  24. void IRAM_ATTR esp_cpu_unstall(int cpu_id)
  25. {
  26. #if SOC_CPU_CORES_NUM > 1
  27. soc_hal_unstall_core(cpu_id);
  28. #endif
  29. }
  30. void IRAM_ATTR esp_cpu_reset(int cpu_id)
  31. {
  32. soc_hal_reset_core(cpu_id);
  33. }
  34. esp_err_t IRAM_ATTR esp_cpu_set_watchpoint(int no, void *adr, int size, int flags)
  35. {
  36. watchpoint_trigger_t trigger;
  37. switch (flags)
  38. {
  39. case ESP_WATCHPOINT_LOAD:
  40. trigger = WATCHPOINT_TRIGGER_ON_RO;
  41. break;
  42. case ESP_WATCHPOINT_STORE:
  43. trigger = WATCHPOINT_TRIGGER_ON_WO;
  44. break;
  45. case ESP_WATCHPOINT_ACCESS:
  46. trigger = WATCHPOINT_TRIGGER_ON_RW;
  47. break;
  48. default:
  49. return ESP_ERR_INVALID_ARG;
  50. }
  51. cpu_hal_set_watchpoint(no, adr, size, trigger);
  52. return ESP_OK;
  53. }
  54. void IRAM_ATTR esp_cpu_clear_watchpoint(int no)
  55. {
  56. cpu_hal_clear_watchpoint(no);
  57. }
  58. bool IRAM_ATTR esp_cpu_in_ocd_debug_mode(void)
  59. {
  60. #if CONFIG_ESP32_DEBUG_OCDAWARE || \
  61. CONFIG_ESP32S2_DEBUG_OCDAWARE || \
  62. CONFIG_ESP32S3_DEBUG_OCDAWARE || \
  63. CONFIG_ESP32C3_DEBUG_OCDAWARE || \
  64. CONFIG_ESP32H2_DEBUG_OCDAWARE
  65. return cpu_ll_is_debugger_attached();
  66. #else
  67. return false; // Always return false if "OCD aware" is disabled
  68. #endif
  69. }
  70. #if __XTENSA__
  71. void esp_cpu_configure_region_protection(void)
  72. {
  73. /* Note: currently this is configured the same on all Xtensa targets
  74. *
  75. * Both chips have the address space divided into 8 regions, 512MB each.
  76. */
  77. const int illegal_regions[] = {0, 4, 5, 6, 7}; // 0x00000000, 0x80000000, 0xa0000000, 0xc0000000, 0xe0000000
  78. for (size_t i = 0; i < sizeof(illegal_regions) / sizeof(illegal_regions[0]); ++i) {
  79. mpu_hal_set_region_access(illegal_regions[i], MPU_REGION_ILLEGAL);
  80. }
  81. mpu_hal_set_region_access(1, MPU_REGION_RW); // 0x20000000
  82. }
  83. #endif