修改了bsp_usart的初始化方式,防止出现变包长数据读取一场的问题.增加了注释.
This commit is contained in:
parent
269b08f701
commit
e3137d867f
|
@ -3,7 +3,8 @@
|
|||
"memory.h": "c",
|
||||
"stdint-gcc.h": "c",
|
||||
"led_task.h": "c",
|
||||
"stdinf.h": "c"
|
||||
"stdinf.h": "c",
|
||||
"usart.h": "c"
|
||||
},
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
|
||||
}
|
|
@ -127,7 +127,7 @@ int main(void)
|
|||
.controller_param_init_config = {.current_PID = {.Improve = 0, .Kp = 1, .Ki = 0, .Kd = 0, .DeadBand = 0, .MaxOut = 4000}, .speed_PID = {.Improve = 0, .Kp = 1, .Ki = 0, .Kd = 0, .DeadBand = 0, .MaxOut = 4000}}};
|
||||
dji_motor_instance *djimotor = DJIMotorInit(config);
|
||||
|
||||
referee_init(&huart6);
|
||||
RefereeInit(&huart6);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Call init function for freertos objects (in freertos.c) */
|
||||
|
|
|
@ -259,3 +259,5 @@ HAL库初始化 --> BSP初始化 --> Application初始化 --> app调用其拥有
|
|||
**注意,应用初始化不得放入其对应任务中,即使是在死循环前,否则可能导致一些需要定时器的任务初始化异常**。
|
||||
|
||||
APP会调用其所有的模块的初始化函数(注册函数),这是因为本框架的设计思想是任何模块在被注册(构造/初始化)之前,都是不存在的,当且仅当定义了一个模块结构体(也称实例)的时候,才有一个实体的概念。
|
||||
|
||||
> 参考了哈工深南宫小樱战队的框架设计,在此鸣谢。
|
|
@ -67,8 +67,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
|||
if (huart == instance[i]->usart_handle)
|
||||
{
|
||||
instance[i]->module_callback();
|
||||
memset(instance[i]->recv_buff,0,instance[i]->recv_buff_size);
|
||||
|
||||
memset(instance[i]->recv_buff,0,instance[i]->recv_buff_size); // 接收结束后清空buffer,对于变长数据是必要的
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(instance[i]->usart_handle, instance[i]->recv_buff, instance[i]->recv_buff_size);
|
||||
__HAL_DMA_DISABLE_IT(instance[i]->usart_handle->hdmarx, DMA_IT_HT);
|
||||
break;
|
||||
|
|
|
@ -13,6 +13,7 @@ typedef void (*usart_module_callback)();
|
|||
/* usart_instance struct,each app would have one instance */
|
||||
typedef struct
|
||||
{
|
||||
// 更新:弃用malloc方案,使用了固定大小的数组方便debug时查看
|
||||
uint8_t recv_buff[USART_RXBUFF_LIMIT]; // 预先定义的最大buff大小,如果太小请修改USART_RXBUFF_LIMIT
|
||||
uint8_t recv_buff_size; // 模块接收一包数据的大小
|
||||
UART_HandleTypeDef *usart_handle; // 实例对应的usart_handle
|
||||
|
|
|
@ -209,6 +209,7 @@ void DJIMotorControl()
|
|||
motor_controller = &motor->motor_controller;
|
||||
motor_measure = &motor->motor_measure;
|
||||
|
||||
// pid_ref会顺次通过被启用的环充当数据的载体
|
||||
if (motor_setting->close_loop_type & ANGLE_LOOP) // 计算位置环
|
||||
{
|
||||
if (motor_setting->angle_feedback_source == OTHER_FEED)
|
||||
|
@ -233,7 +234,7 @@ void DJIMotorControl()
|
|||
motor_controller->pid_ref = PID_Calculate(&motor_controller->current_PID, motor_measure->given_current, motor_controller->pid_ref);
|
||||
}
|
||||
|
||||
set = (int16_t)motor_controller->pid_ref;
|
||||
set = (int16_t)motor_controller->pid_ref; // 获取最终输出
|
||||
if (motor_setting->reverse_flag == MOTOR_DIRECTION_REVERSE) // 设置反转
|
||||
set *= -1;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "bsp_usart.h"
|
||||
#include "dma.h"
|
||||
|
||||
|
||||
// 参考深圳大学 Infantry_X-master
|
||||
#define RE_RX_BUFFER_SIZE 200
|
||||
|
||||
|
@ -16,14 +15,12 @@ referee_info_t referee_info;
|
|||
uint8_t Judge_Self_ID; // 当前机器人的ID
|
||||
uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID
|
||||
|
||||
|
||||
|
||||
static void ReceiveCallback()
|
||||
{
|
||||
Judge_Read_Data(referee_usart_instance.recv_buff);
|
||||
JudgeReadData(referee_usart_instance.recv_buff);
|
||||
}
|
||||
|
||||
void referee_init(UART_HandleTypeDef *referee_usart_handle)
|
||||
void RefereeInit(UART_HandleTypeDef *referee_usart_handle)
|
||||
{
|
||||
referee_usart_instance.module_callback = ReceiveCallback;
|
||||
referee_usart_instance.usart_handle = referee_usart_handle;
|
||||
|
@ -31,22 +28,19 @@ void referee_init(UART_HandleTypeDef *referee_usart_handle)
|
|||
USARTRegister(&referee_usart_instance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 读取裁判数据,中断中读取保证速度
|
||||
* @param 缓存数据
|
||||
* @retval 是否对正误判断做处理
|
||||
* @attention 在此判断帧头和CRC校验,无误再写入数据,不重复判断帧头
|
||||
*/
|
||||
void Judge_Read_Data(uint8_t *ReadFromUsart)
|
||||
void JudgeReadData(uint8_t *ReadFromUsart)
|
||||
{
|
||||
uint16_t judge_length; // 统计一帧数据长度
|
||||
// referee_info.CmdID = 0; //数据命令码解析
|
||||
// 空数据包,则不作任何处理
|
||||
if (ReadFromUsart == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return;
|
||||
|
||||
// 写入帧头数据(5-byte),用于判断是否开始存储裁判数据
|
||||
memcpy(&referee_info.FrameHeader, ReadFromUsart, LEN_HEADER);
|
||||
|
@ -122,8 +116,7 @@ void Judge_Read_Data(uint8_t *ReadFromUsart)
|
|||
if (*(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL) == 0xA5)
|
||||
{
|
||||
// 如果一个数据包出现了多帧数据,则再次读取
|
||||
Judge_Read_Data(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL);
|
||||
|
||||
JudgeReadData(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +127,7 @@ void Judge_Read_Data(uint8_t *ReadFromUsart)
|
|||
* @retval 实时功率值
|
||||
* @attention
|
||||
*/
|
||||
float JUDGE_fGetChassisPower(void)
|
||||
float JudgeGetChassisPower(void)
|
||||
{
|
||||
return (referee_info.PowerHeatData.chassis_power);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
// 起始字节,协议固定为0xA5
|
||||
#define JUDGE_FRAME_HEADER (0xA5)
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
/***************裁判系统数据接收********************/
|
||||
|
@ -341,14 +342,8 @@ typedef struct
|
|||
|
||||
extern referee_info_t referee_info;
|
||||
|
||||
void referee_init(UART_HandleTypeDef *referee_usart_handle);
|
||||
void Judge_Read_Data(uint8_t *ReadFromUsart);
|
||||
float JUDGE_fGetChassisPower(void);
|
||||
void RefereeInit(UART_HandleTypeDef *referee_usart_handle);
|
||||
void JudgeReadData(uint8_t *ReadFromUsart);
|
||||
float JudgeGetChassisPower(void);
|
||||
|
||||
#endif // !REFEREE_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue