Browse Source

uart改动测试,测试完成,还需优化

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
e3ba22f5c2
7 changed files with 145 additions and 412 deletions
  1. 1 1
      inc/AppConfig.h
  2. 2 10
      inc/AppTaskUart.h
  3. 6 1
      inc/hal_module_adapter.h
  4. 5 3
      src/AppTaskTcp.c
  5. 111 379
      src/AppTaskUart.c
  6. 1 1
      src/app.c
  7. 19 17
      src/hal_module_adapter.c

+ 1 - 1
inc/AppConfig.h

@@ -11,7 +11,7 @@
 #define BMS_MANUFACTURE             (2)                 //BMS制造商表示1-超力源,2-美顺
 #define BMS_INFO                    (1)                 //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
 #define DATA_MODULE_TYPE            (1)                 //1表示NB模块,2表示4G cat1
-#define EOLSTATE                    (0)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
+#define EOLSTATE                    (1)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
 #define DEFAULT_SN                  "RLTEST00000000002" //默认上传的SN编码
 #define	APPSWVERSION		        0x0300000A          //数据模块软件版本号
 

+ 2 - 10
inc/AppTaskUart.h

@@ -28,7 +28,7 @@
 #include <stdlib.h>
 #include "numeric.h"
 #include "AppSignal.h"
-
+#include "hal_uart.h"
 #define  PROC_UART_TASK_STACK_SIZE (2048)
 
 #define BMS_ADDRESS_CODE    0x01
@@ -47,13 +47,6 @@ typedef enum
     PROCESS_UART_STATE_UPDATE,
     PROCESS_UART_STATE_SLEEP
 }process_Uart;
-typedef struct _UartAnswerData
-{
-	volatile BOOL UartFlag;
-    UINT8 Header[3];
-    UINT8 data[200];
-    UINT16 len;
-}UartAnswerData_S;
 typedef struct _UartQueryType
 {
     UINT8 Bms_Address; 
@@ -151,7 +144,6 @@ void AppTaskUartDeInit(void *arg);
 //BMS升级函数声明
 UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);
 void SP_BMS_Update_Service();
-UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
 updateBMSStatus MS_BMS_Update_Service();
 UINT16 MS_BMS_Update_CRC16(UINT8* pSendData,UINT16 len);
-UINT8 MS_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
+UINT8 UartAppTrasmit(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);

+ 6 - 1
inc/hal_module_adapter.h

@@ -71,7 +71,12 @@ typedef struct
     UINT32 request;
     UINT32 param[7];
 }adcReqMsg;
-
+typedef struct _UartBuffer
+{
+	UINT8 header[3];
+    UINT8 data[200];
+    UINT32 len;
+}UartBuffer;
 typedef struct
 {
     void * dataPtr;

+ 5 - 3
src/AppTaskTcp.c

@@ -743,15 +743,16 @@ static void TcpDataInfoRecvHandle()
                         if(*(Ptr+31)==0x01)//0x01代表锁定
                         {
                             AppDataInfo.appDataModify = TRUE;
-                            AppDataInfo.BattLock = TRUE;
+                            AppDataInfo.UserLock = TRUE;
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
                         else if(*(Ptr+31)==0x02)              //0x02代表解锁
                         {
                             AppDataInfo.appDataModify = TRUE;
-                            AppDataInfo.BattLock = FALSE;
+                            AppDataInfo.UserLock = FALSE;
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
+
                     }
                     else if(*(Ptr+30)==0x8A)//继电器控制
                     {
@@ -793,7 +794,8 @@ static void TcpDataInfoRecvHandle()
                         {
                             BuzzerControl = FALSE;
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
-                        }   
+                        }
+                        BattLockFunc();   
                     }
                     else if(*(Ptr+30)==0x85)//租期设置
                     {

+ 111 - 379
src/AppTaskUart.c

@@ -10,22 +10,16 @@
 
 #include "AppTaskUart.h"
 
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-volatile BOOL isRecvTimeout = false;
-volatile BOOL isRecvComplete = false;
+extern QueueHandle_t uartDataHandle;
 static StaticTask_t             gProcess_Uart_Task_t;
 static UINT8                  gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
 static osThreadId_t           UartTaskId = NULL;
 static process_Uart             gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
 #define PROC_UART_STATE_SWITCH(a)  (gProcess_Uart_Task = a)
-
 static UINT8 Uart_WriteCmd_func(UartWriteData_S UartWriteData);
-void USART_callback(uint32_t event);
 static UINT16 crc_chk(UINT8* data, UINT8 length);
 UINT8 Uart_Encrypt_Send(void);
-void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle,UartWriteData_S UartWriteData,UartAnswerData_S UartAnswerData);
-static UINT8 Uart_DataRecv_func(UartQueryType Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun);
+void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle,UartBuffer UartAnswerData);
 static void UartTask(void* arg)
 {
 
@@ -34,10 +28,9 @@ static void UartTask(void* arg)
     UINT8   UartRecvFlagCounter = 0;
     UartQueryType Uart_Read_Msg;//发送结构体初始化
     memset(&(Uart_Read_Msg),0x00,sizeof(Uart_Read_Msg));
-    UartAnswerData_S UartAnswerData;//应答数据初始化
-	memset(&(UartAnswerData),0x00,sizeof(UartAnswerData_S));
-	UartWriteData_S  UartWriteData;
-	memset(&(UartWriteData),0x00,sizeof(UartWriteData_S));//Uart控制命令初始化
+    UartBuffer UartAnswerData;//应答数据初始化
+	memset(&(UartAnswerData),0x00,sizeof(UartBuffer));
+	UartWriteData_S  UartWriteDataHandleRecv;
     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_INTI);
 	UINT8 ret = 0x00;
 	if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
