cache_err_int.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2015-2017 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. The cache has an interrupt that can be raised as soon as an access to a cached
  16. region (flash, psram) is done without the cache being enabled. We use that here
  17. to panic the CPU, which from a debugging perspective is better than grabbing bad
  18. data from the bus.
  19. */
  20. #include <stdint.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdbool.h>
  24. #include "freertos/FreeRTOS.h"
  25. #include "esp_err.h"
  26. #include "esp_intr_alloc.h"
  27. #include "esp_attr.h"
  28. #include "soc/dport_reg.h"
  29. #include "soc/periph_defs.h"
  30. #include "sdkconfig.h"
  31. #include "esp32s2beta/dport_access.h"
  32. void esp_cache_err_int_init(void)
  33. {
  34. uint32_t core_id = xPortGetCoreID();
  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
  39. // this interrupt.
  40. intr_matrix_set(core_id, ETS_CACHE_IA_INTR_SOURCE, ETS_CACHEERR_INUM);
  41. // Enable invalid cache access interrupt when the cache is disabled.
  42. // When the interrupt happens, we can not determine the CPU where the
  43. // invalid cache access has occurred. We enable the interrupt to catch
  44. // invalid access on both CPUs, but the interrupt is connected to the
  45. // CPU which happens to call this function.
  46. // For this reason, panic handler backtrace will not be correct if the
  47. // interrupt is connected to PRO CPU and invalid access happens on the APP
  48. // CPU.
  49. DPORT_SET_PERI_REG_MASK(DPORT_PRO_CACHE_IA_INT_EN_REG,
  50. DPORT_MMU_ENTRY_FAULT_INT_ENA |
  51. DPORT_DCACHE_REJECT_INT_ENA |
  52. DPORT_DCACHE_WRITE_FLASH_INT_ENA |
  53. DPORT_DC_PRELOAD_SIZE_FAULT_INT_ENA |
  54. DPORT_DC_SYNC_SIZE_FAULT_INT_ENA |
  55. DPORT_ICACHE_REJECT_INT_ENA |
  56. DPORT_IC_PRELOAD_SIZE_FAULT_INT_ENA |
  57. DPORT_IC_SYNC_SIZE_FAULT_INT_ENA |
  58. DPORT_CACHE_DBG_INT_CLR |
  59. DPORT_CACHE_DBG_EN);
  60. ESP_INTR_ENABLE(ETS_CACHEERR_INUM);
  61. }
  62. int IRAM_ATTR esp_cache_err_get_cpuid(void)
  63. {
  64. return PRO_CPU_NUM;
  65. }