ソースを参照

CAN_232_串口优化完成

LAPTOP-KB7QFH2U\ChenJie-PC 2 年 前
コミット
bd5e4ad8ec

+ 32 - 29
RTD/src/Lpuart_Uart_Ip.c

@@ -161,7 +161,7 @@ Lpuart_Uart_Ip_StateStructureType Lpuart_Uart_Ip_apStateStructure[LPUART_UART_IP
 #include "Uart_MemMap.h"
 
 /* Pointer to lpuart runtime state structure */
-static Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
+Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
 
 /** @brief User config structure. */
 const Lpuart_Uart_Ip_UserConfigType * Lpuart_Uart_Ip_apUserConfig[LPUART_UART_IP_NUMBER_OF_INSTANCES];
@@ -218,7 +218,6 @@ static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable)
 static void Lpuart_Uart_Ip_PutData(const uint8 Instance);
 static void Lpuart_Uart_Ip_GetData(const uint8 Instance);
 static void Lpuart_Uart_Ip_RxIrqHandler(const uint8 Instance);
-static void Lpuart_Uart_Ip_RxIdleIrqHandler(uint32 Instance);//zhenchao
 static void Lpuart_Uart_Ip_TxEmptyIrqHandler(const uint8 Instance);
 static void Lpuart_Uart_Ip_TxCompleteIrqHandler(const uint8 Instance);
 static void Lpuart_Uart_Ip_ErrIrqHandler(const uint8 Instance);
@@ -1122,6 +1121,34 @@ Lpuart_Uart_Ip_StatusType Lpuart_Uart_Ip_SetRxBuffer(const uint8 Instance,
     return LPUART_UART_IP_STATUS_SUCCESS;
 }
 
+//zhengchao
+static void Lpuart_Uart_Ip_RxIdleIrqHandler(uint32 Instance)
+{
+    Lpuart_Uart_Ip_StateStructureType * UartState;
+    const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
+
+    LPUART_Type * Base;
+
+    Base = Lpuart_Uart_Ip_apBases[Instance];
+
+    UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
+    UartUserCfg = (Lpuart_Uart_Ip_UserConfigType*) Lpuart_Uart_Ip_apUserConfig[Instance];
+
+//    /* Disable receive idle interrupt. */
+//    Lpuart_Uart_Ip_SetIntMode(Base, (uint32)LPUART_CTRL_ILIE_SHIFT, FALSE);
+    /* Clear idle flag*/
+    Base->STAT |= LPUART_STAT_IDLE(0);
+
+    /* Invoke callback if there is one */
+
+    if (UartUserCfg->Callback != NULL_PTR)
+    {
+    	UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RECV_IDLE,UartUserCfg->CallbackParam);
+    }
+    UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
+    
+}
+
 /*FUNCTION**********************************************************************
  *
  * Function Name : Lpuart_Uart_Ip_IrqHandler
@@ -1211,31 +1238,7 @@ void Lpuart_Uart_Ip_IrqHandler(const uint8 Instance)
 		}
     }
 }
-//zhengchao
-static void Lpuart_Uart_Ip_RxIdleIrqHandler(uint32 Instance)
-{
-    Lpuart_Uart_Ip_StateStructureType * UartState;
-    const Lpuart_Uart_Ip_UserConfigType *UartUserCfg;
-
-    LPUART_Type * Base;
-    Base = Lpuart_Uart_Ip_apBases[Instance];
-
-    UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[Instance];
-    UartUserCfg = (Lpuart_Uart_Ip_UserConfigType*) Lpuart_Uart_Ip_apUserConfig[Instance];
 
-    /* Disable receive idle interrupt. */
-    Lpuart_Uart_Ip_SetIntMode(Base, (uint32)LPUART_CTRL_ILIE_SHIFT, FALSE);
-    /* Clear idle flag*/
-    Base->STAT |= LPUART_STAT_IDLE(0);
-
-    /* Invoke callback if there is one */
-    if (UartUserCfg->Callback != NULL_PTR)
-    {
-    	UartUserCfg->Callback(Instance, LPUART_UART_IP_EVENT_RECV_IDLE,UartUserCfg->CallbackParam);
-    }
-    UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
-
-}
 /*FUNCTION**********************************************************************
  *
  * Function Name : Lpuart_Uart_Ip_RxIrqHandler
@@ -1872,7 +1875,7 @@ static void Lpuart_Uart_Ip_CompleteReceiveDataUsingInt(const uint8 Instance)
     /* In Abort case, the transmission need to stop instantly */
     if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
     {
-        Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
+        Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US/10, LPUART_UART_IP_TIMEOUT_TYPE);
         /* Wait until the data is completely received */
         while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
                !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
@@ -1984,7 +1987,7 @@ void Lpuart_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance)
         if (UartState->ReceiveStatus == LPUART_UART_IP_STATUS_ABORTED)
         {
             /* Wait until the last transmission complete */
-            Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US, LPUART_UART_IP_TIMEOUT_TYPE);
+            Lpuart_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LPUART_UART_IP_TIMEOUT_VALUE_US/10, LPUART_UART_IP_TIMEOUT_TYPE);
             while (!Lpuart_Uart_Ip_GetStatusFlag(Base, LPUART_UART_IP_DATA_REG_FULL) && \
                !Lpuart_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LPUART_UART_IP_TIMEOUT_TYPE))
             {}
@@ -2032,7 +2035,7 @@ static void Lpuart_Uart_Ip_SetupIntDmaMode(const uint8 Instance, boolean Enable)
       Base = Lpuart_Uart_Ip_apBases[Instance];
 
       /* Setup error interrupts */
-      Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, Enable);
+      Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_RX_OVERRUN, 0);
       Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_PARITY_ERR_FLAG, Enable);
       Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_NOISE_ERR_FLAG, Enable);
       Lpuart_Uart_Ip_SetIntMode(Base, LPUART_UART_IP_INT_FRAME_ERR_FLAG, Enable);

+ 1 - 1
generate/include/Eep_Cfg.h

@@ -170,7 +170,7 @@ extern "C"{
 #define EEP_COMPARE_API             FTFC_EEP_IP_COMPARE_API
 
 /* Pre-processor switch to enable and disable development error detection */
-#define EEP_DEV_ERROR_DETECT        (STD_ON)
+#define EEP_DEV_ERROR_DETECT        (STD_OFF) //zhengchao 20220421
 
 /* Compile switch to enable and disable the Eep_GetJobResult function */
 #define EEP_GET_JOB_RESULT_API      (STD_ON)

+ 1 - 1
generate/include/Flexio_Uart_Ip_Defines.h

@@ -92,7 +92,7 @@ extern "C"{
 #define FLEXIO_UART_IP_TIMEOUT_TYPE                     (OSIF_COUNTER_SYSTEM)
 
 /* @brief Number of loops before returning FLEXIO_STATUS_TIMEOUT.*/
-#define FLEXIO_UART_IP_TIMEOUT_VALUE_US                 (10000U)
+#define FLEXIO_UART_IP_TIMEOUT_VALUE_US                 (100000U)
 
 /* @brief Support for User mode. If this parameter has been configured to TRUE, the Uart driver can be executed from both supervisor and user mode. */
 #define FLEXIO_UART_IP_ENABLE_USER_MODE_SUPPORT         (STD_OFF)

+ 27 - 12
src/AppTaskBle.c

@@ -36,6 +36,7 @@ void BleTask(void *pvParameters)
 	uint16 ReadLen = 0;
 	uint8 *retptr = NULL;
 	uint8 *pSend = NULL;
+	uint8 *UartRecvPtr=NULL;
 	for (;;)
 	{
 		switch (bleWorkState)
@@ -70,11 +71,11 @@ void BleTask(void *pvParameters)
 					Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD, STD_ON);
 				}
 			}
-			memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
-			UART_Receive_Data(UART_LPUART2, RX_Buffer[UART_LPUART2],&ReadLen, 100);
-			memcpy(AtCmdRead, RX_Buffer[UART_LPUART2], sizeof(AtCmdRead));
+			UART_Receive_Data(UART_LPUART2, &UartRecvPtr,&ReadLen, 100);
 			if (ReadLen>0)//未连接状态下,蓝牙串口处会发送连接状态以及扫描的内容
 			{
+				memset(AtCmdRead,0x00,sizeof(AtCmdRead));
+				memcpy(AtCmdRead, &UartRecvPtr,ReadLen);
 				retptr = (uint8 *)strstr((char *)AtCmdRead, (char *)("STA:connect"));
 				if (retptr)
 				{
@@ -97,6 +98,11 @@ void BleTask(void *pvParameters)
 					xQueueSend(Uart2ToCanDataHandle,&BleAskData,0);
 				}
 			}
+			if(UartRecvPtr != NULL)
+			{
+				free(UartRecvPtr);
+			}
+			UartRecvPtr = NULL;
 			break;
 		}
 		case 1: //已连接
@@ -153,11 +159,11 @@ void BleTask(void *pvParameters)
 					BleAnsData.DataPtr = NULL;
 				}
 			}
-			memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
-			UART_Receive_Data(UART_LPUART2, RX_Buffer[UART_LPUART2],&ReadLen, 100);
-			memcpy(AtCmdRead, RX_Buffer[UART_LPUART2], sizeof(AtCmdRead));
+			UART_Receive_Data(UART_LPUART2, &UartRecvPtr,&ReadLen, 100);
 			if (ReadLen>0)//连接的状态下,蓝牙串口会发送断开状态以及发送的内容
 			{
+				memset(AtCmdRead,0x00,sizeof(AtCmdRead));
+				memcpy(AtCmdRead, UartRecvPtr, ReadLen);
 				uint8 *retptr = NULL;
 				retptr = (uint8 *)strstr((char *)AtCmdRead, (char *)("STA:disconnec"));
 				if(retptr)
@@ -212,6 +218,11 @@ void BleTask(void *pvParameters)
 					}
 				}
 			}
+			if(UartRecvPtr != NULL)
+			{
+				free(UartRecvPtr);
+			}
+			UartRecvPtr = NULL;
 			break;
 		}
 		default:
@@ -222,6 +233,7 @@ void BleTask(void *pvParameters)
 }
 static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, uint8 *CmdRead, sint8 *retFunc)
 {
+	uint8 *UartRecvPtr = NULL;
 	uint16 ReadLen = 0;
 	uint8 ATCmd_Send[50];
 	uint16 ATCmd_SendLen;
@@ -234,13 +246,18 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	}
 	ATCmd_SendLen = ATCmd_SendLen + SetValueLen;
 	/**/
-	memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
-	UART_Query_Data(UART_LPUART2, UART_LPUART2, ATCmd_Send, ATCmd_SendLen, RX_Buffer[UART_LPUART2],&ReadLen, 1000);
-	memcpy(CmdRead, RX_Buffer[UART_LPUART2], 50);
+//	memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
+	UART_Query_Data(UART_LPUART2, UART_LPUART2, ATCmd_Send, ATCmd_SendLen, &UartRecvPtr,&ReadLen, 1000);
+	memcpy(CmdRead, UartRecvPtr, 50);
 	/*
 	UartTramsit(ATCmd_Send, ATCmd_SendLen, CmdRead, 1, osWaitForever);
 	*/
 	*retFunc = BleAtCmdFunc[CmdIdx].cb(ATCmd_Send, CmdRead, CmdIdx);
+	if(UartRecvPtr != NULL)
+	{
+		free(UartRecvPtr);
+	}
+	UartRecvPtr = NULL;
 	return;
 }
 static void bleInit(void)
@@ -249,6 +266,7 @@ static void bleInit(void)
 	sint8 ret = -1;
 	uint8 bleInitStep = 0;
 	uint8 BleCurrentName[6];