@@ -50,13 +43,6 @@ static void UartTask(void* arg)
         {
 			case PROCESS_UART_STATE_INTI:
 			{
-				USARTdrv->Initialize(USART_callback);
-				USARTdrv->PowerControl(ARM_POWER_FULL);
-				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-								ARM_USART_DATA_BITS_8 |
-								ARM_USART_PARITY_NONE |
-								ARM_USART_STOP_BITS_1 |
-								ARM_USART_FLOW_CONTROL_NONE, 9600);
 				PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_ENCRYPT);
 				break;
 			}
@@ -75,13 +61,15 @@ static void UartTask(void* arg)
             case PROCESS_UART_STATE_IDLE:
             {
                 osDelay(100);
-				Uart_Cmd_Control(UartWriteCmdHandle,UartWriteData,UartAnswerData);//电池锁定,继电器锁定,加热控制
+				Uart_Cmd_Control(UartWriteCmdHandle,UartAnswerData);//电池锁定,继电器锁定,加热控制
                 if(TimeCounter%10==0 && gProcess_app==WORK)
                 {
 					#ifdef USING_PRINTF1
 						printf("Uart work begin:%02x\n",PadInterrupt);
 					#endif
-                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK&&UartRecvFlag==1)
+					ECOMM_TRACE(UNILOG_PLA_APP, UartAppTask_83, P_SIG, 0,"Uart work begin:%02x",PadInterrupt);
+					memset(&(UartWriteDataHandleRecv),0x00,sizeof(UartWriteDataHandleRecv));
+                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteDataHandleRecv,0,10)==osOK&&UartRecvFlag==1)
                     {
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
                         break;
@@ -117,12 +105,12 @@ static void UartTask(void* arg)
                 Uart_Read_Msg.Reg_Begin_L = 0x00;
                 Uart_Read_Msg.Reg_Num_H   = Reg_Num>>8;
                 Uart_Read_Msg.Reg_Num_L   = Reg_Num;
-                memset(&(UartAnswerData),0x00,sizeof(UartAnswerData_S));
+                memset((UINT8 *)&(UartAnswerData),0x00,sizeof(UartBuffer));
 				CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Read_Msg,6);
 				Uart_Read_Msg.CRC_L = CRC_chk_buffer;
 				Uart_Read_Msg.CRC_H = CRC_chk_buffer>>8;
-				Uart_Recv_LEN = Uart_DataRecv_func(Uart_Read_Msg,(UINT8*)(UartAnswerData.Header));
-                #ifdef USING_PRINTF1
+				Uart_Recv_LEN = UartAppTrasmit((UINT8 *)&Uart_Read_Msg,sizeof(Uart_Read_Msg),(UINT8 *)&UartAnswerData,Reg_Num*2 + 5,1000);
+                #ifdef USING_PRINTF
 					printf("[%d]Uart_Recv_buffer-%d: ",__LINE__,Uart_Recv_LEN);
                 #endif
 				#ifdef USING_PRINTF1
