esp_panic.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef PANIC_H
  2. #define PANIC_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #define PANIC_RSN_NONE 0
  8. #define PANIC_RSN_DEBUGEXCEPTION 1
  9. #define PANIC_RSN_DOUBLEEXCEPTION 2
  10. #define PANIC_RSN_KERNELEXCEPTION 3
  11. #define PANIC_RSN_COPROCEXCEPTION 4
  12. #define PANIC_RSN_INTWDT_CPU0 5
  13. #define PANIC_RSN_INTWDT_CPU1 6
  14. #define PANIC_RSN_CACHEERR 7
  15. #define PANIC_RSN_MAX 7
  16. #ifndef __ASSEMBLER__
  17. #include "esp_err.h"
  18. #include "soc/soc.h"
  19. /**
  20. * @brief If an OCD is connected over JTAG. set breakpoint 0 to the given function
  21. * address. Do nothing otherwise.
  22. * @param data Pointer to the target breakpoint position
  23. */
  24. void esp_set_breakpoint_if_jtag(void *fn);
  25. #define ESP_WATCHPOINT_LOAD 0x40000000
  26. #define ESP_WATCHPOINT_STORE 0x80000000
  27. #define ESP_WATCHPOINT_ACCESS 0xC0000000
  28. /**
  29. * @brief Set a watchpoint to break/panic when a certain memory range is accessed.
  30. *
  31. * @param no Watchpoint number. On the ESP32, this can be 0 or 1.
  32. * @param adr Base address to watch
  33. * @param size Size of the region, starting at the base address, to watch. Must
  34. * be one of 2^n, with n in [0..6].
  35. * @param flags One of ESP_WATCHPOINT_* flags
  36. *
  37. * @return ESP_ERR_INVALID_ARG on invalid arg, ESP_OK otherwise
  38. *
  39. * @warning The ESP32 watchpoint hardware watches a region of bytes by effectively
  40. * masking away the lower n bits for a region with size 2^n. If adr does
  41. * not have zero for these lower n bits, you may not be watching the
  42. * region you intended.
  43. */
  44. esp_err_t esp_set_watchpoint(int no, void *adr, int size, int flags);
  45. /**
  46. * @brief Clear a watchpoint
  47. *
  48. * @param no Watchpoint to clear
  49. *
  50. */
  51. void esp_clear_watchpoint(int no);
  52. /**
  53. * @brief Checks stack pointer in dram
  54. */
  55. inline static bool esp_stack_ptr_in_dram(uint32_t sp)
  56. {
  57. //Check if stack ptr is in between SOC_DRAM_LOW and SOC_DRAM_HIGH, and 16 byte aligned.
  58. return !(sp < SOC_DRAM_LOW + 0x10 || sp > SOC_DRAM_HIGH - 0x10 || ((sp & 0xF) != 0));
  59. }
  60. #if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
  61. /**
  62. * @brief Checks stack pointer in external ram
  63. */
  64. inline static bool esp_stack_ptr_in_extram(uint32_t sp)
  65. {
  66. //Check if stack ptr is in between SOC_EXTRAM_DATA_LOW and SOC_EXTRAM_DATA_HIGH, and 16 byte aligned.
  67. return !(sp < SOC_EXTRAM_DATA_LOW + 0x10 || sp > SOC_EXTRAM_DATA_HIGH - 0x10 || ((sp & 0xF) != 0));
  68. }
  69. #endif
  70. /**
  71. * @brief Checks stack pointer
  72. */
  73. static inline bool esp_stack_ptr_is_sane(uint32_t sp)
  74. {
  75. #if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
  76. return (esp_stack_ptr_in_dram(sp) || esp_stack_ptr_in_extram(sp));
  77. #else
  78. return esp_stack_ptr_in_dram(sp);
  79. #endif
  80. }
  81. #endif
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif