|
@@ -58,7 +58,7 @@ static process_Uart gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
|
|
|
|
|
|
//函数声明区
|
|
|
void USART_callback(uint32_t event);
|
|
|
-UINT8 Uart_Transmit_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer);
|
|
|
+UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer);
|
|
|
UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData);
|
|
|
UINT16 crc_chk(UINT8* data, UINT8 length);
|
|
|
void battSOCDisplay(void);
|
|
@@ -128,7 +128,7 @@ static void UartTask(void* arg)
|
|
|
else if(Timer_count%10==0)
|
|
|
{
|
|
|
#ifdef USING_PRINTF
|
|
|
- printf("[%d]Uart Timer 5s:%d\n",__LINE__,Timer_count);
|
|
|
+ printf("[%d]Uart Timer 5s:%d,Header:%x\n",__LINE__,Timer_count,UartReadMsg.Header[2]);
|
|
|
#endif
|
|
|
if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
|
|
|
{
|
|
@@ -179,7 +179,7 @@ static void UartTask(void* arg)
|
|
|
}
|
|
|
case PROCESS_UART_STATE_READ:
|
|
|
{
|
|
|
- osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
|
|
|
+ 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,8 +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;
|
|
|
- memset(UartReadMsg.Header,0x00,Uart_Uds_LEN);
|
|
|
- Uart_Recv_LEN = Uart_Transmit_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
|
|
|
+ Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
|
|
|
+ osMutexRelease(UartMutex);
|
|
|
if(Uart_Recv_LEN>0)
|
|
|
{
|
|
|
UartReadMsg.UartFlag = TRUE;
|
|
@@ -216,7 +216,6 @@ static void UartTask(void* arg)
|
|
|
}
|
|
|
printf("\n");
|
|
|
#endif
|
|
|
- osMutexRelease(UartMutex);
|
|
|
break;
|
|
|
}
|
|
|
case PROCESS_UART_STATE_WRITE:
|
|
@@ -237,6 +236,7 @@ static void UartTask(void* arg)
|
|
|
{
|
|
|
osDelay(60000/portTICK_PERIOD_MS);
|
|
|
}
|
|
|
+ osThreadExit();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -377,7 +377,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
|
|
|
}
|
|
|
}
|
|
|
//Uart发送接收函数
|
|
|
-UINT8 Uart_Transmit_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
|
+UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
|
{
|
|
|
UINT16 CRC_Rece_buffer;
|
|
|
UINT16 CRC_chk_buffer;
|
|
@@ -397,18 +397,30 @@ UINT8 Uart_Transmit_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(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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- #ifdef USING_PRINTF
|
|
|
+ #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++)
|
|
|
{
|