为裁判系统添加了守护线程,拟解决超级电容功率控制问题
This commit is contained in:
parent
4ef3aa2f76
commit
7a95d3c451
|
@ -131,7 +131,7 @@ void MX_FREERTOS_Init(void)
|
|||
osThreadDef(instask, StartINSTASK, osPriorityNormal, 0, 1024);
|
||||
insTaskHandle = osThreadCreate(osThread(instask), NULL);
|
||||
|
||||
osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 512);
|
||||
osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 256);
|
||||
motorTaskHandle = osThreadCreate(osThread(motortask), NULL);
|
||||
|
||||
osThreadDef(daemontask, StartDAEMONTASK, osPriorityNormal, 0, 128);
|
||||
|
@ -159,10 +159,10 @@ void StartDefaultTask(void const *argument)
|
|||
MX_USB_DEVICE_Init();
|
||||
/* USER CODE BEGIN StartDefaultTask */
|
||||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
osDelay(1);
|
||||
}
|
||||
// for (;;)
|
||||
// {
|
||||
// osDelay(1);
|
||||
// }
|
||||
/* USER CODE END StartDefaultTask */
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
#include "rm_referee.h"
|
||||
#include "referee_UI.h"
|
||||
#include "string.h"
|
||||
|
||||
static Referee_Interactive_info_t *Interactive_data; // UI绘制需要的机器人状态数据
|
||||
static referee_info_t *referee_recv_info; // 接收到的裁判系统数据
|
||||
uint8_t UI_Seq; // 包序号,供整个referee文件使用
|
||||
|
||||
/**
|
||||
* @brief 判断各种ID,选择客户端ID
|
||||
|
@ -280,7 +282,7 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data)
|
|||
|
||||
if (_Interactive_data->lid_mode != _Interactive_data->lid_last_mode)
|
||||
{
|
||||
_Interactive_data->Referee_Interactive_Flag.lid_flag= 1;
|
||||
_Interactive_data->Referee_Interactive_Flag.lid_flag = 1;
|
||||
_Interactive_data->lid_last_mode = _Interactive_data->lid_mode;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,47 +14,14 @@
|
|||
#include "crc_ref.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "task.h"
|
||||
#include "daemon.h"
|
||||
|
||||
#define RE_RX_BUFFER_SIZE 200
|
||||
|
||||
static USARTInstance *referee_usart_instance; // 裁判系统串口实例
|
||||
static DaemonInstance *referee_daemon; // 裁判系统守护进程
|
||||
static referee_info_t referee_info; // 裁判系统数据
|
||||
|
||||
static void RefereeRxCallback();
|
||||
static void JudgeReadData(uint8_t *buff);
|
||||
|
||||
uint8_t UI_Seq = 0; // 包序号,供整个referee文件使用
|
||||
|
||||
/* 裁判系统通信初始化 */
|
||||
referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle)
|
||||
{
|
||||
USART_Init_Config_s conf;
|
||||
conf.module_callback = RefereeRxCallback;
|
||||
conf.usart_handle = referee_usart_handle;
|
||||
conf.recv_buff_size = RE_RX_BUFFER_SIZE;
|
||||
referee_usart_instance = USARTRegister(&conf);
|
||||
return &referee_info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 裁判系统数据发送函数,由于使用
|
||||
* @param
|
||||
*/
|
||||
void RefereeSend(uint8_t *send, uint16_t tx_len)
|
||||
{
|
||||
static TickType_t xLastWakeTime;
|
||||
USARTSend(referee_usart_instance, send, tx_len, USART_TRANSFER_DMA);
|
||||
vTaskDelayUntil(&xLastWakeTime, 120);
|
||||
}
|
||||
|
||||
/*裁判系统串口接收回调函数,解析数据 */
|
||||
static void RefereeRxCallback()
|
||||
{
|
||||
JudgeReadData(referee_usart_instance->recv_buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取裁判数据,中断中读取保证速度
|
||||
* @param buff: 读取到的裁判系统原始数据
|
||||
|
@ -136,3 +103,45 @@ static void JudgeReadData(uint8_t *buff)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*裁判系统串口接收回调函数,解析数据 */
|
||||
static void RefereeRxCallback()
|
||||
{
|
||||
DaemonReload(referee_daemon);
|
||||
JudgeReadData(referee_usart_instance->recv_buff);
|
||||
}
|
||||
// 裁判系统丢失回调函数,重新初始化裁判系统串口
|
||||
static void RefereeLostCallback(void *arg)
|
||||
{
|
||||
USARTServiceInit(referee_usart_instance);
|
||||
}
|
||||
|
||||
/* 裁判系统通信初始化 */
|
||||
referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle)
|
||||
{
|
||||
USART_Init_Config_s conf;
|
||||
conf.module_callback = RefereeRxCallback;
|
||||
conf.usart_handle = referee_usart_handle;
|
||||
conf.recv_buff_size = RE_RX_BUFFER_SIZE;
|
||||
referee_usart_instance = USARTRegister(&conf);
|
||||
|
||||
Daemon_Init_Config_s daemon_conf = {
|
||||
.callback = RefereeLostCallback,
|
||||
.owner_id = referee_usart_instance,
|
||||
.reload_count = 30, // 0.3s没有收到数据,则认为丢失,重启串口接收
|
||||
};
|
||||
referee_daemon = DaemonRegister(&daemon_conf);
|
||||
|
||||
return &referee_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 裁判系统数据发送函数
|
||||
* @param
|
||||
*/
|
||||
void RefereeSend(uint8_t *send, uint16_t tx_len)
|
||||
{
|
||||
static TickType_t xLastWakeTime;
|
||||
USARTSend(referee_usart_instance, send, tx_len, USART_TRANSFER_DMA);
|
||||
vTaskDelayUntil(&xLastWakeTime, 120);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue