luat_debug.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef LUAT_DEBUG_H
  22. #define LUAT_DEBUG_H
  23. /**
  24. * @defgroup luatos_debug 调式接口
  25. * @{
  26. */
  27. /**
  28. * @brief 出现异常后系统处理
  29. *
  30. */
  31. typedef enum LUAT_DEBUG_FAULT_MODE
  32. {
  33. LUAT_DEBUG_FAULT_RESET, /**< 出现异常后重启,批量产品强烈建议用 */
  34. LUAT_DEBUG_FAULT_HANG, /**< 出现异常后死机,测试阶段强烈建议用 */
  35. LUAT_DEBUG_FAULT_HANG_RESET, /**< 出现异常后尝试上传死机信息给PC工具,上传成功或者超时后重启 */
  36. LUAT_DEBUG_FAULT_SAVE_RESET /**< 出现异常后保存信息到flash,然后重启 */
  37. }LUAT_DEBUG_FAULT_MODE_E;
  38. /**
  39. * @brief 格式打印并输出到LOG口
  40. *
  41. * @param fmt 格式
  42. * @param ... 后续变量
  43. */
  44. void luat_debug_print(const char *fmt, ...);
  45. /**
  46. * @brief luat_debug_print宏定义为LUAT_DEBUG_PRINT
  47. * @param fmt 格式
  48. * @param ... 后续变量
  49. */
  50. #define LUAT_DEBUG_PRINT(fmt, ...) luat_debug_print("%s %d:"fmt, __FUNCTION__,__LINE__, ##__VA_ARGS__)
  51. /**
  52. * @brief 断言处理,并格式打印输出到LOG口
  53. *
  54. * @param fun_name 断言的函数
  55. * @param line_no 行号
  56. * @param fmt 格式
  57. * @param ... 后续变量
  58. */
  59. void luat_debug_assert(const char *fun_name, unsigned int line_no, const char *fmt, ...);
  60. #define LUAT_DEBUG_ASSERT(condition, fmt, ...) do { \
  61. { \
  62. if((condition) == 0) \
  63. { \
  64. luat_debug_assert(__FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \
  65. }\
  66. } \
  67. } while(0) ///< luat_debug_assert宏定义为LUAT_DEBUG_ASSERT
  68. /**
  69. * @brief 设置出现异常后系统处理模式
  70. *
  71. * @param mode 处理模式 LUAT_DEBUG_FAULT_RESET 重启模式
  72. LUAT_DEBUG_FAULT_HANG 死机模式
  73. */
  74. void luat_debug_set_fault_mode(LUAT_DEBUG_FAULT_MODE_E mode);
  75. /**
  76. * @brief 是否开启/停止csdk log
  77. *
  78. * @param onoff 开关 0关闭 1打开,开机默认开状态
  79. */
  80. void luat_debug_print_onoff(unsigned char onoff);
  81. /** @}*/
  82. #endif