esp_core_dump.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2015-2019 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. #ifndef ESP_CORE_DUMP_H_
  14. #define ESP_CORE_DUMP_H_
  15. #include <stddef.h>
  16. #include "esp_err.h"
  17. #include "freertos/xtensa_context.h"
  18. /**************************************************************************************/
  19. /******************************** EXCEPTION MODE API **********************************/
  20. /**************************************************************************************/
  21. /**
  22. * @brief Initializes core dump module internal data.
  23. *
  24. * @note Should be called at system startup.
  25. */
  26. void esp_core_dump_init(void);
  27. /**
  28. * @brief Saves core dump to flash.
  29. *
  30. * The structure of data stored in flash is as follows:
  31. *
  32. * | TOTAL_LEN | VERSION | TASKS_NUM | TCB_SIZE |
  33. * | TCB_ADDR_1 | STACK_TOP_1 | STACK_END_1 | TCB_1 | STACK_1 |
  34. * . . . .
  35. * . . . .
  36. * | TCB_ADDR_N | STACK_TOP_N | STACK_END_N | TCB_N | STACK_N |
  37. * | CRC32 |
  38. *
  39. * Core dump in flash consists of header and data for every task in the system at the moment of crash.
  40. * For flash data integrity control CRC is used at the end of core the dump data.
  41. * The structure of core dump data is described below in details.
  42. * 1) Core dump starts with header:
  43. * 1.1) TOTAL_LEN is total length of core dump data in flash including CRC. Size is 4 bytes.
  44. * 1.2) VERSION field keeps 4 byte version of core dump.
  45. * 1.2) TASKS_NUM is the number of tasks for which data are stored. Size is 4 bytes.
  46. * 1.3) TCB_SIZE is the size of task's TCB structure. Size is 4 bytes.
  47. * 2) Core dump header is followed by the data for every task in the system.
  48. * Task data are started with task header:
  49. * 2.1) TCB_ADDR is the address of TCB in memory. Size is 4 bytes.
  50. * 2.2) STACK_TOP is the top of task's stack (address of the topmost stack item). Size is 4 bytes.
  51. * 2.2) STACK_END is the end of task's stack (address from which task's stack starts). Size is 4 bytes.
  52. * 3) Task header is followed by TCB data. Size is TCB_SIZE bytes.
  53. * 4) Task's stack is placed after TCB data. Size is (STACK_END - STACK_TOP) bytes.
  54. * 5) CRC is placed at the end of the data.
  55. */
  56. void esp_core_dump_to_flash(XtExcFrame *frame);
  57. /**
  58. * @brief Print base64-encoded core dump to UART.
  59. *
  60. * The structure of core dump data is the same as for data stored in flash (@see esp_core_dump_to_flash) with some notes:
  61. * 1) CRC is not present in core dump printed to UART.
  62. * 2) Since CRC is omitted TOTAL_LEN does not include its size.
  63. * 3) Printed base64 data are surrounded with special messages to help user recognize the start and end of actual data.
  64. */
  65. void esp_core_dump_to_uart(XtExcFrame *frame);
  66. /**************************************************************************************/
  67. /*********************************** USER MODE API ************************************/
  68. /**************************************************************************************/
  69. /**
  70. * @brief Retrieves address and size of coredump data in flash.
  71. * This function is always available, even when core dump is disabled in menuconfig.
  72. *
  73. * @param out_addr pointer to store image address in flash.
  74. * @param out_size pointer to store image size in flash (including CRC). In bytes.
  75. *
  76. * @return ESP_OK on success, otherwise \see esp_err_t
  77. */
  78. esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size);
  79. #endif