panic_internal.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "port/panic_funcs.h"
  16. #include "sdkconfig.h"
  17. extern bool g_panic_abort;
  18. // Function to print longer amounts of information such as the details
  19. // and backtrace field of panic_info_t. These functions should limit themselves
  20. // to printing to the console and should do other more involved processing,
  21. // and must be aware that the main logic in panic.c has a watchdog timer active.
  22. typedef void (*panic_info_dump_fn_t)(const void* frame);
  23. // Non architecture specific exceptions (generally valid for all targets).
  24. // Can be used to convey to the main logic what exception is being
  25. // dealt with to perform some actions, without knowing the underlying
  26. // architecture/chip-specific exception.
  27. typedef enum {
  28. PANIC_EXCEPTION_DEBUG,
  29. PANIC_EXCEPTION_IWDT,
  30. PANIC_EXCEPTION_TWDT,
  31. PANIC_EXCEPTION_ABORT,
  32. PANIC_EXCEPTION_FAULT, // catch-all for all types of faults
  33. } panic_exception_t;
  34. typedef struct {
  35. int core; // core which triggered panic
  36. panic_exception_t exception; // non-architecture-specific exception code
  37. const char* reason; // exception string
  38. const char* description; // short description of the exception
  39. panic_info_dump_fn_t details; // more details on the exception
  40. panic_info_dump_fn_t state; // processor state, usually the contents of the registers
  41. const void* addr; // instruction address that triggered the exception
  42. const void* frame; // reference to the frame
  43. } panic_info_t;
  44. #define PANIC_INFO_DUMP(info, dump_fn) {if ((info)->dump_fn) (*(info)->dump_fn)((info->frame));}
  45. // Create own print functions, since printf might be broken, and can be silenced
  46. // when CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  47. #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  48. void panic_print_char(char c);
  49. void panic_print_str(const char *str);
  50. void panic_print_dec(int d);
  51. void panic_print_hex(int h);
  52. #else
  53. #define panic_print_char(c)
  54. #define panic_print_str(str)
  55. #define panic_print_dec(d)
  56. #define panic_print_hex(h)
  57. #endif
  58. void __attribute__((noreturn)) panic_abort(const char *details);