+	uint8 *UartRecvPtr=NULL;
 	while (1)
 	{
 		vTaskDelay(pdMS_TO_TICKS(100));
@@ -258,7 +276,6 @@ static void bleInit(void)
 		{
 			//UartTramsit(NULL, 0, AtCmdRead, 1, 100);
 			uint16 Readlen = 0;
-			UART_Receive_Data(UART_LPUART2, AtCmdRead,&Readlen, 100);
 			memset(AtCmdRead, 0x00, sizeof(AtCmdRead));
 			AtcmdTransmit(AT_Cmd_Test, NULL, 0, AtCmdRead, &ret);
 			if (ret == 0)
@@ -399,8 +416,6 @@ static sint8 bleRoleSetFunc(void)
 		{
 		case 0: // AT同步
 		{
-			//			UartTramsit(NULL, 0, AtCmdRead, 1, 100);
-			UART_Receive_Data(UART_LPUART2, AtCmdRead,&ReadLen, 1000);
 			memset(AtCmdRead, 0x00, sizeof(AtCmdRead));
 			AtcmdTransmit(AT_Cmd_Test, NULL, 0, AtCmdRead, &ret);
 			if (ret == 0)

+ 36 - 1
src/AppTaskCan.c

@@ -210,16 +210,46 @@ static void uartDataDecode(uint8 Data[])
     case 0x08: //完成换电
     {
     	swapBattDone = 1;
+    	uint16 CrcChkCal = 0;
+    	ReadLen = 1*7+2;
+    	DataSend.RealLen = ReadLen;
+    	DataSend.DataPtr = malloc(ReadLen+1);
+    	memset(DataSend.DataPtr,0x00,ReadLen+1);
+    	*(DataSend.DataPtr+7*0) = 0x81;
+    	CrcChkCal = CRC16_Modbus(DataSend.DataPtr,ReadLen-2);
+    	*(DataSend.DataPtr+1*7+0) = CrcChkCal;
+    	*(DataSend.DataPtr+1*7+1) = CrcChkCal>>8;
+    	McuDataRet= xQueueSend(McuDataRecvHandle,&DataSend,1000*2);
         break;
     }
     case 0x09: //强制解锁,强制上升
     {
     	unlockCmdFlg = 1;
+    	uint16 CrcChkCal = 0;
+    	ReadLen = 1*7+2;
+    	DataSend.RealLen = ReadLen;
+    	DataSend.DataPtr = malloc(ReadLen+1);
+    	memset(DataSend.DataPtr,0x00,ReadLen+1);
+    	*(DataSend.DataPtr+7*0) = 0x91;
+    	CrcChkCal = CRC16_Modbus(DataSend.DataPtr,ReadLen-2);
+    	*(DataSend.DataPtr+1*7+0) = CrcChkCal;
+    	*(DataSend.DataPtr+1*7+1) = CrcChkCal>>8;
+    	McuDataRet= xQueueSend(McuDataRecvHandle,&DataSend,1000*2);
         break;
     }
     case 0x0A: //强制锁紧,强制下降
     {
     	lockCmdFlg = 1;
+    	uint16 CrcChkCal = 0;
+    	ReadLen = 1*7+2;
+    	DataSend.RealLen = ReadLen;
+    	DataSend.DataPtr = malloc(ReadLen+1);
+    	memset(DataSend.DataPtr,0x00,ReadLen+1);
+    	*(DataSend.DataPtr+7*0) = 0xA1;
+    	CrcChkCal = CRC16_Modbus(DataSend.DataPtr,ReadLen-2);
+    	*(DataSend.DataPtr+1*7+0) = CrcChkCal;
+    	*(DataSend.DataPtr+1*7+1) = CrcChkCal>>8;
+    	McuDataRet= xQueueSend(McuDataRecvHandle,&DataSend,1000*2);
         break;
     }
     case 0x0B: //回到行车状态
@@ -351,7 +381,7 @@ static void CanDecode(uint32 AskCanID, uint8 AskData[])
 	{
 	case 0x201:
 		PackExcSts= AskData[0];
-		VehPowerMode = (AskData[1]>>3)&0x01;
+//		VehPowerMode = (AskData[1]>>3)&0x01;
 		GearSts = (AskData[1]>>4)&0x01;
 		EPBWorkingSts = (AskData[1]>>5)&0x01;
 		BrakeSwitchSts = (AskData[1]>>6)&0x01;
@@ -386,6 +416,11 @@ static void CanDecode(uint32 AskCanID, uint8 AskData[])
 			}
 		}
 		break;
+	case 0x206:
+	{
+		VehPowerMode = AskData[4];
+		break;
+	}
 	default:
 		break;
 	}

+ 11 - 7
src/AppTaskUart0.c

@@ -23,25 +23,29 @@ void UartTask(void *pvParameters)
 	McuDataSendHandle = xQueueCreate(2, 10); // Mcu的AT数据指令发送队列
 	McuDataRecvHandle = xQueueCreate(1, sizeof(BleRecvDataFromUart2)); // Mcu的AT数据数据获取队列
 	char AtCmdRead[50+7];
-	uint8 temp[6] = {0xBE, 0xC8, 0xD9, 0xA2, 0xE2, 0x2B};
-	memcpy(&AtCmdRead[strlen(AtCmdRead)], temp, sizeof(temp));
 	char McuAtCmdAns[300] = {0};
 	uint8 McuAtCmdAnsLen;
 	uint8 RecvRet = 1;
 	uint16 ReadLen = 0;
+	uint8 *UartRecvPtr=NULL;
 	for (;;)
 	{
 		vTaskDelay(pdMS_TO_TICKS(10));
-		RecvRet = UART_Receive_Data(UART_LPUART0, RX_Buffer[UART_LPUART0],&ReadLen, 1000);
-		memcpy(AtCmdRead, RX_Buffer[UART_LPUART0], sizeof(AtCmdRead));
-		memset(RX_Buffer[UART_LPUART0], 0x00, sizeof(RX_Buffer[UART_LPUART0]));
-		if(!RecvRet)
+		UART_Receive_Data(UART_LPUART0,&UartRecvPtr,&ReadLen, 1000);
+		memset(AtCmdRead,0x00,sizeof(AtCmdRead));
+		memcpy(AtCmdRead, UartRecvPtr, ReadLen);
+		if(ReadLen>0)
 		{
 			memset(McuAtCmdAns,0x00,sizeof(McuAtCmdAns));
 			McuAtCmdAnsLen = 0;
 			McuATCmdTransmit(AtCmdRead, ReadLen, McuAtCmdAns, &McuAtCmdAnsLen);
 			UART_Send_Data(UART_LPUART0,McuAtCmdAns,McuAtCmdAnsLen,1000);
 		}
+		if(UartRecvPtr != NULL)
+		{
+			free(UartRecvPtr);
+		}
+		UartRecvPtr = NULL;
 	}
 }
 void McuATCmdTransmit(char *Readptr, uint16 Readlen, char *AnsPtr, uint8 *AnsPtrLen)
@@ -83,7 +87,7 @@ sint8 McuAtCallbackFunc(char *Readptr,uint16 ReadLen, McuAtCmd McuAtIdx, char *A
 		*AnsPtrLen = strlen(SucAns);
 		for (uint8 i = 0; i < sizeof(BleVersion) * 2; i++)
 		{
-			chartemp = HexToChar(BleVersion >> (28 - 4 * i));
+			chartemp = HexToChar((BleVersion >> (28 - 4 * i))&0x0F);
 			memcpy(AnsPtr + *AnsPtrLen + i, &chartemp, 1);
 		}
 

+ 7 - 0
src/Hal_Wdg.c

@@ -101,8 +101,15 @@ void WATCHDOG_HAL_Feed(void)
 	Wdg_43_Instance0_SetTriggerCondition(500);
 }
 
+typedef void (*AppAddr)(void);
 void DoResetECU(void)
 {
 	IsFeedWdg = FALSE;
 	Wdg_43_Instance0_SetTriggerCondition(0);
+	while(1)
+	{
+//		AppAddr resetHandle = (AppAddr)(0x00);
+//		    (resetHandle)();
+		;
+	}
 }

+ 1 - 1
src/UDSTask.c

@@ -68,7 +68,7 @@ static const uint16 g_dnpCrcTable[256u] =
 /* Set information CRC */
 #define SetInforCRC(xCrc) ((*(uint16 *)(gs_stBootInfo.infoStartAddr + 14)) = (uint16)(xCrc))
 
-static void CreatSoftwareCrc16(const uint8 *i_pDataBuf, const uint32 i_dataLen, uint32 *m_pCurCrc)
+void CreatSoftwareCrc16(const uint8 *i_pDataBuf, const uint32 i_dataLen, uint32 *m_pCurCrc)
 {
     uint16 crc = 0u;
     uint32 index = 0u;

+ 424 - 257
src/hal_adapter.c

@@ -6,276 +6,443 @@
  */
 #include "hal_adapter.h"
 #include "AppGlobalVar.h"
-/*NB*/
-/**
- * @brief :??????
- * @param {UINT8} *pSend
- * @param {UINT32} sendLen
- * @param {UINT8} *pRead
- * @param {UINT32} readLen
- * @param {UINT32} timeout
- * @return {*}
- */
-/*
-UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UINT32 timeout)
+uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[3][BUFFER_SIZE];
+uint32_t bufferIdx[3] = {0};
+
+ volatile Uart_StatusType Uart_TransmitStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
+ QueueHandle_t UartRecvQueue[3];
+ QueueHandle_t UartSendQueue[3];
+ QueueHandle_t UartHalQueueHandle;
+ void Uart_Hal_RecvTask(void *pvParameters);
+ void Uart_Hal_SendTask(void *pvParameters);
+ Std_ReturnType UartStartRecvFunc(uint8 channel);
+Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 **rxBuffer, uint16 *rxlen, uint32 T_timeout)
 {
-    UartBufferPtr UartData = {NULL, 0};
-    uint8 ReadLen = 0;
-    if (pSend)
-    {
-        HAL_UART_SendStr(PORT_USART_0, pSend, sendLen);
-    }
-    if (readLen > 0)
-    {
-        osStatus_t ret = osMessageQueueGet(uart0DataHandle, &UartData, 0, timeout);
-        if (ret == osOK)
-        {
-            if (UartData.dataPtr != NULL)
-            {
-                memcpy(pRead, (UINT8 *)UartData.dataPtr, UartData.len);
-                free(UartData.dataPtr);
-            }
-            UartData.dataPtr = NULL;
-            ReadLen = UartData.len;
-        }
-        else
-        {
-            osDelayUntil(1000);
-            osMessageQueueReset(uart0DataHandle);
-            memset(pRead, 0x00, readLen);
-            ReadLen = 0;
-        }
-    }
-    return ReadLen;
+	UartMsg_t UartRecvMsg;
+	UartMsg_t UartSendMsg;
+	BaseType_t Sendret = pdFALSE;
+	BaseType_t Recvret = pdFALSE;
+	uint32 retVal = E_NOT_OK;
+	UartSendMsg.DataLen = sendLength;
+	UartSendMsg.dataPrt = txBuffer;
+	*rxlen = 0;
+	Sendret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,10);
+
+	memset(&UartRecvMsg,0,sizeof(UartMsg_t));
+
+	if(Sendret == pdTRUE)
+	{
+		Recvret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
+		if(Recvret == pdTRUE)
+		{
+			*rxlen = UartRecvMsg.DataLen;
+			*rxBuffer = UartRecvMsg.dataPrt;
+			retVal = E_OK;
+		}
+	}
+	return retVal;
 }
-*/
- uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];
- uint32_t bufferIdx[3] = {0};
- Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout)
- {
-     volatile Std_ReturnType R_Uart_Status;
-     volatile Std_ReturnType T_Uart_Status;
-     volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
-     volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
-     uint32 T_bytesRemaining;
-     uint32 R_bytesRemaining;
-     uint32 timeout = T_timeout;
-     uint32 retVal = E_NOT_OK;
-     //    uint8 Rx_Buffer[MSG_LEN];
-
-     /* Uart_AsyncReceive transmit data */
- //    IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(0);
-     bufferIdx[recvChannel]=0;
- 	switch(recvChannel)
- 	{
- 	case 0:
- 		IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
- 		break;
- 	case 1:
- 		IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
- 		break;
- 	case 2:
- 		IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
- 		break;
- 	default:
- 		break;
- 	}
- if (txBuffer == NULL || rxBuffer == NULL)
- {
-     return retVal;
- }
- /* Uart_AsyncSend transmit data */
- Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
- T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
- if (E_OK != T_Uart_Status)
- {
-     Uart_Abort(transChannel, UART_SEND);
-     return E_NOT_OK;
- }
- Uart_SetBuffer(recvChannel, &RX_Buffer[recvChannel][0], DMA_SIZE, UART_RECEIVE);
- R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
- if (E_OK != R_Uart_Status)
+Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 **rxBuffer, uint16 *rxlen, sint32 T_timeout)
+{
+	UartMsg_t UartRecvMsg;
+	BaseType_t ret = pdFALSE;
+	uint32 retVal = E_NOT_OK;
+	*rxlen = 0;
+	ret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
+	if(ret == pdTRUE)
+	{
+		*rxlen = UartRecvMsg.DataLen;
+		*rxBuffer = UartRecvMsg.dataPrt;
+		retVal = E_OK;
+	}
+	return retVal;
+}
+Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
+{
+	UartMsg_t UartSendMsg;
+	BaseType_t ret = pdFALSE;
+	uint32 retVal = E_NOT_OK;
+	UartSendMsg.DataLen = sendLength;
+	UartSendMsg.dataPrt = txBuffer;
+	ret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,T_timeout);
+	if(ret == pdTRUE)
+	{
+		retVal = E_OK;
+	}
+	return retVal;
+}
+ void UartInit(void)
  {
-     Uart_Abort(recvChannel, UART_RECEIVE);
-     return E_NOT_OK;
+	 UartRecvQueue[0] = xQueueCreate(3, sizeof(UartMsg_t));
+	 UartRecvQueue[1] = xQueueCreate(3, sizeof(UartMsg_t));
+	 UartRecvQueue[2] = xQueueCreate(3, sizeof(UartMsg_t));
+	 UartSendQueue[0] = xQueueCreate(1, sizeof(UartMsg_t));
+	 UartSendQueue[1] = xQueueCreate(1, sizeof(UartMsg_t));
+	 UartSendQueue[2] = xQueueCreate(1, sizeof(UartMsg_t));
+	 UartHalQueueHandle = xQueueCreate(6, sizeof(UartHalMsg_t));
+
+	 xTaskCreate(Uart_Hal_RecvTask, (const char *const)"UartRecv", 1024, (void *)0, main_TASK_PRIORITY + 3, NULL);
+	 xTaskCreate(Uart_Hal_SendTask, (const char *const)"UartSend", 1024, (void *)0, main_TASK_PRIORITY + 2, NULL);
  }
