panic_internal.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "soc/soc_caps.h"
  17. #include "sdkconfig.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. extern bool g_panic_abort;
  22. extern void *g_exc_frames[SOC_CPU_CORES_NUM];
  23. // Function to print longer amounts of information such as the details
  24. // and backtrace field of panic_info_t. These functions should limit themselves
  25. // to printing to the console and should do other more involved processing,
  26. // and must be aware that the main logic in panic.c has a watchdog timer active.
  27. typedef void (*panic_info_dump_fn_t)(const void* frame);
  28. // Non architecture specific exceptions (generally valid for all targets).
  29. // Can be used to convey to the main logic what exception is being
  30. // dealt with to perform some actions, without knowing the underlying
  31. // architecture/chip-specific exception.
  32. typedef enum {
  33. PANIC_EXCEPTION_DEBUG,
  34. PANIC_EXCEPTION_IWDT,
  35. PANIC_EXCEPTION_TWDT,
  36. PANIC_EXCEPTION_ABORT,
  37. PANIC_EXCEPTION_FAULT, // catch-all for all types of faults
  38. } panic_exception_t;
  39. typedef struct {
  40. int core; // core which triggered panic
  41. panic_exception_t exception; // non-architecture-specific exception code
  42. const char* reason; // exception string
  43. const char* description; // short description of the exception
  44. panic_info_dump_fn_t details; // more details on the exception
  45. panic_info_dump_fn_t state; // processor state, usually the contents of the registers
  46. const void* addr; // instruction address that triggered the exception
  47. const void* frame; // reference to the frame
  48. bool pseudo_excause; // flag indicating that exception cause has special meaning
  49. } panic_info_t;
  50. #define PANIC_INFO_DUMP(info, dump_fn) {if ((info)->dump_fn) (*(info)->dump_fn)((info->frame));}
  51. // Create own print functions, since printf might be broken, and can be silenced
  52. // when CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  53. #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  54. void panic_print_char(char c);
  55. void panic_print_str(const char *str);
  56. void panic_print_dec(int d);
  57. void panic_print_hex(int h);
  58. #else
  59. #define panic_print_char(c)
  60. #define panic_print_str(str)
  61. #define panic_print_dec(d)
  62. #define panic_print_hex(h)
  63. #endif
  64. void __attribute__((noreturn)) panic_abort(const char *details);
  65. void panic_arch_fill_info(void *frame, panic_info_t *info);
  66. void panic_soc_fill_info(void *frame, panic_info_t *info);
  67. void panic_print_registers(const void *frame, int core);
  68. void panic_print_backtrace(const void *frame, int core);
  69. uint32_t panic_get_address(const void* frame);
  70. void panic_set_address(void *frame, uint32_t addr);
  71. uint32_t panic_get_cause(const void* frame);
  72. #ifdef __cplusplus
  73. }
  74. #endif