Ver Fonte

fix dhcp (increase timeout)
rewrite eth test

balbekova há 7 anos atrás
pai
commit
00cc1838d7

+ 33 - 6
service_hw/Commands/bt_6701_commands.c

@@ -57,6 +57,11 @@ extern BUTTON_NO_FIX_t defButton;
 extern uint8_t SetCounter;
 extern BUTTON_NO_FIX_t setButton;
 
+/**
+  * @brief  Флаг ининциализации Eth интерфейса
+  */
+extern unsigned char eth_ready_flag;
+
 // -------------------------------------------------------------------------- //
 //                              __weak функции
 
@@ -315,15 +320,37 @@ void COM_TestSPIflash(void)
 void Test_Ethernet(void)
 {
     static bool ethernetInit = false;
+    int timeout = 100; /* 10 sec timeout */
   
-    if (ethernetInit == false)
+   // if (ethernetInit == false)
     {
-        ethernetInit = true;
-        COM_SetMAC();
-        ETH_BSP_Config();
-        LwIP_Init();
-        sys_thread_new("HTTP", vTaskTcpServer, NULL, 4*configMINIMAL_STACK_SIZE, tskIDLE_PRIORITY);
+        if (eth_ready_flag == 0) {
+        	if(!ethernetInit){
+        		ethernetInit = true;
+				COM_SetMAC();
+				ETH_BSP_Config();
+				 LwIP_Init();
+        	}
+        	else{
+        		init_get_ip_address_controller();
+        	}
+        }
+        /* Waiting ETH init */
+        while ((eth_ready_flag == 0) && (timeout-- > 0)) {
+            vTaskDelay(100);
+        }
+
+        if (eth_ready_flag == 0) {
+            printf("ETH FAIL\r\n");
+        }
+        else {
+            sys_thread_new("HTTP", vTaskTcpServer, NULL, 4*configMINIMAL_STACK_SIZE, tskIDLE_PRIORITY);
+            ethernetInit = true;
+        }
     }
+  /*  else {
+        printf("ETH OK\r\n");
+    }*/
    
 	TEST_SetTest(TEST_WAIT);
 }

+ 12 - 2
service_hw/Commands/commands_api.c

@@ -13,6 +13,7 @@
 #include "stm32f4xx.h"  
 #include "commands_api.h"
 #include "settings_api.h"
+#include "sys_api.h"
 #include "buttons.h"
 #include "led.h"
 #include "parameters.h"
@@ -67,11 +68,17 @@ extern char STM_ID[33];
 extern char STM_ID_HEX[12];
 uint8_t MAC[6];
 
