bs_bcu_app/kit/kit_debug.h

135 lines
3.6 KiB
C
Raw Normal View History

2024-11-07 17:24:19 +08:00
#ifndef _KIT_DEBUG_H_
#define _KIT_DEBUG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "kit_time.h"
#include "kit_macro.h"
#if defined (DEBUG_ASSERT_RTT) || (DEBUG_ASSERT_UART)
#if defined (DEBUG_ASSERT_RTT)
#ifndef DEBUG_PRINTF_RTT
#define DEBUG_PRINTF_RTT
#endif
#elif defined (DEBUG_ASSERT_UART)
#ifndef DEBUG_PRINTF_UART
#define DEBUG_PRINTF_UART
#endif
#endif
void kit_assert_param(uint8_t* file, uint32_t line);
void kit_assert_res(uint8_t* file, uint32_t line, uint32_t dev, KitResult res);
#define KIT_ASSERT_PARAM(expr) ((expr) ? (void)0 : kit_assert_param((uint8_t *)__FILE__, __LINE__))
#define KIT_ASSERT_RES(dev, res) ((res == 0) ? (void)0 : kit_assert_res((uint8_t *)__FILE__, __LINE__, dev, res))
#else
#define KIT_ASSERT_PARAM(expr) ((void)0)
#define KIT_ASSERT_RES(dev, res) ((void)0)
#endif
#if defined (DEBUG_PRINTF_RTT)
#include "SEGGER_RTT.h"
#define KIT_DEBUG_PRINTF(fmt, args...) \
do\
{\
SEGGER_RTT_printf(0, "%d %s>> ", kit_time_get_tick(), __FUNCTION__);\
SEGGER_RTT_printf(0, fmt, ##args);\
}while(0)
#define KIT_MODULE_PRINTF(en, fmt, args...) \
if(en == true) \
{\
SEGGER_RTT_printf(0, "%d %s>> ", kit_time_get_tick(), __FUNCTION__);\
SEGGER_RTT_printf(0, fmt, ##args);\
}
#define KIT_DEBUG_PRINTF_TIME() \
do\
{\
SEGGER_RTT_printf(0, "%d %s>> ", kit_time_get_tick(), __FUNCTION__);\
SEGGER_RTT_printf(0, fmt, ##args);\
}while(0)
#elif defined (DEBUG_ASSERT_UART)
#include "stdio.h"
#define KIT_DEBUG_PRINTF(fmt, args...) \
do\
{\
printf("%d %s>> ", kit_time_get_tick(), __FUNCTION__);\
printf(fmt, ##args);\
}while(0)
#else
#define KIT_DEBUG_PRINTF(fmt, args...) ((void)0)
#endif
#if defined (DEBUG_PRINTF_RTT)
#include "SEGGER_RTT.h"
#define KIT_DEBUG_PRINTF_U8_BUF(buf, len) \
do\
{\
uint32_t i = 0; \
uint8_t * _buf = (uint8_t *)buf; \
for(i = 0; i < len; i++) \
{ \
SEGGER_RTT_printf(0, "%x ", _buf[i]);\
} \
SEGGER_RTT_printf(0, "\r\n");\
}while(0)
#define KIT_DEBUG_PRINTF_U16_BUF(buf, len) \
do\
{\
uint32_t i = 0; \
uint16_t * _buf = (uint16_t *)buf; \
for(i = 0; i < len; i++) \
{ \
SEGGER_RTT_printf(0, "%d ", _buf[i]);\
} \
SEGGER_RTT_printf(0, "\r\n");\
}while(0)
#define KIT_DEBUG_PRINTF_I32_BUF(buf, len) \
do\
{\
uint32_t i = 0; \
int32_t * _buf = (int32_t *)buf; \
for(i = 0; i < len; i++) \
{ \
SEGGER_RTT_printf(0, "%d ", _buf[i]);\
} \
SEGGER_RTT_printf(0, "\r\n");\
}while(0)
#elif defined (DEBUG_ASSERT_UART)
#include "stdio.h"
#define KIT_DEBUG_PRINTF(fmt, args...) \
do\
{\
printf("%d %s>> ", kit_time_get_tick(), __FUNCTION__);\
printf(fmt, ##args);\
}while(0)
#else
#define KIT_DEBUG_PRINTF_U8_BUF(buf, len) ((void)0)
#define KIT_DEBUG_PRINTF_U16_BUF(buf, len) ((void)0)
#define KIT_DEBUG_PRINTF_I32_BUF(buf, len) ((void)0)
#define KIT_DEBUG_PRINTF(fmt, args...) ((void)0)
#define KIT_MODULE_PRINTF(en, fmt, args...) ((void)0)
#endif
void kit_debug_queue(uint16_t *buf, uint8_t len, uint16_t value);
void kit_debug_scope_init(const char* type, uint8_t *buf, uint16_t len);
void kit_debug_scope_save(uint16_t tick, uint16_t x, uint16_t y, uint16_t z);
#ifdef DEBUG_ASSERT_UART
int fputc(int ch, FILE *f);
#endif
#ifdef __cplusplus
}
#endif
#endif