Browse Source

打印引起的Uart重启问题,未解决!!!!!!!!!!先跳过

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
8c835f722d
1 changed files with 33 additions and 12 deletions
  1. 33 12
      src/UartTask.c

+ 33 - 12
src/UartTask.c

@@ -93,7 +93,6 @@ static void UartTask(void* arg)
 	BOOL uartReadSuccessFlag = false;
     Uart_Read_Msg_Type Uart_Read_Msg;
     Uart_Write_Data_Type UartWriteData; //Uart控制命令
-	UINT8 *Uart_Buffer_Ptr;
     if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
 	{
 		UartWriteCmdHandle = osMessageQueueNew(3,sizeof(Uart_Write_Data_Type), NULL);
@@ -180,6 +179,7 @@ static void UartTask(void* arg)
             }
             case PROCESS_UART_STATE_READ:
             {
+				osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
                 Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
@@ -188,13 +188,8 @@ static void UartTask(void* arg)
                 Uart_Read_Msg.Reg_Num_H = Reg_Num>>8;
                 Uart_Read_Msg.Reg_Num_L = Reg_Num;
                 Uart_Uds_LEN = Reg_Num*2;
-				Uart_Buffer_Ptr = malloc(Uart_Uds_LEN);
-                memset(Uart_Buffer_Ptr,0x00,Uart_Uds_LEN);
-                Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,Uart_Buffer_Ptr);
-				osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
-				memcpy(UartReadMsg.Header,Uart_Buffer_Ptr,Uart_Uds_LEN);
+                Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
 				osMutexRelease(UartMutex);
-				free(Uart_Buffer_Ptr);
 				if(Uart_Recv_LEN>0)
 				{
 					UartReadMsg.UartFlag = TRUE;
@@ -401,17 +396,43 @@ UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
         printf("\n");
     #endif
     USARTdrv->Receive(Uart_Recv_Buffer,Data_Len);
-    while((isRecvTimeout == false) && (isRecvComplete == false))
+    // while((isRecvTimeout == false) && (isRecvComplete == false))
+    // {
+    //     timeout++;
+    //     osDelay(100);
+    //     if (timeout>=50)
+    //     {
+    //         timeout =0;
+    //         isRecvTimeout = true;
+    //         break;
+    //     }
+    // }
+	while(true)
     {
+        
         timeout++;
-        osDelay(100);
-        if (timeout>=50)
+
+        if((isRecvTimeout == true) || (isRecvComplete == true))
         {
-            timeout =0;
-            isRecvTimeout = true;
             break;
         }
+        else
+        {
+
+            osDelay(100);
+            if (timeout>=50)
+            {
+                timeout =0;
+                isRecvTimeout = true;
+                //break;
+            }
+        }
+            
     }
+	#ifdef USING_PRINTF  
+             printf("%s[%d]\r\n",__FUNCTION__, __LINE__);
+             printf("timeout = %d\n",timeout);
+            #endif
     #ifdef USING_PRINTF1
         printf("Uart_Rece_buffer: ");
         for(int i=0;i<Data_Len;i++)