TelenkovDmitry 7 vuotta sitten
vanhempi
commit
dce26dacb8
8 muutettua tiedostoa jossa 86 lisäystä ja 34 poistoa
  1. 3 3
      config/common_config.h
  2. 1 1
      iap/User/main.c
  3. 9 5
      modules/log/log.c
  4. 32 4
      modules/log/ringfs.c
  5. 1 0
      modules/sys_api.c
  6. 17 8
      modules/testing/testing.c
  7. 19 12
      user/init_task.c
  8. 4 1
      user/main.c

+ 3 - 3
config/common_config.h

@@ -62,7 +62,7 @@
 /**
   * @brief  Таймаут возврата в основное ПО, сек.
   */
-#define UPDATE_TIMEOUT  60
+#define UPDATE_TIMEOUT  10*60
 
 #define USER_FLASH_FIRST_PAGE_ADDRESS 0x08020000 /* Only as example see comment */
 #define USER_FLASH_LAST_PAGE_ADDRESS  0x08060000
@@ -81,7 +81,7 @@
 /**
   * @brief  Отладочный порт USART и консоль
   */
-#define USART_DEBUG_ENABLE
+//#define USART_DEBUG_ENABLE
 
 #define SYSTEMTICK_PERIOD_MS  1
 
@@ -115,7 +115,7 @@
   * @brief  SNMP протокол
   */
 #if defined HARDWARE_BT6702
-//#define SNMP_ENABLE
+#define SNMP_ENABLE
 #endif
 
 /**

+ 1 - 1
iap/User/main.c

@@ -154,7 +154,7 @@ void main(void)
 //    SD_NVIC_Init();
   } else {
     IAPviaETH = true;
-    timer_AddFunction(500, &LED_Blinky_Green);
+    timer_AddFunction(500, &LED_Blinky_Red);
   }
   
   /* Check if valid stack address (RAM address) */

+ 9 - 5
modules/log/log.c

@@ -114,7 +114,7 @@ void log_task(void* params)
 	for(;;){
 		flUpdateLog = true;
 		vTaskDelay(LOG_TIME);
-	/*	vTaskDelay(50);
+		/*vTaskDelay(50);
 		log_event_data(LOG_SYSTEM_BOOT, "Администратор");
 		log_add(")215.7;215.7;220.5;000;50.1;2.30;25.0;00000001;");*/
 	}
