Browse Source

增加了工作睡觉确认,睡眠可以正确进入,增加了校验不过初始化uart通讯,改为17串7温度

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
95b06b156a
1 changed files with 34 additions and 24 deletions
  1. 34 24
      src/app.c

+ 34 - 24
src/app.c

@@ -36,7 +36,7 @@ uint8_t TcpSlpHandler          = 0xfd;
 
 #define Uart_Send_LEN         (8)
 #define Uart_Rece_LEN         (40)
-
+#define battbuffer_len         (110)
 #define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
 extern ARM_DRIVER_USART Driver_USART1;
 static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
@@ -52,15 +52,18 @@ static UINT32                   gCellID = 0;
 int TcpconnectID = -1;
 volatile bool tcp_ready = false;
 
-uint8_t Batt_Cell_Num = 14;//默认数值14、17
+uint8_t Batt_Cell_Num = 17;//默认数值14、17
 uint8_t Batt_Cell_Num_2 ;//默认数值
-uint8_t Batt_Temp_Num = 5;//默认数值5、7
+uint8_t Batt_Temp_Num = 7;//默认数值5、7
 int16_t Uart_Rece_BattI=0x0000;
 uint8_t Can_Rece_buffer[8];
 volatile bool Can_Enable = false;
 uint16_t data_index = 0x0000;
 volatile bool Sleep_Flag = false;
-uint8_t battbuffer[100];//电池数据都存在此数组中————电压14,温度5
+volatile bool Uart_Sleep_Flag = false;
+volatile bool Can_Sleep_Flag = false;
+volatile bool Tcp_Sleep_Flag = false;
+uint8_t battbuffer[battbuffer_len];//电池数据都存在此数组中————电压14,温度5
 /**
  *  存放规则如下:
  * 位置:   0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15              16             
@@ -268,7 +271,7 @@ static void Main_Task(void* arg)
                 {
                     sleep_index = 0;
                 }
-                if (sleep_index >=60000)
+                if (sleep_index >=6000)
                 {
                     PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
                     sleep_index = 0;
@@ -277,14 +280,16 @@ static void Main_Task(void* arg)
             }
             case PROCESS_STATE_SLEEP:
             {
-                while((gProcess_Uart_Task!=PROCESS_UART_STATE_SLEEP)||(gProcess_Can_Task!=PROCESS_CAN_STATE_SLEEP)||(gProcess_Tcp_Task!=PROCESS_TCP_STATE_SLEEP))
+                while(true)
                 {
                     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
                     PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
                     PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_SLEEP);
+                    if((Uart_Sleep_Flag)&&(Can_Sleep_Flag)&&(Tcp_Sleep_Flag))
+                        break;
                 }
                 Sleep_Flag = TRUE;
-                osDelay(1000);
+                osDelay(2000);
                 #ifdef USING_PRINTF
                             printf("Ms_sleep:uart_%d,can_%d,tcp_%d\r\n",gProcess_Uart_Task,gProcess_Can_Task,gProcess_Tcp_Task);
                 #endif
@@ -311,7 +316,7 @@ static void Main_Task(void* arg)
                 #ifdef USING_PRINTF
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
-
+                slpManDeepSlpTimerStart(deepslpTimerID, 60000);
                 while(1)
                 {
                     osDelay(60000/portTICK_PERIOD_MS);
@@ -376,14 +381,14 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece
     Uart_Send_buffer[7] = CRC_chk_buffer>>8;
     uint32_t timeout = 0x00000000;
     USARTdrv->Send(Uart_Send_buffer,8);
-    // #ifdef USING_PRINTF
-    // printf("Uart_Send_buffer:  ");
-    // for(int i=0;i<8;i++)
-    // {
-    //     printf("%x ",Uart_Send_buffer[i]);
-    // }
-    //  printf("\n");
-    // #endif
+    #ifdef USING_PRINTF
+    printf("Uart_Send_buffer:  ");
+    for(int i=0;i<8;i++)
+    {
+        printf("%x ",Uart_Send_buffer[i]);
+    }
+     printf("\n");
+    #endif
     USARTdrv->Receive(Uart_Rece_buffer,Data_Len);
     while((isRecvTimeout == false) && (isRecvComplete == false))
     {
@@ -402,13 +407,6 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece
         isRecvComplete = false;
         CRC_Rece_buffer =*(Uart_Rece_buffer+Data_Len-1)<<8|*(Uart_Rece_buffer+Data_Len-2);
         CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Data_Len-2);
-        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
-        {
-            return Uart_Rece_buffer;//此处指针移位出现重启问题
-        }
-        else //接收数据的校验不过屏蔽
-        {
-            osDelay(2000);
         #ifdef USING_PRINTF
             printf("Uart_Rece_buffer: ");
             for(int i=0;i<Data_Len;i++)
@@ -417,7 +415,15 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece
             }
             printf("crcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
         #endif
+        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
+        {
+            return Uart_Rece_buffer;//此处指针移位出现重启问题
+        }
+        else //接收数据的校验不过屏蔽
+        {
+            osDelay(2000);
             memset(Uart_Rece_buffer,0x00,Data_Len);
+            USARTdrv->Initialize(USART_callback);
             return Uart_Rece_buffer;
         }
     }
@@ -426,6 +432,7 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece
         memset(Uart_Rece_buffer,0x00,Data_Len);
         isRecvTimeout = false;
         osDelay(100);
+        USARTdrv->Initialize(USART_callback);
         return Uart_Rece_buffer;
     }
 
@@ -452,7 +459,7 @@ static void Uart_Task(void* arg)
     int Rece_index = 0;
     volatile  uint8_t Data_Len;
     Uart_Receive_Type Uart_Receive_Msg;
-    memset(&battbuffer[0],0x00,100);
+    memset(&battbuffer[0],0x00,battbuffer_len);
 	PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
     slpManApplyPlatVoteHandle("UARTSLP",&UartSlpHandler);
     slpManPlatVoteDisableSleep(UartSlpHandler, SLP_SLP2_STATE); 
@@ -612,6 +619,7 @@ static void Uart_Task(void* arg)
                 #ifdef USING_PRINTF
                     printf("UART_STATE_SLEEP\n");
                 #endif
+                Uart_Sleep_Flag = true;
                 while(1)
                 {
                     osDelay(60000/portTICK_PERIOD_MS);
@@ -863,6 +871,7 @@ static void Can_Task(void* arg)
                         printf("[%d]We Can Check Vote can State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
                     #endif					
                 }
+                Can_Sleep_Flag = true;
                 while(true)
                 {
                     osDelay(60000/portTICK_PERIOD_MS);
@@ -1239,6 +1248,7 @@ static void Tcp_Task(void* arg)
                 #ifdef USING_PRINTF
                     printf("TCP_STATE_SLEEP\n");
                 #endif
+                Tcp_Sleep_Flag = TRUE;
                 while(1)
                 {
                     osDelay(30000/portTICK_PERIOD_MS);