@@ -138,23 +126,21 @@ static void UartTask(void* arg)
 					UartErrorFlag = 0;
 					UartRecvFlagCounter = 0;
                     UartRecvFlag = 1;
-                    UartAnswerData.len = Uart_Recv_LEN;
                     uartBattInfoDecode(UartAnswerData.data);
 					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
 					break;
                 }
                 else if(Uart_Recv_LEN==1)//接收的数据校验不过
                 {
-					osDelay(100);
                     UartRecvFlagCounter++;
                 }
 				else//没有接收到数据
 				{
-					osDelay(100);
                     UartRecvFlagCounter++;
 				}
 				if(UartRecvFlagCounter>=10)
 				{
+					UartRecvFlagCounter = 0;
 					uartBattInfoDecode(UartAnswerData.data);
 					UartRecvFlag = 0;
 					UartErrorFlag = 1;
@@ -165,7 +151,7 @@ static void UartTask(void* arg)
             }
             case PROCESS_UART_STATE_WRITE:
             {
-                UartCmdRecvFlag = Uart_WriteCmd_func(UartWriteData);
+                UartCmdRecvFlag = Uart_WriteCmd_func(UartWriteDataHandleRecv);
 				osDelay(500);
                 PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
                 break;
@@ -190,7 +176,6 @@ static void UartTask(void* arg)
                     printf("Uart silence begin\n");
                 #endif
                 UartRecvFlag = 0;
-				USARTdrv->PowerControl(ARM_POWER_LOW);
                 while (true)
                 {
                     osDelay(100);
@@ -215,211 +200,133 @@ static UINT8 Uart_WriteCmd_func(UartWriteData_S UartWriteData)
 {
     UartWriteMsgType Uart_Write_Msg;
     UINT16 RegAddress = 0x0000;
-    UINT16 CRC_chk_buffer;
-    UINT8 timeout = 0x00;
-    UINT8 Uart_Recv_Buffer[8];
+    UINT16 CRC_chk_buffer,Uart_Recv_LEN=0;
+    UINT8 Uart_Recv_Buffer[16]={0};
     switch (UartWriteData.WriteCmd)
     {
         case 0x01://是否锁定
         {   
             RegAddress = 0x1B + AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP;
-            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
-            Uart_Write_Msg.Reg_Begin_L = RegAddress;
-            Uart_Write_Msg.Reg_Num_H = 0x00;
-            Uart_Write_Msg.Reg_Num_L = 0x01;
-            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
-            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
-            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
-            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
             break;
         }
 		case 0x02://是否加热
 		{
 			RegAddress = 0x1C + AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP;
-            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
-            Uart_Write_Msg.Reg_Begin_L = RegAddress;
-            Uart_Write_Msg.Reg_Num_H = 0x00;
-            Uart_Write_Msg.Reg_Num_L = 0x01;
-            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
-            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
-            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
-            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
             break;
 		}
 		case 0x04://是否继电器控制
 		{
 			RegAddress = 0x1B + AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP;
-            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
-            Uart_Write_Msg.Reg_Begin_L = RegAddress;
-            Uart_Write_Msg.Reg_Num_H = 0x00;
-            Uart_Write_Msg.Reg_Num_L = 0x01;
-            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
-            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
-            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
-            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
             break;
 		}
         default:
         {
             UartWriteData.WriteCmd = 0x00;
             return 0;
-            break;
         }
     }
-    USARTdrv->Send((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg));
-    #ifdef USING_PRINTF1
-        printf("Uart_Send_buffer:  ");
-        for(int i=0;i<sizeof(Uart_Write_Msg);i++)
-        {
-            printf("%x ",*((UINT8 *)&Uart_Write_Msg+i));
-        }
-        printf("\n");
-    #endif
-    USARTdrv->Receive(Uart_Recv_Buffer,8);
-    while((isRecvTimeout == false) && (isRecvComplete == false))
-    {
-        timeout++;
-        osDelay(100);
-        if (timeout>=10)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        #ifdef USING_PRINTF1
-            printf("Uart_Rece_buffer: ");
-            for(int i=0;i<8;i++)
-            {
-            printf("%x ",Uart_Recv_Buffer[i]);
-            }
-            printf("\n");
-        #endif
-        isRecvComplete = false;
-        if(Uart_Recv_Buffer[1]==0x10)
-        {
-            return UartWriteData.WriteCmd;
-        }
-        else
-        {
-            return 0x00;
-        }
-    }
-    else
-    {
-        isRecvTimeout = false;
-        return 0x00;
-    }
+	Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
+	Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
+	Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
+	Uart_Write_Msg.Reg_Begin_L = RegAddress;
+	Uart_Write_Msg.Reg_Num_H = 0x00;
+	Uart_Write_Msg.Reg_Num_L = 0x01;
+	Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
+	memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
+	CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
+	Uart_Write_Msg.CRC_L = CRC_chk_buffer;
+	Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
+	Uart_Recv_LEN = UartAppTrasmit((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg),(UINT8 *)&Uart_Recv_Buffer,8,1000);
+	if(Uart_Recv_Buffer[1] == 0x10)
+	{
+		return UartWriteData.WriteCmd;
+	}
+	else
+	{
+		return 0;
+	}
+
 }
-void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle,UartWriteData_S UartWriteData,UartAnswerData_S UartAnswerData)
+void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle,UartBuffer UartAnswerData)
 {
+	UartWriteData_S UartWriteData;
+	memset(&(UartWriteData),0x00,sizeof(UartWriteData_S));//Uart控制命令初始化
 	UINT8 HeatSwitch = 0;
 	if(TimeCounter%10==0 && BattHeaterSwitch(&HeatSwitch,HeatForceControl)==TRUE)
 	{
 		UartWriteData.WriteCmd = 0x02;
 		UartWriteData.Data[0] = 0x00;
 		UartWriteData.Data[1] = HeatSwitch&0xFF;
-		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,10);
 	}
 	if(battWorkState ==0x00 && AppDataInfo.BattLock==TRUE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x01)!=0x00)//try to lock lock the discharge 
 	{
 		UartWriteData.WriteCmd = 0x01;
 		UartWriteData.Data[0] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2]);
 		UartWriteData.Data[1] = 0x02;
