feat: 添加协议处理和校验和计算功能,更新 UART 相关代码
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "bsp_beep.h"
|
||||
#include "usart.h"
|
||||
#include "elog.h"
|
||||
#include "protocol.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -57,6 +58,18 @@ const osThreadAttr_t initTask_attributes = {
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* Definitions for CarCtrlTask */
|
||||
osThreadId_t CarCtrlTaskHandle;
|
||||
const osThreadAttr_t CarCtrlTask_attributes = {
|
||||
.name = "CarCtrlTask",
|
||||
.stack_size = 256 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* Definitions for CmdQueue */
|
||||
osMessageQueueId_t CmdQueueHandle;
|
||||
const osMessageQueueAttr_t CmdQueue_attributes = {
|
||||
.name = "CmdQueue"
|
||||
};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
@@ -73,6 +86,7 @@ PUTCHAR_PROTOTYPE {
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void StartDefaultTask(void *argument);
|
||||
void CarCtrl_Task(void *argument);
|
||||
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
|
||||
@@ -103,6 +117,10 @@ void MX_FREERTOS_Init(void) {
|
||||
/* start timers, add new ones, ... */
|
||||
/* USER CODE END RTOS_TIMERS */
|
||||
|
||||
/* Create the queue(s) */
|
||||
/* creation of CmdQueue */
|
||||
CmdQueueHandle = osMessageQueueNew (16, 16, &CmdQueue_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
@@ -111,6 +129,9 @@ void MX_FREERTOS_Init(void) {
|
||||
/* creation of initTask */
|
||||
initTaskHandle = osThreadNew(StartDefaultTask, NULL, &initTask_attributes);
|
||||
|
||||
/* creation of CarCtrlTask */
|
||||
CarCtrlTaskHandle = osThreadNew(CarCtrl_Task, NULL, &CarCtrlTask_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
@@ -134,24 +155,35 @@ void StartDefaultTask(void *argument)
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
const char *message = "Hello, ESP12F! This is a test message.";
|
||||
HAL_StatusTypeDef status = ESP12F_TCP_SendMessage(message);
|
||||
if (status == HAL_OK) {
|
||||
HAL_GPIO_WritePin(RUN_LED_GPIO_Port, RUN_LED_Pin, GPIO_PIN_SET);
|
||||
BEEP_On();
|
||||
osDelay(50);
|
||||
BEEP_Off();
|
||||
osDelay(20);
|
||||
|
||||
} else {
|
||||
HAL_GPIO_WritePin(RUN_LED_GPIO_Port, RUN_LED_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||
|
||||
osDelay(1000);
|
||||
|
||||
}
|
||||
/* USER CODE END StartDefaultTask */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_CarCtrl_Task */
|
||||
/**
|
||||
* @brief Function implementing the CarCtrlTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_CarCtrl_Task */
|
||||
__weak void CarCtrl_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN CarCtrl_Task */
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
|
||||
osDelay(1); // osMessageQueueGet 已经是阻塞的,不需要额外的 osDelay
|
||||
}
|
||||
/* USER CODE END CarCtrl_Task */
|
||||
}
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user