mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # .vscode/launch.json # application/gimbal/gimbal.c # application/robot.c # bsp/usart/bsp_usart.c # bsp/usart/bsp_usart.h # modules/master_machine/master_process.c # modules/master_machine/seasky_protocol.c
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
/* can instance ptrs storage, used for recv callback */
|
||||
// 在CAN产生接收中断会遍历数组,选出hcan和rxid与发生中断的实例相同的那个,调用其回调函数
|
||||
// @todo: 后续为每个CAN总线单独添加一个can_instance指针数组,提高回调查找的性能
|
||||
static CANInstance *can_instance[CAN_MX_REGISTER_CNT] = {NULL};
|
||||
static uint8_t idx; // 全局CAN实例索引,每次有新的模块注册会自增
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "SEGGER_RTT_Conf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFFER_INDEX 0
|
||||
|
||||
void BSPLogInit()
|
||||
{
|
||||
@@ -15,7 +14,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 +30,5 @@ void Float2Str(char *str, float va)
|
||||
sprintf(str, "-%d.%d", head, point);
|
||||
else
|
||||
sprintf(str, "%d.%d", head, point);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
#ifndef _BSP_LOG_H
|
||||
#define _BSP_LOG_H
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include "SEGGER_RTT_Conf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUFFER_INDEX 0
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化日志功能,在操作系统启动之前调用
|
||||
* @brief 日志系统初始化
|
||||
*
|
||||
*/
|
||||
void BSPLogInit();
|
||||
|
||||
/**
|
||||
* @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf
|
||||
* @brief 日志功能原型,供下面的LOGI,LOGW,LOGE等使用
|
||||
*
|
||||
* @param fmt
|
||||
* @param ...
|
||||
* @return int
|
||||
*/
|
||||
#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__)
|
||||
|
||||
/* 有颜色格式日志输出,建议使用这些宏来输出日志 */
|
||||
// information level
|
||||
#define LOGINFO(format,...) LOG_PROTO("I", RTT_CTRL_TEXT_BRIGHT_GREEN , format, ##__VA_ARGS__)
|
||||
// warning level
|
||||
#define LOGWARNING(format,...) LOG_PROTO("W", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__)
|
||||
// error level
|
||||
#define LOGERROR(format,...) LOG_PROTO("E", RTT_CTRL_TEXT_BRIGHT_RED , format, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf.
|
||||
*
|
||||
* @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,10 +67,11 @@ 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)
|
||||
{
|
||||
@@ -83,6 +84,7 @@ uint8_t USARTIsReady(USARTInstance *_instance)
|
||||
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
|
||||
|
||||
@@ -11,20 +11,21 @@
|
||||
|
||||
#include "bsp_usb.h"
|
||||
|
||||
static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2028
|
||||
static uint8_t *bsp_usb_rx_buffer; // 接收到的数据会被放在这里,buffer size为2048
|
||||
// 注意usb单个数据包(Full speed模式下)最大为64byte,超出可能会出现丢包情况
|
||||
|
||||
// 这是传输完成的回调函数,在usbd_cdc_if.c中被调用
|
||||
__weak void USBTransmitCpltCallback(uint32_t len)
|
||||
{
|
||||
// 本次发送的数据
|
||||
// 本次发送的数据长度
|
||||
UNUSED(len);
|
||||
// 传输完成会调用此函数,to do something
|
||||
}
|
||||
|
||||
// 这是接收回调函数
|
||||
__weak void USBReceiveCpltCallback(uint32_t len)
|
||||
{
|
||||
// 本次接收的数据
|
||||
// 本次接收的数据长度
|
||||
UNUSED(len);
|
||||
// 传输完成会调用此函数,to do something
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user