-		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,10);
 	}
 	else if (battWorkState ==0x00 && AppDataInfo.BattLock==FALSE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x01)!=0x01 ) // try to unlock
 	{
 		UartWriteData.WriteCmd = 0x01;
 		UartWriteData.Data[0] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2]);
 		UartWriteData.Data[1] = 0x03;
-		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,10);
 	}
 	if(AppDataInfo.RelayControl==TRUE && getbit((UartAnswerData.data[(0x09+AppNVMData.BattCellCount+AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]),0)==0x00)//继电器断开
 	{
 		UartWriteData.WriteCmd = 0x04;
 		UartWriteData.Data[0] = 0x80;
 		UartWriteData.Data[1] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]);
-		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,10);
 	}
 	else if(AppDataInfo.RelayControl==FALSE && getbit((UartAnswerData.data[(0x09+AppNVMData.BattCellCount+AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]),0)==0x01)//继电器闭合
 	{
 		UartWriteData.WriteCmd = 0x04;
 		UartWriteData.Data[0] = 0x00;
 		UartWriteData.Data[1] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]);
-		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,10);
 	}
 }
-//Uart发送接收函数
-static UINT8 Uart_DataRecv_func(UartQueryType Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun)
+UINT8 UartAppTrasmit(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout)
 {
-    UINT16 CRC_Rece_buffer = 0x00;
-    UINT16 CRC_chk_buffer = 0xff;
-    UINT16 Data_Len = 0 ;
-    UINT8 timeout = 0x00;
-	UINT8 pSendCmd[8];
-	memcpy(pSendCmd,(UINT8*)(&Uart_Read_Msg_Fun),8);
-	Data_Len  = ((Uart_Read_Msg_Fun.Reg_Num_H<<8)|(Uart_Read_Msg_Fun.Reg_Num_L))*2+5;
-	USARTdrv->Send(pSendCmd,8);
-    USARTdrv->Receive(Uart_Recv_Buffer_Fun,Data_Len);
-	while(true)
-    {
-        timeout++;
-        if((isRecvTimeout == true) || (isRecvComplete == true))
-        {
-            break;
-        }
-        else
-        {
-            osDelay(100);
-            if (timeout>=10)
-            {
-                timeout =0;
-                isRecvTimeout = true;
-            }
-        } 
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_Rece_buffer =*(Uart_Recv_Buffer_Fun+Data_Len-1)<<8|*(Uart_Recv_Buffer_Fun+Data_Len-2);
-        CRC_chk_buffer = crc_chk(Uart_Recv_Buffer_Fun,Data_Len-2);
-	    #ifdef USING_PRINTF1
-	         printf("Uart_Rece_buffer after Crc: ");
-	         for(int i=0;i<Data_Len;i++)
-	         {
-	         	printf("%x ",*(Uart_Recv_Buffer_Fun+i));
-	   	     }
-	         printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
-	    #endif
-        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
-        {
-            return Data_Len;
-        }
-        else //接收数据的校验不过
-        {
-            memset(Uart_Recv_Buffer_Fun,0x00,Data_Len);
-            return 1;
-        }
-    }
-    else
-    {
-        memset(Uart_Recv_Buffer_Fun,0x00,Data_Len);
-        isRecvTimeout = false;
-        return 2;
-    }
-	return 0;
+	UINT16 CRC_Rece_buffer = 0x00;
+	UINT16 CRC_chk_buffer = 0xff;
+	HAL_UART_SendStr(PORT_USART_1,pSend,sendLen);
+	if(readLen>0)
+	{
+		UartBuffer UartData;
+		osStatus_t ret = osMessageQueueGet(uartDataHandle, &UartData, 0, timeout);    	
+		if (ret == osOK)
+		{
+			memcpy(pRead,(UINT8 *)&UartData,UartData.len);
+			CRC_Rece_buffer =*(pRead+UartData.len-1)<<8|*(pRead+UartData.len-2);
+        	CRC_chk_buffer = crc_chk(pRead,UartData.len-2);
+			if(*(pRead+0)!=0x01||CRC_Rece_buffer!=CRC_chk_buffer)
+			{
+				hal_uart_hardware_config_t hwConfig = {
+	                                        ARM_POWER_FULL,
+	                                        ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
+	                                        ARM_USART_PARITY_NONE       | ARM_USART_STOP_BITS_1 |
+	                                        ARM_USART_FLOW_CONTROL_NONE,
+	                                        9600U
+	                                       };
+				HAL_UART_ResetUartSetting(PORT_USART_1, &hwConfig, TRUE);
+				memset(pRead,0x00,readLen);
+				return  0;
+			}
+			return UartData.len;
+		}
+		else
+		{
+			memset(pRead,0x00,readLen);
+			return 0;
+		}
+	}
+	else
+	{
+		return 1;
+	}
 }
 UINT8 Uart_Encrypt_Send()
 {
@@ -428,7 +335,6 @@ UINT8 Uart_Encrypt_Send()
 	UINT8 UartEncryptBuffer[17];
 	UINT8 UartDecryptBuffer[5];
 	UINT16 CRC_chk_buffer;
-	UINT8 timeCount = 0;
 	UartEncryptBuffer[0] = BMS_ADDRESS_CODE;
 	UartEncryptBuffer[1] = UART_ENCRYPT_CODE;
 	UartEncryptBuffer[2] = 0x0c;
@@ -443,47 +349,8 @@ UINT8 Uart_Encrypt_Send()
 	CRC_chk_buffer = crc_chk(UartEncryptBuffer,17-2);
 	UartEncryptBuffer[15] = CRC_chk_buffer;
 	UartEncryptBuffer[16] = CRC_chk_buffer>>8;
-	USARTdrv->Send(UartEncryptBuffer,17);
-	USARTdrv->Receive(UartDecryptBuffer,5); 
-	while((isRecvTimeout == false) && (isRecvComplete == false))
-	{
-		timeCount++;
-		osDelay(100);
-		if (timeCount>=10)
-		{
-			timeCount =0;
-			isRecvTimeout = true;
-			break;
-		}
-	}
-	#ifdef USING_PRINTF1
-		printf("[%d]Uart_Encrypt_Recv: ",__LINE__);
-		for(int i=0;i<5;i++)
-		{
-		printf("%x ",UartDecryptBuffer[i]);
-		}
-    #endif	
-	if (isRecvComplete == true)
-	{
-		isRecvComplete = false;
-		return UartDecryptBuffer[2];
-	}
-	else
-	{
-		isRecvTimeout = false;
-		return 0x03;
-	}
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
+	UartAppTrasmit(UartEncryptBuffer,17,(UINT8 *)&UartDecryptBuffer,5,1000);
+	return UartDecryptBuffer[2];
 }
 static UINT16 crc_chk(UINT8* data, UINT8 length)
 {  
@@ -508,6 +375,13 @@ static UINT16 crc_chk(UINT8* data, UINT8 length)
 }
 void AppTaskUartInit(void *arg)
 {
+	if(uartDataHandle == NULL)
+	{
+		uartDataHandle = osMessageQueueNew(1,sizeof(UartBuffer), NULL);
+		if(uartDataHandle == NULL)
+			return;
+	}
+	Usart1Handler(9600U);
     osThreadAttr_t task_attr;
     memset(&task_attr,0,sizeof(task_attr));
     memset(gProcess_Uart_TaskStack, 0xA5, PROC_UART_TASK_STACK_SIZE);
@@ -564,7 +438,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xF5;	//end flag		
 				//printf("updateMsgSendLen0 = %x\n",updateMsgSendLen);
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 500);
 				//printf("updateMsgSendLen1 = %x\n",updateMsgSendLen);
 				if(ret!=0)
 				{
@@ -634,7 +508,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xA6;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -702,7 +576,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xD9;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				//updateStep = UPDATE_STEP_SET_BAUD_RATE;
 				updateStep = UPDATE_STEP_CHECK_VERSION_AGAIN;//2021-04-09跳过波特率设置
 				#ifdef USING_PRINTF1
@@ -734,7 +608,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xF5;	//end flag		
 				//printf("updateMsgSendLen0 = %x\n",updateMsgSendLen);
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 100);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 100);
 				//printf("updateMsgSendLen1 = %x\n",updateMsgSendLen);
 				if(ret!=0)
 				{
@@ -816,7 +690,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				printf("\n");
 				#endif
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				printf("ret = %d\n",ret);
 				if(ret!=0)
 				{
@@ -887,7 +761,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xC9;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -961,7 +835,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[10] = 0xF5;	//end flag
 				
 				memset((UINT8*)(&pUpdateMsgRecv),0,sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -1029,7 +903,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xDA;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen,(UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen,(UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -1105,7 +979,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					pUpdateMsgSend[8+dataLen+1] = SP_BMS_Update_CheckSUM(&pUpdateMsgSend[3], dataLen+6);  //check sum
 					pUpdateMsgSend[8+dataLen+2] = 0xF5;	//end flag
 					memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-					ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+					ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 					if(ret!=0)
 					{
 						if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -1177,7 +1051,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0xEB;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
+				ret = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -1245,7 +1119,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0x1E;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
+				UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				
 				updateStep = UPDATE_STEP_END;
 				
@@ -1283,7 +1157,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0x2F;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
+				UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				osDelay(50);
 				
 				resetCount++;
@@ -1312,7 +1186,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[6] = 0x40;	//check
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
+				UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				osDelay(50);
 				updateStep = UPDATE_STEP_CHECK_VERSION;
 				Cycle_conut++;
@@ -1331,76 +1205,6 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 		}
 	}
 }
-
-UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout)
-{
-
-	UINT8 timeCount = 0;
-	UINT8 j=0;
-	USARTdrv->Send(pSend,sendLen);
-	#ifdef USING_PRINTF1
-		printf("query in:");
-		for(j=0;j<sendLen;j++)
-		{
-			printf("%x ",*(pSend+j));
-		}
-		printf("\n");	
-	#endif
-	if(readLen>0)
-	{
-		USARTdrv->Receive(pRead,readLen);         
-		while((isRecvTimeout == false) && (isRecvComplete == false))
-		{
-			timeCount++;
-			osDelay(100);
-			if (timeCount>=timeout/100)
-			{
-				timeCount =0;
-				isRecvTimeout = true;
-				break;
-			}
-		}
-		#ifdef USING_PRINTF1
-			printf("\nanswer in:");
-			for(j=0;j<readLen;j++)
-			{
-				printf("%x ",*(pRead+j));
-			}
-			printf("\n");
-		#endif	
-		if (isRecvComplete == true)
-		{
-			isRecvComplete = false;
-			if(*(pRead+0)!=0xEB)
-			{
-				USARTdrv->Uninitialize();
-				osDelay(100);
-				USARTdrv->Initialize(USART_callback);
-				USARTdrv->PowerControl(ARM_POWER_FULL);
-				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-						ARM_USART_DATA_BITS_8 |
-						ARM_USART_PARITY_NONE |
-						ARM_USART_STOP_BITS_1 |
-						ARM_USART_FLOW_CONTROL_NONE, 9600);
-				#ifdef USING_PRINTF
-					printf("\nuart reset in \n");	
-				#endif
-				return  0;
-			}
-			return readLen;
-		}
-		else
-		{
-			memset(pRead,0x00,readLen);
-			isRecvTimeout = false;
-			return 0;
-		}
-	}
-	else
-	{
-			return 1;
-	}
-}
 UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len)
 {
 	UINT8 ret = 0;
@@ -1516,7 +1320,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step 1 answer,updateMsgReadLen = %x:\n",updateMsgReadLen);
 				
@@ -1616,7 +1420,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step 3 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
@@ -1699,7 +1503,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step 5 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
@@ -1799,7 +1603,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 					pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 					
 					memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-					ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+					ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 					#ifdef USING_PRINTF
 						printf("update step 7 answer:\n");
 					 for(ii=0;ii<updateMsgReadLen;ii++)
@@ -1883,7 +1687,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step 9 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
@@ -1946,7 +1750,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				ret0 = UartAppTrasmit(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step A answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
@@ -2019,78 +1823,6 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 	return ret;
 
 }
-UINT8 MS_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout)
-{
-
-	UINT8 timeCount = 0;
-	UINT8 j=0;
-	USARTdrv->Send(pSend,sendLen);
-	#ifdef USING_PRINTF1
-		printf("query in:");
-		for(j=0;j<sendLen;j++)
-		{
-			printf("%x ",*(pSend+j));
-		}
-		printf("\n");	
-	#endif
-	if(readLen>0)
-	{
-		USARTdrv->Receive(pRead,readLen);         
-		while((isRecvTimeout == false) && (isRecvComplete == false))
-		{
-			timeCount++;
-			osDelay(100);
-			if (timeCount>=timeout/100)
-			{
-				timeCount =0;
-				isRecvTimeout = true;
-				break;
-			}
-		}
-		#ifdef USING_PRINTF1
-			printf("\nanswer in:");
-			for(j=0;j<readLen;j++)
-			{
-				printf("%x ",*(pRead+j));
-			}
-			printf("\n");
-		#endif	
-		if (isRecvComplete == true)
-		{
-			isRecvComplete = false;
-			if(*(pRead+0)!=0x01)
-			{
-				USARTdrv->Uninitialize();
-				osDelay(100);
-				USARTdrv->Initialize(USART_callback);
-				USARTdrv->PowerControl(ARM_POWER_FULL);
-				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-						ARM_USART_DATA_BITS_8 |
-						ARM_USART_PARITY_NONE |
-						ARM_USART_STOP_BITS_1 |
-						ARM_USART_FLOW_CONTROL_NONE, 9600);
-				#ifdef USING_PRINTF
-					printf("\nuart reset in \n");	
-				#endif
-				return  0;
-			}
-			return readLen;
-		}
-		else
-		{
-			memset(pRead,0x00,readLen);
-			isRecvTimeout = false;
-			return 0;
-		}
-	}
-	else
-	{
-			return 1;
-	}
-}
-
-
-
 static void __invert_uint8(UINT8* dBuf, UINT8* srcBuf)
 {
 	 int i;

+ 1 - 1
src/app.c

@@ -10,7 +10,7 @@
 void appInit(void *arg)
 {
     AppTaskMainInit(arg);
-    AppTaskTcpInit(arg);
+    //AppTaskTcpInit(arg);
     AppTaskControlInit(arg);
     AdcTaskInit();
     AppTaskGpsInit(arg);

+ 19 - 17
src/hal_module_adapter.c

@@ -100,7 +100,7 @@ static osThreadId_t adcTaskHandle = NULL;
 static StaticTask_t adcTask = NULL;
 static UINT8 adcTaskStack[ADC_TASK_STACK_SIZE];
 
-
+QueueHandle_t uartDataHandle = NULL;
 /*
 	gps
 */
@@ -1587,10 +1587,9 @@ void PrintfSendStr(const UINT8 *format, ...)
 	vsnprintf(buf+strlen(buf), 128-strlen(buf), format, args);
 	va_end(args);
 	HAL_UART_SendStr(PORT_USART_1,buf,strlen(buf));
-
 }
 
-#define PRINTF_DATA_RECV_BUFFER_SIZE     						(64)
+#define PRINTF_DATA_RECV_BUFFER_SIZE     						(200)
 uint8_t printf_uart_recv_buf[PRINTF_DATA_RECV_BUFFER_SIZE];
 /**
   \fn    void PrintfDataRecvCallback(uint32_t event, void* dataPtr, uint32_t dataLen)
@@ -1600,10 +1599,19 @@ uint8_t printf_uart_recv_buf[PRINTF_DATA_RECV_BUFFER_SIZE];
   \brief        i2c irq event ,callback function
   \return      
 */
-void PrintfDataRecvCallback(UINT32 event, void* dataPtr, UINT32 dataLen)
-{
-	//ECOMM_TRACE(UNILOG_PLA_APP, PrintfDataRecvCallback, P_SIG, 3, "event=%d, dataPtr=%s, dataLen=%d",event,dataPtr,dataLen);
-    slpManStartWaitATTimer(); 
+void UartDataRecvCallback(UINT32 event, void* dataPtr, UINT32 dataLen)
+{	
+	if((event == ARM_USART_EVENT_RX_TIMEOUT) || (event == ARM_USART_EVENT_RECEIVE_COMPLETE))
+	{
+		if(uartDataHandle!=NULL && dataLen>0)
+		{
+			UartBuffer UartDataBuffer={0};
+			memcpy((UINT8 *)&UartDataBuffer,dataPtr,dataLen);
+			UartDataBuffer.len = dataLen;
+			osMessageQueuePut(uartDataHandle, &UartDataBuffer, 0, 10);
+		}
+   }
+   slpManStartWaitATTimer(); 
 }
 
 void printfPostSendCallback(hal_uart_send_msg_type_t msgType, void* dataPtr, uint32_t dataLen){
@@ -1627,20 +1635,14 @@ void Usart1Handler(UINT32 baudRate)
 	                                        ARM_USART_FLOW_CONTROL_NONE,
 	                                        baudRate
 	                                       };
-
-
-
 	halUartConfig.uartDriverHandler = printfHandle;
-	halUartConfig.recv_cb = PrintfDataRecvCallback;
+	halUartConfig.recv_cb = UartDataRecvCallback;
 	halUartConfig.recvBuffPtr = printf_uart_recv_buf;
 	halUartConfig.recvBuffSize = PRINTF_DATA_RECV_BUFFER_SIZE;
-       halUartConfig.post_send_cb = printfPostSendCallback;
+    halUartConfig.post_send_cb = printfPostSendCallback;
 	HAL_UART_InitHandler(PORT_USART_1, &halUartConfig, &hwConfig, HAL_UART_TASK_CREATE_FLAG_SEND_RECV);
 	HAL_UART_RecvFlowControl(false);
 }
-
-
-
 /**
   \fn         void GsensorI2CCallback(uint32_t event)
   \param[in]  event   : i2c irq event
@@ -1687,7 +1689,7 @@ void GpsDataRecvCallback(UINT32 event, void* dataPtr, UINT32 dataLen)
 {
    if((event == ARM_USART_EVENT_RX_TIMEOUT) || (event == ARM_USART_EVENT_RECEIVE_COMPLETE)){
 	    #ifdef USING_PRINTF	
-	    //	//printf("GpsDataRecvCallback [%d] %s\r\n",dataLen,dataPtr);
+	    	//printf("GpsDataRecvCallback [%d] %s\r\n",dataLen,dataPtr);
 	    #endif 
 		if(gpsHandle!=NULL && dataLen>0){
 			gpsReqMsg gpsInfo;
@@ -1695,7 +1697,7 @@ void GpsDataRecvCallback(UINT32 event, void* dataPtr, UINT32 dataLen)
 			if(gpsInfo.dataPtr){
 				memcpy(gpsInfo.dataPtr,dataPtr,dataLen);	
 				gpsInfo.len=dataLen;
-				osMessageQueuePut(gpsHandle, &gpsInfo, 0, 2000);
+				osMessageQueuePut(gpsHandle, &gpsInfo, 0,60000U);
 			}
 		}
    }