-
- /* Check for no on-going transmission */
- do
+ Std_ReturnType UartStartRecvFunc(uint8 channel)
  {
-	 if(Uart_TransmitStatus != UART_STATUS_NO_ERROR)
-	 {
-		 Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
-	 }
-	 if(Uart_ReceiveStatus != UART_STATUS_NO_ERROR)
+	 sint8 out = 0;
+	 volatile Std_ReturnType R_Uart_Status=E_NOT_OK;
+	 bufferIdx[channel]=0;
+	 memset(RX_Buffer[channel],0x00,BUFFER_SIZE);
+	 switch(channel)
 	 {
-		 Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
+		case 0:
+			IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+			break;
+		case 1:
+			IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
+			break;
+		case 2:
+			IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
+			break;
+		default:
+			break;
 	 }
-     vTaskDelay(pdMS_TO_TICKS(1));
- } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
-
- if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
- {
-     Uart_Abort(transChannel, UART_SEND);
-     retVal = E_NOT_OK;
+	 Uart_SetBuffer(channel, RX_Buffer[channel], DMA_SIZE, UART_RECEIVE);
+	 R_Uart_Status = Uart_AsyncReceive(channel, RX_Buffer[channel], DMA_SIZE);
+	  if (E_OK != R_Uart_Status)
+	  {
+		  Uart_Abort(channel, UART_RECEIVE);
+		  out = E_NOT_OK;
+	  }
+	 return out;
  }
