mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
增加了等级日志和RTT viewer的支持
This commit is contained in:
@@ -15,7 +15,7 @@ int PrintLog(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int n = SEGGER_RTT_vprintf(BUFFER_INDEX, fmt, &args);
|
||||
int n = SEGGER_RTT_vprintf(BUFFER_INDEX, fmt, &args); // 一次可以开启多个buffer(多个终端),我们只用一个
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
@@ -31,4 +31,5 @@ void Float2Str(char *str, float va)
|
||||
sprintf(str, "-%d.%d", head, point);
|
||||
else
|
||||
sprintf(str, "%d.%d", head, point);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,34 @@
|
||||
#define _BSP_LOG_H
|
||||
|
||||
/**
|
||||
* @brief 初始化日志功能,在操作系统启动之前调用
|
||||
* @brief 日志功能原型,供下面的LOGI,LOGW,LOGE等使用
|
||||
*
|
||||
*/
|
||||
void BSPLogInit();
|
||||
#define LOG_PROTO(type,color,format,...) \
|
||||
SEGGER_RTT_printf(BUFFER_INDEX," %s%s"format"\r\n%s", \
|
||||
color, \
|
||||
type, \
|
||||
##__VA_ARGS__, \
|
||||
RTT_CTRL_RESET)
|
||||
|
||||
/* 清屏 */
|
||||
#define LOG_CLEAR() SEGGER_RTT_WriteString(0, " "RTT_CTRL_CLEAR)
|
||||
|
||||
/* 无颜色日志输出 */
|
||||
#define LOG(format,...) LOG_PROTO("","",format,##__VA_ARGS__)
|
||||
|
||||
/* 有颜色格式日志输出 */
|
||||
#define LOGINFO(format,...) LOG_PROTO("I: ", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__)
|
||||
#define LOGWARNING(format,...) LOG_PROTO("W: ", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__)
|
||||
#define LOGERROR(format,...) LOG_PROTO("E: ", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__)
|
||||
|
||||
|
||||
/**
|
||||
* @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf
|
||||
*
|
||||
* @param fmt
|
||||
* @param ...
|
||||
* @return int
|
||||
* @param fmt 格式字符串
|
||||
* @param ... 参数列表
|
||||
* @return int 打印的log字符数
|
||||
*/
|
||||
int PrintLog(const char *fmt, ...);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ static USARTInstance *usart_instance[DEVICE_USART_CNT] = {NULL};
|
||||
*
|
||||
* @param _instance instance owned by module,模块拥有的串口实例
|
||||
*/
|
||||
static void USARTServiceInit(USARTInstance *_instance)
|
||||
void USARTServiceInit(USARTInstance *_instance)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(_instance->usart_handle, _instance->recv_buff, _instance->recv_buff_size);
|
||||
// 关闭dma half transfer中断防止两次进入HAL_UARTEx_RxEventCallback()
|
||||
@@ -67,11 +67,24 @@ void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size,
|
||||
break;
|
||||
default:
|
||||
while (1)
|
||||
; // illegal mode! check your code context!
|
||||
; // illegal mode! check your code context! 检查定义instance的代码上下文,可能出现指针越界
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 串口发送时,gstate会被设为BUSY_TX */
|
||||
uint8_t USARTIsReady(USARTInstance *_instance)
|
||||
{
|
||||
if(_instance->usart_handle->gState | HAL_UART_STATE_BUSY_TX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 每次dma/idle中断发生时,都会调用此函数.对于每个uart实例会调用对应的回调进行进一步的处理
|
||||
* 例如:视觉协议解析/遥控器解析/裁判系统解析
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// 模块回调函数,用于解析协议
|
||||
typedef void (*usart_module_callback)();
|
||||
|
||||
/* 发送模式枚举 */
|
||||
typedef enum
|
||||
{
|
||||
USART_TRANSFER_NONE=0,
|
||||
@@ -37,17 +38,25 @@ typedef struct
|
||||
} USART_Init_Config_s;
|
||||
|
||||
/**
|
||||
* @brief 注册一个串口实例.
|
||||
* @brief 注册一个串口实例,返回一个串口实例指针
|
||||
*
|
||||
* @param init_config 传入串口初始化结构体
|
||||
*/
|
||||
USARTInstance *USARTRegister(USART_Init_Config_s *init_config);
|
||||
|
||||
/**
|
||||
* @brief 启动串口服务,需要传入一个usart实例.一般用于lost callback的情况(使用串口的模块daemon)
|
||||
*
|
||||
* @param _instance
|
||||
*/
|
||||
void USARTServiceInit(USARTInstance *_instance);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 通过调用该函数可以发送一帧数据,需要传入一个usart实例,发送buff以及这一帧的长度
|
||||
* 当前默认为DMA发送,后续会增加中断发送和阻塞发送模式的选择
|
||||
* @todo 目前只支持DMA发送,后续会增加中断发送和阻塞发送模式的选择
|
||||
* 在短时间内连续调用此接口会导致上一次的发送未完成而新的发送取消,后续会增加一个发送状态的判断以及消息队列以解决这个问题
|
||||
* @note 在短时间内连续调用此接口,若采用IT/DMA会导致上一次的发送未完成而新的发送取消.
|
||||
* @note 若希望连续使用DMA/IT进行发送,请配合USARTIsReady()使用,或自行为你的module实现一个发送队列和任务.
|
||||
* @todo 是否考虑为USARTInstance增加发送队列以进行连续发送?
|
||||
*
|
||||
* @param _instance 串口实例
|
||||
* @param send_buf 待发送数据的buffer
|
||||
@@ -55,4 +64,12 @@ USARTInstance *USARTRegister(USART_Init_Config_s *init_config);
|
||||
*/
|
||||
void USARTSend(USARTInstance *_instance, uint8_t *send_buf, uint16_t send_size,USART_TRANSFER_MODE mode);
|
||||
|
||||
/**
|
||||
* @brief 判断串口是否准备好,用于连续或异步的IT/DMA发送
|
||||
*
|
||||
* @param _instance 要判断的串口实例
|
||||
* @return uint8_t ready 1, busy 0
|
||||
*/
|
||||
uint8_t USARTIsReady(USARTInstance *_instance);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user