panic_internal.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "soc/soc_caps.h"
  10. #include "sdkconfig.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. extern bool g_panic_abort;
  15. extern void *g_exc_frames[SOC_CPU_CORES_NUM];
  16. // Function to print longer amounts of information such as the details
  17. // and backtrace field of panic_info_t. These functions should limit themselves
  18. // to printing to the console and should do other more involved processing,
  19. // and must be aware that the main logic in panic.c has a watchdog timer active.
  20. typedef void (*panic_info_dump_fn_t)(const void* frame);
  21. // Non architecture specific exceptions (generally valid for all targets).
  22. // Can be used to convey to the main logic what exception is being
  23. // dealt with to perform some actions, without knowing the underlying
  24. // architecture/chip-specific exception.
  25. typedef enum {
  26. PANIC_EXCEPTION_DEBUG,
  27. PANIC_EXCEPTION_IWDT,
  28. PANIC_EXCEPTION_TWDT,
  29. PANIC_EXCEPTION_ABORT,
  30. PANIC_EXCEPTION_FAULT, // catch-all for all types of faults
  31. } panic_exception_t;
  32. typedef struct {
  33. int core; // core which triggered panic
  34. panic_exception_t exception; // non-architecture-specific exception code
  35. const char* reason; // exception string
  36. const char* description; // short description of the exception
  37. panic_info_dump_fn_t details; // more details on the exception
  38. panic_info_dump_fn_t state; // processor state, usually the contents of the registers
  39. const void* addr; // instruction address that triggered the exception
  40. const void* frame; // reference to the frame
  41. bool pseudo_excause; // flag indicating that exception cause has special meaning
  42. } panic_info_t;
  43. #define PANIC_INFO_DUMP(info, dump_fn) {if ((info)->dump_fn) (*(info)->dump_fn)((info->frame));}
  44. // Create own print functions, since printf might be broken, and can be silenced
  45. // when CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  46. #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  47. void panic_print_char(char c);
  48. void panic_print_str(const char *str);
  49. void panic_print_dec(int d);
  50. void panic_print_hex(int h);
  51. #else
  52. #define panic_print_char(c)
  53. #define panic_print_str(str)
  54. #define panic_print_dec(d)
  55. #define panic_print_hex(h)
  56. #endif
  57. void __attribute__((__noreturn__)) panic_abort(const char *details);
  58. void panic_arch_fill_info(void *frame, panic_info_t *info);
  59. void panic_soc_fill_info(void *frame, panic_info_t *info);
  60. void panic_print_registers(const void *frame, int core);
  61. void panic_print_backtrace(const void *frame, int core);
  62. uint32_t panic_get_address(const void* frame);
  63. void panic_set_address(void *frame, uint32_t addr);
  64. uint32_t panic_get_cause(const void* frame);
  65. #ifdef __cplusplus
  66. }
  67. #endif