- else
+ void Uart_Hal_RecvTask(void *pvParameters)
  {
-     retVal = E_OK;
- }
- if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
- {
-     Uart_Abort(recvChannel, UART_RECEIVE);
-     *rxlen = bufferIdx[recvChannel];
-     //IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
-     retVal = E_NOT_OK;
+	 UartMsg_t UartMsg;
+	 UartHalMsg_t UartHalMsgRecv;
+	 BaseType_t ret = pdFALSE;
+	 uint32 T_bytesRemaining[3] = {0};
+	 uint16 T_timeout[3] = {0};
+	 volatile Uart_StatusType Uart_ReceiveStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
+	 uint8 UartIdx = UART_LPUART0;
+	 uint8 UartState[3] = {UartAbortRecv,UartAbortRecv,UartAbortRecv};
+	 while(1)
+	 {
+		 if((T_timeout[UartIdx]>1000) && (Uart_ReceiveStatus[UartIdx] != UART_STATUS_NO_ERROR) )//判定UART停止,超时停止,不是接收状态则停止
+		 {
+			  Uart_Abort(UartIdx, UART_RECEIVE);
+			  UartState[UartIdx] = UartAbortRecv;
+			  T_timeout[UartIdx] = 0;
+		 }
+		 else if(Uart_ReceiveStatus[UartIdx] == UART_STATUS_NO_ERROR)
+		 {
+			 UartState[UartIdx] = UartRecvComplete;
+		 }
+
+		 if((UartState[UartIdx] == UartAbortRecv) || (UartState[UartIdx] == UartRecvComplete)) //判定UART开始接收:UART停止后开始接收
+		 {
+			 if(E_OK == UartStartRecvFunc(UartIdx))
+			 {
+				 UartState[UartIdx] = UartStartRecv;
+			 }
+		 }
+
+		 ret = xQueueReceive(UartHalQueueHandle,&UartHalMsgRecv,1);
+
+		 Uart_ReceiveStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_RECEIVE);
+		 T_timeout[UartIdx]++;
+		 UartIdx = (UartIdx + 1) > 2 ? 0 : (UartIdx + 1);
+
+
+		  if(ret==pdTRUE)
+		  {
+			  if(UartHalMsgRecv.event==LPUART_UART_IP_EVENT_RECV_IDLE)
+			  {
+					UartMsg.DataLen = UartHalMsgRecv.value;
+//					UartMsg.dataPrt = RX_Buffer[UartHalMsgRecv.Channel];
+
+					UartMsg.dataPrt = malloc(UartMsg.DataLen);
+					memset(UartMsg.dataPrt,0,UartMsg.DataLen);
+					memcpy(UartMsg.dataPrt,RX_Buffer[UartHalMsgRecv.Channel],UartMsg.DataLen);
+
+					xQueueSendToFront(UartRecvQueue[UartHalMsgRecv.Channel],&UartMsg,1);
+
+					T_timeout[UartHalMsgRecv.Channel] = 0;
+					UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
+
+//					Uart_ReceiveStatus[UartHalMsgRecv.Channel] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_RECEIVE);
+			  }
+		  }
+	 }
  }
