luat_debug.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_MODE_E;
  37. /**
  38. * @brief 格式打印并输出到LOG口
  39. *
  40. * @param fmt 格式
  41. * @param ... 后续变量
  42. */
  43. void luat_debug_print(const char *fmt, ...);
  44. /**
  45. * @brief luat_debug_print宏定义为LUAT_DEBUG_PRINT
  46. * @param fmt 格式
  47. * @param ... 后续变量
  48. */
  49. #define LUAT_DEBUG_PRINT(fmt, argv...) luat_debug_print("%s %d:"fmt, __FUNCTION__,__LINE__, ##argv)
  50. /**
  51. * @brief 断言处理,并格式打印输出到LOG口
  52. *
  53. * @param fun_name 断言的函数
  54. * @param line_no 行号
  55. * @param fmt 格式
  56. * @param ... 后续变量
  57. */
  58. void luat_debug_assert(const char *fun_name, unsigned int line_no, const char *fmt, ...);
  59. #define LUAT_DEBUG_ASSERT(condition, fmt, argv...) do { \
  60. { \
  61. if((condition) == 0) \
  62. { \
  63. luat_debug_assert(__FUNCTION__, __LINE__, fmt, ##argv); \
  64. }\
  65. } \
  66. } while(0) ///< luat_debug_assert宏定义为LUAT_DEBUG_ASSERT
  67. /**
  68. * @brief 设置出现异常后系统处理模式
  69. *
  70. * @param mode 处理模式 LUAT_DEBUG_FAULT_RESET 重启模式
  71. LUAT_DEBUG_FAULT_HANG 死机模式
  72. */
  73. void luat_debug_set_fault_mode(LUAT_DEBUG_FAULT_MODE_E mode);
  74. /**
  75. * @brief 是否开启/停止csdk log
  76. *
  77. * @param onoff 开关 0关闭 1打开,开机默认开状态
  78. */
  79. void luat_debug_print_onoff(unsigned char onoff);
  80. /** @}*/
  81. #endif