panic_internal.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "sdkconfig.h"
  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. } panic_info_t;
  42. #define PANIC_INFO_DUMP(info, dump_fn) {if ((info)->dump_fn) (*(info)->dump_fn)((info->frame));}
  43. // Create own print functions, since printf might be broken, and can be silenced
  44. // when CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  45. #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  46. void panic_print_char(char c);
  47. void panic_print_str(const char *str);
  48. void panic_print_dec(int d);
  49. void panic_print_hex(int h);
  50. #else
  51. #define panic_print_char(c)
  52. #define panic_print_str(str)
  53. #define panic_print_dec(d)
  54. #define panic_print_hex(h)
  55. #endif
  56. void __attribute__((noreturn)) panic_abort(const char *details);