- else
+ void Uart_Hal_SendTask(void *pvParameters)
  {
-	 *rxlen = bufferIdx[recvChannel];
-     retVal = E_OK;
- }
- return retVal;
- }
-
- Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
- {
-
-     volatile Std_ReturnType T_Uart_Status;
-     volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
-     uint32 T_bytesRemaining;
-     uint32 timeout = T_timeout;
-     uint32 retVal = E_NOT_OK;
-     //    uint8 Rx_Buffer[MSG_LEN];
-
-     if (txBuffer == NULL)
-     {
-         return retVal;
-     }
-
-     /* Uart_AsyncSend transmit data */
-//     Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
-     T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
-     if (E_OK != T_Uart_Status)
-     {
-         Uart_Abort(transChannel, UART_SEND);
-         return E_NOT_OK;
-     }
-
-     /* Check for no on-going transmission */
-     do
-     {
-         Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
-         vTaskDelay(pdMS_TO_TICKS(1));
-     } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));
-
-     if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
-     {
-         //Uart_Abort(transChannel, UART_SEND);
-         retVal = E_NOT_OK;
-     }
-     else
-     {
-         retVal = E_OK;
-     }
-     return retVal;
- }
+	 UartMsg_t UartSendMsg;
+	 BaseType_t ret = pdFALSE;
+	 uint32 T_bytesRemaining[3] = {0};
+	 uint16 T_timeout[3] = {0};
+	 volatile Std_ReturnType T_Uart_Status[3];
+	 uint8 UartIdx = UART_LPUART0;
+	 uint8 UartSendState[3] = {UartNoDataSend,UartNoDataSend,UartNoDataSend};
+	 while(1)
+	 {
+		 ret = xQueueReceive(UartSendQueue[UartIdx],&UartSendMsg,1);
+		 if(ret==pdTRUE)
+		 {
+			 T_Uart_Status[UartIdx] = Uart_AsyncSend(UartIdx, UartSendMsg.dataPrt, UartSendMsg.DataLen);
+		     if (E_OK != T_Uart_Status[UartIdx])
+		     {
+		         Uart_Abort(UartIdx, UART_SEND);
+		         UartSendState[UartIdx] = UartAbortSend;
+		     }
+		     else
+		     {
+		    	 UartSendState[UartIdx] = UartStartSend;
+		     }
+		 }
+		 /*开始发送后的判定*/
+		 if(UartSendState[UartIdx] == UartStartSend)
+		 {
+			 Uart_TransmitStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_SEND);
+			 T_timeout[UartIdx]++;
+		 }
+		 if(T_timeout[UartIdx]>=1000 || ((Uart_TransmitStatus[UartIdx] != UART_STATUS_OPERATION_ONGOING) && (UartSendState[UartIdx] == UartStartSend)))
+		 {
+			 if(T_timeout[UartIdx]>=1000)
+			 {
+				 Uart_Abort(UartIdx, UART_SEND);
+				 UartSendState[UartIdx] = UartAbortSend;
+			 }
+			 else if(Uart_TransmitStatus[UartIdx] == UART_STATUS_NO_ERROR)
+			 {
+				 UartSendState[UartIdx] = UartSendComplete;
+			 }
+			 T_timeout[UartIdx] = 0;
+		 }
+
+		 UartIdx = (UartIdx + 1) > 2 ? 0 : (UartIdx + 1);
+	 }
 
- Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen,sint32 T_timeout)
- {
-     volatile Std_ReturnType R_Uart_Status=E_NOT_OK;
-     volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
-     uint32 T_bytesRemaining = 0;
-     uint32 retVal = E_NOT_OK;
-     //    uint8 Rx_Buffer[MSG_LEN];
-     bufferIdx[recvChannel]=0;
-     *rxlen = 0;
-     if (rxBuffer == NULL)
-     {
-         return retVal;
-     }
-     /* Uart_AsyncReceive transmit data */
-	switch(recvChannel)
-	{
-	case 0:
-		IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
-		break;
-	case 1:
-		IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
-		break;
-	case 2:
-		IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
-		break;
-	default:
-		break;
-	}
-     Uart_SetBuffer(recvChannel, rxBuffer, DMA_SIZE, UART_RECEIVE);
-     R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
-     if (E_OK != R_Uart_Status)
-     {
-         Uart_Abort(recvChannel, UART_RECEIVE);
-         return E_NOT_OK;
-     }
-     /* Check for no on-going transmission */
-     do
-     {
-         Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
-         vTaskDelay(pdMS_TO_TICKS(1));
-     } while ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus)&& 0<T_timeout--);
-     if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
-     {
-         Uart_Abort(recvChannel, UART_RECEIVE);
-         *rxlen = bufferIdx[recvChannel];
-         retVal = E_NOT_OK;
-     }
-     else
-     {
-    	 *rxlen = bufferIdx[recvChannel];
-         retVal = E_OK;
-     }
-     return retVal;
- }
- void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event )
- {
- //    (void)userData;
-     uint32_t temp;
-     /* Check the event type */
-     if (event == LPUART_UART_IP_EVENT_RX_FULL)
-     {
-         /* The reception stops when receiving idle is detected or the buffer is full */
-         if (bufferIdx[hwInstance] <= (BUFFER_SIZE - DMA_SIZE))
-         {
-             /* Update the buffer index and the rx buffer */
-        	 bufferIdx[hwInstance] += DMA_SIZE;
-         	Uart_SetBuffer(hwInstance,&RX_Buffer[hwInstance][bufferIdx[hwInstance]],DMA_SIZE,UART_RECEIVE);
-             //Lpuart_Uart_Ip_SetRxBuffer(hwInstance, &RX_Buffer[bufferIdx], DMA_SIZE);
-         }
-     }
-     else if (event == LPUART_UART_IP_EVENT_ERROR)
-     {
-//     	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
-//     	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
-//     	/*Add the remaining data size to the sum of the received size*/
-//     	bufferIdx[hwInstance] += temp;
-         /*Abort the receiving after detecting IDLE receiving*/
-     	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
- //    	bufferIdx = 0;
-     }
-     else if( event == LPUART_UART_IP_EVENT_RECV_IDLE)
-     {
-     	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
- 		temp = DMA_SIZE - (uint32_t)IP_DMA->TCD[hwInstance].CITER.ELINKNO;
- 		/*Add the remaining data size to the sum of the received size*/
- 		bufferIdx[hwInstance] += temp;
- 		/*Abort the receiving after detecting IDLE receiving*/
- 		Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
- //		rxSuccess = true;
-     }
-     else
-     {
-    	 temp = 0;
-     }
  }