+/**
+  * @brief  Общая структура настроек
+  */
+extern SETTINGS_t sSettings;
+
 /**
   * @brief  
   */
 void vTestCommands(void *params)
 {
+
     for (;;)
     {
         if (fUpdatable) {
@@ -304,13 +311,16 @@ void COM_SetMAC(void)
 
   /* Восьмой бит первого октета должен быть равен 0 */
 
-  MAC[0] = octet1 & 0xFE;
+/*  MAC[0] = octet1 & 0xFE;
   MAC[1] = octet2;
   MAC[2] = octet3;
 
   MAC[3] = 0x00;
   MAC[4] = 0x00;
-  MAC[5] = 0x00;
+  MAC[5] = 0x00;*/
+
+  /* Устанавливаем MAC, но не сохраняем */
+  snprintf(sSettings.sInfo.mac, MAC_LEN, "%02X-%02X-%02X-00-00-00", octet1 & 0xFE, octet2, octet3);
 
 }
 

+ 1 - 1
service_hw/Ethernet/lwipopts.h

@@ -151,7 +151,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
  - To use this feature let the following define uncommented.
  - To disable it and process by CPU comment the  the checksum.
 */
-#define CHECKSUM_BY_HARDWARE 
+#define CHECKSUM_BY_HARDWARE
 
 
 #ifdef CHECKSUM_BY_HARDWARE

+ 54 - 10
service_hw/Ethernet/netconf.c

@@ -30,11 +30,22 @@
   */
 struct netif xnetif; 
 
+
+/**
+  * @brief  Флаг ининциализации Eth интерфейса
+  */
+unsigned char eth_ready_flag = 0;
+
 /**
   * @brief  Задача получения сетевый параметров по DHCP протоколу
   */
 TaskHandle_t xHandleDHCP = NULL;
 
+/**
+  * @brief  Общая структура настроек
+  */
+extern SETTINGS_t sSettings;
+
 
 void LwIP_Init(void)
 {
@@ -62,6 +73,11 @@ void LwIP_Init(void)
                 tskIDLE_PRIORITY + 2, &xHandleDHCP);
 }
 
+void init_get_ip_address_controller(void){
+	 xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,
+	                tskIDLE_PRIORITY + 2, &xHandleDHCP);
+}
+
 /**
   * @brief  LwIP_DHCP_Process_Handle
   * @param  None
@@ -117,6 +133,11 @@ void LwIP_DHCP_task(void * pvParameters)
           
 		  printf("ETH OK\r\n");
 		  
+		  /* Установлен динамический IP. *
+		   * Ждем инициализацию интерфейса и выставляем флаг готовности. */
+		  vTaskDelay(2000);
+		  eth_ready_flag = 1;
+
           vTaskDelete(xHandleDHCP);
         }
         else
@@ -124,15 +145,38 @@ void LwIP_DHCP_task(void * pvParameters)
           /* DHCP timeout */
           if (dhcpTry++ > MAX_DHCP_TRIES)
           {
-            DHCP_state = DHCP_TIMEOUT;
-
-            /* Stop DHCP */
-            dhcp_stop(&xnetif);
-			
-			/* Сообщение о неудачной попытке получить IP */
-			printf("ETH FAIL\r\n");
-			
-			vTaskDelete(xHandleDHCP);
+              DHCP_state = DHCP_TIMEOUT;
+
+              /* Stop DHCP */
+              dhcp_stop(&xnetif);
+
+  		/*	if (sSettings.sFlags.netsettingsChanged == true)
+  		    {
+  			  ipaddr.addr = ipaddr_addr(sSettings.sWebTempParams.ip);
+  	          netmask.addr = ipaddr_addr(sSettings.sWebTempParams.mask);
+  	          gw.addr = ipaddr_addr(sSettings.sWebTempParams.gate);
+  			}
+  			else
+  			{
+  			  ipaddr.addr = ipaddr_addr(sSettings.sWebParams.ip);
+  	          netmask.addr = ipaddr_addr(sSettings.sWebParams.mask);
+  	          gw.addr = ipaddr_addr(sSettings.sWebParams.gate);
+  			}
+
+              //Static address used
+              netif_set_addr(&xnetif, &ipaddr , &netmask, &gw);
+
+              printf("DHCP timeout\n\r");
+              printf("\n\rStatic IP address\n\r");
+  			printf(ipaddr_ntoa(&ipaddr));
+  		    printf("\n\r");*/
+
+  		    /* Установлен динамический IP. *
+  		    * Ждем инициализацию интерфейса и выставляем флаг готовности. */
+  		    vTaskDelay(2000);
+  		    eth_ready_flag = 0;
+
+  			vTaskDelete(xHandleDHCP);
           }
         }
       }
@@ -141,7 +185,7 @@ void LwIP_DHCP_task(void * pvParameters)
       default: break;
     }
 
-    vTaskDelay(250);
+    vTaskDelay(1250);
   }   
 }
 

+ 1 - 0
service_hw/Ethernet/netconf.h

@@ -44,6 +44,7 @@ void LwIP_Init(void);
 
 void LwIP_DHCP_task(void * pvParameters);
 
+void init_get_ip_address_controller(void);
 
 #ifdef __cplusplus
 }