@@ -129,16 +129,20 @@ void log_init(bool format) {
 	ringfs_flash.sector_count = spi_flash_desc.sector_count/2 - LOG_FLASH_SECTOR_OFFSET;
 
 	ringfs_init(&fs, &ringfs_flash, LOG_ENTRY_VERSION, sizeof(log_entry_t));
-	if (format || ringfs_scan(&fs) != 0)
+	if (format || ringfs_scan(&fs) != 0){
+		DBG printf("FAT1 false\r\n");
 		ringfs_format(&fs);
-
+	}
+	DBG printf("FAT1 true\r\n");
 	ringfs_flash2.sector_size = spi_flash_desc.sector_size;
 	ringfs_flash2.sector_count = spi_flash_desc.sector_count/2 - LOG_FLASH_SECTOR_OFFSET;
 
 	ringfs_init(&fs2, &ringfs_flash2, LOG_ENTRY_VERSION, sizeof(log_entry_t));
-	if (format || ringfs_scan(&fs2) != 0)
+	if (format || ringfs_scan(&fs2) != 0){
+		DBG printf("FAT2 false\r\n");
 		ringfs_format(&fs2);
-
+	}
+	DBG printf("FAT2 true\r\n");
 	fLogInit = true;
 
 	log_mutex = xSemaphoreCreateMutex();

+ 32 - 4
modules/log/ringfs.c

@@ -191,6 +191,8 @@ int ringfs_scan(struct ringfs *fs)
     /* If there's no IN_USE sector, we start at the first one. */
     bool used_seen = false;
 
+    bool err_sector = true;
+
     /* Iterate over sectors. */
     for (int sector=0; sector<fs->flash->sector_count; sector++) {
         int addr = _sector_address(fs, sector);
@@ -202,7 +204,15 @@ int ringfs_scan(struct ringfs *fs)
         /* Detect partially-formatted partitions. */
         if (header.status == SECTOR_FORMATTING) {
         	DBG printf("ringfs_scan: partially formatted partition\r\n");
-            return -1;
+        	if(err_sector){
+				err_sector = false;
+				_sector_free(fs, addr);
+				//fs->flash->read(fs->flash, addr, &header, sizeof(header));
+				header.status = SECTOR_FREE;
+				header.version = fs->version;
+			}else{
+				return -1;
+			}
         }
 
         /* Detect and fix partially erased sectors. */
@@ -214,14 +224,32 @@ int ringfs_scan(struct ringfs *fs)
         /* Detect corrupted sectors. */
         if (header.status != SECTOR_FREE && header.status != SECTOR_IN_USE) {
         	DBG printf("ringfs_scan: corrupted sector %d\r\n", sector);
-            return -1;
+        	if(err_sector){
+				err_sector = false;
+				_sector_free(fs, addr);
+				//fs->flash->read(fs->flash, addr, &header, sizeof(header));
+				header.status = SECTOR_FREE;
+				header.version = fs->version;
+			}else{
+				return -1;
+			}
         }
 
         /* Detect obsolete versions. We can't do this earlier because the version
          * could have been invalid due to a partial erase. */
         if (header.version != fs->version) {
-            DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
-            return -1;
+        	DBG printf("ringfs_scan: corrupted sector %d\r\n", sector);
+        	DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
+            if(err_sector){
+            	err_sector = false;
+            	_sector_free(fs, addr);
+            	//fs->flash->read(fs->flash, addr, &header, sizeof(header));
+            	DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
+            	header.status = SECTOR_FREE;
+            	header.version = fs->version;
+            }else{
+            	return -1;
+            }
         }
 
         /* Record the presence of a FREE sector. */

+ 1 - 0
modules/sys_api.c

@@ -84,6 +84,7 @@ bool SYS_SetDefault(SYS_t *settings) {
 
 	snprintf(settings->customer, CUST_LEN, SYS_CUSTOMER);
 	snprintf(settings->proddate, PROD_LEN, "00.00.00");
+	snprintf(settings->testState, 5, "T2OK");
 	settings->controlword = SETTINGS_CONTROL_WORD;
 
 	return true;

+ 17 - 8
modules/testing/testing.c

@@ -16,6 +16,7 @@
 #include "common_config.h"
 #include "stm32_uid.h"
 #include "led.h"
+#include "hal.h"
 
 #include "FreeRTOS.h"
 #include "task.h"
@@ -42,11 +43,11 @@ bool fServer = false;
 
 
 #define MSG_LEN   300
-char msg[MSG_LEN];
 
-uint8_t ID[33];
+char ID[33];
 
 extern SETTINGS_t   sSettings;       // Общая структура настроек
+extern bool isIpReceived;
 
 /**
   * @brief  Тестирование
@@ -54,15 +55,21 @@ extern SETTINGS_t   sSettings;       // Общая структура настр
 // TODO Убрать заглушки
 void vTaskTesting(void *params)
 {
-	uint8_t len;
+  uint8_t len;
+  
+  while (!isIpReceived) {
+    vTaskDelay(100);
+  }    
+  
   for (;;)
-  {
+  {    
 	  //printf("Start testing task\r\n");
-  
+	  memset(ID, 0, 33);
 	  /* Читаем ID */
 	  GetSTM32IDStr(ID, &len);
 	  
 	  /* Отправляем запрос */
+      vTaskDelay(3000);
 	  TEST_SendData();
 	  
 	  /* Ждем timeout и высылаем ответ на тестер */
@@ -77,6 +84,8 @@ void vTaskTesting(void *params)
 
         LED_Off(LED_INIT_R);
 	    fServer = false;
+	    vTaskDelay(2000);
+	    Reboot();
 	    vTaskDelete(NULL);
       }
       
@@ -92,12 +101,12 @@ void TEST_SendData(void)
   struct netconn *conn;
   struct netbuf *buf;
   char *data;
+  char msg[MSG_LEN];
   err_t err;
-  char str[20] = {0};
    
   /* Отправляем сообщение на сервер по UDP */
   memset(msg, 0, MSG_LEN);
-  
+ 
   conn = netconn_new( NETCONN_UDP );
   
   if (conn!= NULL)
@@ -122,7 +131,7 @@ void TEST_SendData(void)
 	  strcat(msg, VERSION);
 	  strcat(msg, ";;;");
       
-	  for (uint8_t i = 0; i < 12; i++) 
+	//  for (uint8_t i = 0; i < 12; i++)
 	  {
 		 strcat(msg, ID);
 	  }	

+ 19 - 12
user/init_task.c

@@ -78,6 +78,8 @@ void InitTask(void *params)
 // -----------------------------------------------------------------------------    
   InitUSART();
   ups_megatec_init();
+
+  log_init(false);
 // -----------------------------------------------------------------------------    
  // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
   //SETTINGS_SetDefaultDebug();
@@ -135,13 +137,25 @@ void InitTask(void *params)
 #ifdef NET_ENABLE
   ETH_BSP_Config();
   LwIP_Init();
+  
 #ifdef WEB_SERVER_ENABLE
-  //HTTP_Init();
-  HTTPS_Init();
+  if(strncmp(sSettings.sFlags.testState, "T2OK", 4)){
+
+	  HTTP_Init();
+  	  xTaskCreate(vTaskTesting, "Testing", 2*configMINIMAL_STACK_SIZE,
+                NULL, tskIDLE_PRIORITY, NULL);
+    }
+  else{
+	   HTTPS_Init();
 #define SSL_TASK_PRIO   ( configMAX_PRIORITIES - 3 )
-  xTaskCreate(ssl_server, "SSL", 10*configMINIMAL_STACK_SIZE, NULL, SSL_TASK_PRIO, NULL); 
+	   xTaskCreate(ssl_server, "SSL", 10*configMINIMAL_STACK_SIZE, NULL, SSL_TASK_PRIO, NULL);
 #endif
+	   // UDP for net settings 
+	  	  UDP_netsetting_init();
+  }
+
 
+  
 #ifdef SNMP_ENABLE
 
   SNMP_Init();
@@ -154,7 +168,7 @@ void InitTask(void *params)
    
 #endif	
     
- 
+#endif  
 // -----------------------------------------------------------------------------      
 	 /* SNTP */
 	 SNTP_Init();
@@ -162,11 +176,9 @@ void InitTask(void *params)
 				 NULL, tskIDLE_PRIORITY, &xHandleSntpOnceSinhro);
 	 xTaskCreate(vTaskPeriodicSynchro, "sntpPeriodicSinhro", 2*configMINIMAL_STACK_SIZE,
 				 NULL, tskIDLE_PRIORITY, NULL);
-#endif      
 // -----------------------------------------------------------------------------  
 
-	 /* UDP for net settings */
-	  UDP_netsetting_init();
+
 // Тестирование
     
   // Тест таблицы трапов  
@@ -179,11 +191,6 @@ void InitTask(void *params)
 #endif  
 // -----------------------------------------------------------------------------      
 
- /* if(strncmp(sSettings.sFlags.testState, "T2OK", 4)){
-	  xTaskCreate(vTaskTesting, "Testing", configMINIMAL_STACK_SIZE,
-              NULL, tskIDLE_PRIORITY, NULL);
-  }*/
-
   //TEST_InitRS485();
   //TEST_IO();
   

+ 4 - 1
user/main.c

@@ -3,6 +3,7 @@
 #include "FreeRTOS.h"
 #include "task.h"
 #include "common_config.h"
+#include "settings_api.h"
 
 #include "gpio.h"
 
@@ -50,10 +51,12 @@ int main()
 	WDG_Init();
 
 	spi_flash_init();
-	log_init(false);
+	//log_init(false);
 	//log_test();
 	//spi_flash_test();
 //  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
+
+	init_settings();
   
   xTaskCreate( InitTask, "InitTask", 1000, NULL, tskIDLE_PRIORITY, NULL);