+//
+//Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout)
+//{
+//    volatile Std_ReturnType R_Uart_Status;
+//    volatile Std_ReturnType T_Uart_Status;
+//    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
+//    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
+//    uint32 T_bytesRemaining;
+//    uint32 R_bytesRemaining;
+//    uint32 timeout = T_timeout;
+//    uint32 retVal = E_NOT_OK;
+//    bufferIdx[recvChannel] = 0;
+//    switch (recvChannel)
+//    {
+//    case 0:
+//        IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    case 1:
+//        IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    case 2:
+//        IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    default:
+//        break;
+//    }
+//    if (txBuffer == NULL || rxBuffer == NULL)
+//    {
+//        return retVal;
+//    }
+//
+//    /* Uart_AsyncSend transmit data */
+//    Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
+//    T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
+//    if (E_OK != T_Uart_Status)
+//    {
+//        Uart_Abort(transChannel, UART_SEND);
+//        return E_NOT_OK;
+//    }
+//    Uart_SetBuffer(recvChannel, &RX_Buffer[recvChannel][0], DMA_SIZE, UART_RECEIVE);
+//    R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
+//    if (E_OK != R_Uart_Status)
+//    {
+//        Uart_Abort(recvChannel, UART_RECEIVE);
+//        return E_NOT_OK;
+//    }
+//    /* Check for no on-going transmission */
+//    do
+//    {
+//        if (Uart_TransmitStatus != UART_STATUS_NO_ERROR)
+//        {
+//            Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
+//        }
+//        if (Uart_ReceiveStatus != UART_STATUS_NO_ERROR)
+//        {
+//            Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
+//        }
+//        vTaskDelay(pdMS_TO_TICKS(1));
+//    } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
+//    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
+//    {
+//        Uart_Abort(transChannel, UART_SEND);
+//        retVal = E_NOT_OK;
+//    }
+//    else
+//    {
+//        retVal = E_OK;
+//    }
+//    if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
+//    {
+//        Uart_Abort(recvChannel, UART_RECEIVE);
+//        *rxlen = bufferIdx[recvChannel];
+//        retVal = E_NOT_OK;
+//    }
+//    else
+//    {
+//        *rxlen = bufferIdx[recvChannel];
+//        retVal = E_OK;
+//    }
+//    return retVal;
+//}
+//
+//Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
+//{
+//
+//    volatile Std_ReturnType T_Uart_Status;
+//    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
+//    uint32 T_bytesRemaining;
+//    uint32 timeout = T_timeout;
+//    uint32 retVal = E_NOT_OK;
+//    if (txBuffer == NULL)
+//    {
+//        return retVal;
+//    }
+//
+//    /* Uart_AsyncSend transmit data */
+//    T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
+//    if (E_OK != T_Uart_Status)
+//    {
+//        Uart_Abort(transChannel, UART_SEND);
+//        return E_NOT_OK;
+//    }
+//    /* Check for no on-going transmission */
+//    do
+//    {
+//        Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
+//        vTaskDelay(pdMS_TO_TICKS(1));
+//    } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));
+//
+//    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
+//    {
+//        retVal = E_NOT_OK;
+//    }
+//    else
+//    {
+//        retVal = E_OK;
+//    }
+//    return retVal;
+//}
+//
+//Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen, sint32 T_timeout)
+//{
+//    volatile Std_ReturnType R_Uart_Status = E_NOT_OK;
+//    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
+//    uint32 T_bytesRemaining = 0;
+//    uint32 retVal = E_NOT_OK;
+//    //    uint8 Rx_Buffer[MSG_LEN];
+//    bufferIdx[recvChannel] = 0;
+//    *rxlen = 0;
+//    if (rxBuffer == NULL)
+//    {
+//        return retVal;
+//    }
+//    /* Uart_AsyncReceive transmit data */
+//    switch (recvChannel)
+//    {
+//    case 0:
+//        IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    case 1:
+//        IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    case 2:
+//        IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
+//        break;
+//    default:
+//        break;
+//    }
+//    Uart_SetBuffer(recvChannel, rxBuffer, DMA_SIZE, UART_RECEIVE);
+//    R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
+//    if (E_OK != R_Uart_Status)
+//    {
+//        Uart_Abort(recvChannel, UART_RECEIVE);
+//        return E_NOT_OK;
+//    }
+//    /* Check for no on-going transmission */
+//    do
+//    {
+//        Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
+//        vTaskDelay(pdMS_TO_TICKS(1));
+//
+//    } while ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < T_timeout--);
+//    if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
+//    {
+//        Uart_Abort(recvChannel, UART_RECEIVE);
+//        *rxlen = bufferIdx[recvChannel];
+//        retVal = E_NOT_OK;
+//    }
+//    else
+//    {
+//        *rxlen = bufferIdx[recvChannel];
+//        retVal = E_OK;
+//    }
+//    return retVal;
+//}
+extern Lpuart_Uart_Ip_StateStructureType *Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
+void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event)
+{
+    //    (void)userData;
+		Lpuart_Uart_Ip_StateStructureType * UartState;
+		UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[hwInstance];
+    /* Check the event type */
+    if (event == LPUART_UART_IP_EVENT_RX_FULL)
+    {
+        /* The reception stops when receiving idle is detected or the buffer is full */
+        if (bufferIdx[hwInstance] <= (BUFFER_SIZE - DMA_SIZE))
+        {
+            /* Update the buffer index and the rx buffer */
+            bufferIdx[hwInstance] += DMA_SIZE;
+            Uart_SetBuffer(hwInstance, &RX_Buffer[hwInstance][bufferIdx[hwInstance]], DMA_SIZE, UART_RECEIVE);
+            // Lpuart_Uart_Ip_SetRxBuffer(hwInstance, &RX_Buffer[bufferIdx], DMA_SIZE);
+        }
+    }
+    if (event == LPUART_UART_IP_EVENT_ERROR)
+    {
+        //     	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
+        //     	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
+        //     	/*Add the remaining data size to the sum of the received size*/
+        //     	bufferIdx[hwInstance] += temp;
+        /*Abort the receiving after detecting IDLE receiving*/
+        Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
+        Lpuart_Uart_Ip_AbortSendingData(hwInstance);
+        //    	bufferIdx = 0;
+    }
+    if (event == LPUART_UART_IP_EVENT_RECV_IDLE)
+    {
+         uint32_t temp;
+         UartHalMsg_t UartHalMsg;
+         UartHalMsg.Channel = hwInstance;
+         UartHalMsg.event = event;
+        /*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
+        temp = DMA_SIZE - (uint32_t)IP_DMA->TCD[hwInstance].CITER.ELINKNO;
+        /*Add the remaining data size to the sum of the received size*/
+        bufferIdx[hwInstance] += temp;
+        /*Abort the receiving after detecting IDLE receiving*/
+        UartState->IsRxBusy = FALSE;
+        UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
+        Lpuart_Uart_Ip_CompleteReceiveUsingDma(hwInstance);
+ 		UartHalMsg.value = bufferIdx[hwInstance];
+ 		xQueueSendFromISR(UartHalQueueHandle,&UartHalMsg,pdFALSE);
+    }
+}
 
  /*CAN*/
  Can_PduType Can_CreatePduInfo(Can_IdType id, CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8 *sdu)

