core_debug.h 2.9 KB

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