cache_err_int.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2015-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. /**
  15. * @file cache_err_int.c
  16. * @brief The cache has an interrupt that can be raised as soon as an access to a cached
  17. * region (Flash, PSRAM) is done without the cache being enabled.
  18. * We use that here to panic the CPU, which from a debugging perspective,
  19. * is better than grabbing bad data from the bus.
  20. */
  21. #include <stdint.h>
  22. #include "sdkconfig.h"
  23. #include "esp_err.h"
  24. #include "esp_attr.h"
  25. #include "esp_intr_alloc.h"
  26. #include "soc/soc.h"
  27. #include "soc/extmem_reg.h"
  28. #include "soc/periph_defs.h"
  29. #include "hal/cpu_hal.h"
  30. #include "esp32s3/dport_access.h"
  31. #include "esp32s3/rom/ets_sys.h"
  32. void esp_cache_err_int_init(void)
  33. {
  34. uint32_t core_id = cpu_hal_get_core_id();
  35. ESP_INTR_DISABLE(ETS_CACHEERR_INUM);
  36. // We do not register a handler for the interrupt because it is interrupt
  37. // level 4 which is not serviceable from C. Instead, xtensa_vectors.S has
  38. // a call to the panic handler for this interrupt.
  39. intr_matrix_set(core_id, ETS_CACHE_IA_INTR_SOURCE, ETS_CACHEERR_INUM);
  40. // Enable invalid cache access interrupt when the cache is disabled.
  41. // When the interrupt happens, we can not determine the CPU where the
  42. // invalid cache access has occurred. We enable the interrupt to catch
  43. // invalid access on both CPUs, but the interrupt is connected to the
  44. // CPU which happens to call this function.
  45. // For this reason, panic handler backtrace will not be correct if the
  46. // interrupt is connected to PRO CPU and invalid access happens on the APP CPU.
  47. SET_PERI_REG_MASK(EXTMEM_CACHE_ILG_INT_CLR_REG,
  48. EXTMEM_MMU_ENTRY_FAULT_INT_CLR |
  49. EXTMEM_DCACHE_WRITE_FLASH_INT_CLR |
  50. EXTMEM_DCACHE_PRELOAD_OP_FAULT_INT_CLR |
  51. EXTMEM_DCACHE_SYNC_OP_FAULT_INT_CLR |
  52. EXTMEM_ICACHE_PRELOAD_OP_FAULT_INT_CLR |
  53. EXTMEM_ICACHE_SYNC_OP_FAULT_INT_CLR);
  54. SET_PERI_REG_MASK(EXTMEM_CACHE_ILG_INT_ENA_REG,
  55. EXTMEM_MMU_ENTRY_FAULT_INT_ENA |
  56. EXTMEM_DCACHE_WRITE_FLASH_INT_ENA |
  57. EXTMEM_DCACHE_PRELOAD_OP_FAULT_INT_ENA |
  58. EXTMEM_DCACHE_SYNC_OP_FAULT_INT_ENA |
  59. EXTMEM_ICACHE_PRELOAD_OP_FAULT_INT_ENA |
  60. EXTMEM_ICACHE_SYNC_OP_FAULT_INT_ENA);
  61. ESP_INTR_ENABLE(ETS_CACHEERR_INUM);
  62. }
  63. int IRAM_ATTR esp_cache_err_get_cpuid(void)
  64. {
  65. // FIXME
  66. return -1;
  67. }