+ 55 - 48
src/hal_adapter.h

@@ -16,39 +16,7 @@
 
 #ifndef HAL_ADAPTER_H_
 #define HAL_ADAPTER_H_
-/*NB
-
-#include "commontypedef.h"
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include <stdlib.h>
-#include "numeric.h"
-#include "AppSignal.h"
-#include "hal_uart.h"
-#include "timers.h"
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef signed char sint8;
-typedef signed short sint16;
-typedef signed int sint32;
-UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UINT32 timeout);
- */
+
  #include "Mcal.h"
  #include "CAN.h"
  #include "SchM_Can.h"
@@ -70,28 +38,67 @@ UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UI
  #include "task.h"
  #include "semphr.h"
  #include "Eep.h"
-#define getbit(x,y)     ((x) >> (y)&1)                        //获取x的第y位的数值
-#define setbit(x,y)     x|=(1<<y)                             //x的第y位置1
-#define clrbit(x,y)     x&=~(1<<y)                            //x的第y位置0
- #define UART_LPUART0 0
- #define UART_LPUART1 1
- #define UART_LPUART2 2
- #define FLEXIO_RX 3
- #define FLEXIO_TX 4
- #define main_TASK_PRIORITY                ( tskIDLE_PRIORITY + 7 )
+typedef unsigned char UINT8;
+typedef unsigned short UINT16;
+typedef unsigned long UINT32;
+typedef unsigned char BOOL;
+typedef signed char INT8;
+typedef signed short INT16;
+typedef signed long INT32;
+#define CAN0 0
+#define CAN1 1
+#ifndef min
+#define min(A, B) ((A) <= (B) ? (A) : (B))
+#endif
+#ifndef max
+#define max(A, B) ((A) < (B) ? (B) : (A))
+#endif
+#define getbit(x, y) ((x) >> (y)&1) //获取x的第y位的数值
+#define setbit(x, y) x |= (1 << y)  // x的第y位置1
+#define clrbit(x, y) x &= ~(1 << y) // x的第y位置0
+#define UART_LPUART0 0
+#define UART_LPUART1 1
+#define UART_LPUART2 2
+#define FLEXIO_RX 3
+#define FLEXIO_TX 4
+#define main_TASK_PRIORITY (tskIDLE_PRIORITY + 7)
 
  #define MSG_LEN 50U
  #define TJA1153_START_ID (uint32_t)(0x555u)
  #define TJA1153_CONFIG_ID (uint32_t)(0x18DA00F1u)
 
- #define BUFFER_SIZE 200
- #define DMA_SIZE 50
- extern uint8_t RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];
- Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout);
+#define BUFFER_SIZE 1000
+#define DMA_SIZE 20
+ typedef struct
+ {
+     uint16 DataLen;
+     uint8 *dataPrt;
+ } UartMsg_t;
+ typedef struct
+ {
+	 uint8 Channel;
+	 Lpuart_Uart_Ip_EventType event;
+     uint16  value;
+ } UartHalMsg_t;
+ typedef enum
+ {
+	 UartStartRecv = 0,
+	 UartAbortRecv,
+	 UartRecvOnGoing,
+	 UartRecvComplete,
+
+	 UartStartSend,
+	 UartAbortSend,
+	 UartSendOnGoing,
+	 UartSendComplete,
+	 UartNoDataSend,
+ };
+
+Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 **rxBuffer, uint16 *rxlen, uint32 T_timeout);
  Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout);
- Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer,uint16 *rxlen, sint32 T_timeout);
+Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 **rxBuffer, uint16 *rxlen, sint32 T_timeout);
  void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event);
-
+void UartInit(void);
  /*CAN*/
  typedef enum
  {

+ 5 - 4
src/main.c

@@ -135,12 +135,13 @@ int main(void)
 	/* Enable the Gpt notification to periodically service the Wdg */
 	Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
 	WdgInit();
-	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
-	IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
-    Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_BT_POW_EN,STD_ON);
-    Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD,STD_ON);
+	IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
+	IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
+    //Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_BT_POW_EN,STD_ON);
+    //Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD,STD_ON);
 
     xTaskCreate( MainTask, ( const char * const ) "MainTask", 128, (void*)0, main_TASK_PRIORITY+3 , NULL );
+	UartInit();
 //    xTaskCreate( BleTask, ( const char * const ) "BleTask", 256 + 64, (void*)0, main_TASK_PRIORITY , NULL );
     xTaskCreate( CanTask, ( const char * const ) "CanTask" , 512, (void*)0, main_TASK_PRIORITY + 2, NULL );
     xTaskCreate( UartTask, ( const char * const ) "UartTask" , 512, (void*)0, main_TASK_PRIORITY + 1, NULL );