panic_internal.h 2.9 KB

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