core_debug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 __CORE_DEBUG_H__
  22. #define __CORE_DEBUG_H__
  23. #include "stdint.h"
  24. #include "bsp_common.h"
  25. enum
  26. {
  27. DBG_CMD_REBOOT = 0,
  28. DBG_CMD_FLASHDOWNLOADSTART,
  29. DBG_CMD_FLASHDOWNLOAD,
  30. DBG_CMD_FLASHDOWNLOADEND,
  31. DBG_CMD_RUNAPP,
  32. DBG_CMD_FLASHLZMABLOCKEND,
  33. DBG_DEVICE_FW_UPGRADE_READY = 0x80,
  34. DBG_DEVICE_FW_UPGRADE_RESULT,
  35. DBG_CMD_INFO = 0xff,
  36. };
  37. #ifdef __BUILD_APP__
  38. #define DBG_INFO(x,y...) DBG_Printf("%s %d:"x"\r\n", __FUNCTION__,__LINE__,##y)
  39. #define DBG_ERR(x,y...) DBG_Printf("%s %d:"x"\r\n", __FUNCTION__,__LINE__,##y)
  40. #define DBG(x,y...) DBG_Printf("%s %d:"x"\r\n", __FUNCTION__,__LINE__,##y)
  41. #define DBGF DBG_ERR("!")
  42. #else
  43. #define DBG_INFO(x,y...) DBG_Trace("%s %d:"x, __FUNCTION__,__LINE__,##y)
  44. #define DBG_ERR(x,y...) DBG_Trace("%s %d:"x, __FUNCTION__,__LINE__,##y)
  45. //#define DBG(x,y...) DBG_Trace("%s %d:"x, __FUNCTION__,__LINE__,##y)
  46. #define DBG(x,y...)
  47. #define DBGF DBG_ERR("!")
  48. #endif
  49. /**
  50. * @brief log日志输出初始化
  51. *
  52. * @param AppMode 是否是APP模式,1是 0否
  53. */
  54. void DBG_Init(uint8_t AppMode);
  55. /**
  56. * @brief 16进制数据转成字符串输出
  57. *
  58. * @param Data
  59. * @param len
  60. */
  61. void DBG_HexPrintf(void *Data, unsigned int len);
  62. /**
  63. * @brief 非阻塞输出,app用
  64. *
  65. * @param format
  66. * @param ...
  67. */
  68. void DBG_Printf(const char* format, ...);
  69. /**
  70. * @brief 阻塞输出,在bootloader和打印堆栈信息用
  71. *
  72. * @param format
  73. * @param ...
  74. */
  75. void DBG_Trace(const char* format, ...);
  76. /**
  77. * @brief 非阻塞直接输出,app用
  78. *
  79. * @param Data
  80. * @param Len
  81. */
  82. void DBG_DirectOut(void *Data, uint32_t Len);
  83. /**
  84. * @brief 阻塞输出到串口,app用,一般不需要调用
  85. * @param IsForce 是否强制发送
  86. */
  87. void DBG_Send(void);
  88. void DBG_Response(uint8_t Cmd, uint8_t Result, uint8_t *Data, uint8_t Len);
  89. void DBG_SetRxCB(CBFuncEx_t cb);
  90. void DBG_SetTxCB(CBDataFun_t cb);
  91. void add_printf_data(uint8_t *data, uint32_t len);
  92. #endif