Pārlūkot izejas kodu

add test rtc, set, spiflash

balbekova 7 gadi atpakaļ
vecāks
revīzija
96d108b7e6

+ 1 - 1
peripheral_modules/inc/spi_flash.h

@@ -36,5 +36,5 @@ extern ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout)
 extern ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
 extern int spi_flash_erase_sector(int addr, uint32_t timeout);
 extern int spi_flash_chip_erase(uint32_t timeout);
-extern void spi_flash_test(void);
+extern bool spi_flash_test(void);
 #endif /* SPI_FLASH_H */

+ 21 - 14
peripheral_modules/src/spi_flash.c

@@ -339,10 +339,13 @@ uint8_t txbuf1[] = "This film came out on DVD yesterday and I rushed to buy it.
 		    restoration work will be needed to make the image absolutely perfect. \
 		    But let's concentrate on the positive: This film is a summit of visual \
 		    splendour and its sets, costumes, colour photography, composition and lighting \
+            achieve, in every single scene, wonders of artistry, creativity and delicacy \
+		    But let's concentrate on the positive: This film is a summit of visual \
+		    splendour and its sets, costumes, colour photography, composition and lighting \
 		    achieve, in every single scene, wonders of artistry, creativity and delicacy \
 		    that will probably never be equalled. Suffice it to say that it has, \
 		    among many other treasures, a sunrise duel scene in the snow that still has viewers \
-		    wondering whether it was shot outdoors or in a studio and that will have them wondering forever.\r\n";
+		    wondering whether it was shot outdoors or in a studio and that will have them wondering foreverhsgkhgkshgu.\r\n";
 
 uint8_t txbuf2[] = "STM32F4xx SPI Firmware Library Example: communication with an M25P SPI FLASH\r\n";
 
@@ -353,30 +356,34 @@ uint8_t txbuf2[] = "STM32F4xx SPI Firmware Library Example: communication with a
 uint8_t  rxbuf1[bufsize1] = {0};
 uint8_t  rxbuf2[bufsize2] = {0};
 
-void spi_flash_test(void) {
+bool spi_flash_test(void) {
+
+	uint16_t i;
     if (!spi_flash_init())
-	return;
+	return false;
     int ret = 0, addr = 0, offset = 0;
+    for(i = 0; i < spi_flash_desc.sector_count; i ++){
+		//spi_flash_read(i*spi_flash_desc.sector_size, rxbuf1, bufsize1, 0);
+		spi_flash_erase_sector(i*spi_flash_desc.sector_size,0);
+		//spi_flash_read(0, rxbuf1, bufsize1, 0);
 
-    spi_flash_read(0, rxbuf1, bufsize1, 0);
-    spi_flash_erase_sector(0,0);
-    spi_flash_read(0, rxbuf1, bufsize1, 0);
-    
-    spi_flash_write(addr, txbuf1, bufsize1, 0);
+		spi_flash_write(i*spi_flash_desc.sector_size, txbuf1, bufsize1, 0);
 
-    memset(rxbuf1, 0, bufsize1);
-    spi_flash_read(0, rxbuf1, bufsize1, 0);
+		memset(rxbuf1, 0, bufsize1);
+		spi_flash_read(i*spi_flash_desc.sector_size, rxbuf1, bufsize1, 0);
 
-    if (memcmp(txbuf1, rxbuf1, bufsize1) != 0)
-	return;
+		if (memcmp(txbuf1, rxbuf1, bufsize1) != 0)
+		return false;
 
-    spi_flash_erase_sector(0,0);
+    }
+    return true;
+    /*spi_flash_erase_sector(0,0);
     spi_flash_read(0, rxbuf1, bufsize1, 0);
 
     spi_flash_write(0, txbuf2, bufsize2, 0);
 
     memset(rxbuf2, 0, bufsize2);
-    spi_flash_read(0, rxbuf2, bufsize2, 0);
+    spi_flash_read(0, rxbuf2, bufsize2, 0);*/
 
 
 /*

+ 84 - 0
service_hw/Commands/bt_6701_commands.c

@@ -26,6 +26,7 @@
 #include "d_inouts.h"
 #include "config_service.h"
 #include "usart.h"
+#include "spi_flash.h"
 
 #include "FreeRTOS.h"
 #include "task.h"
@@ -43,10 +44,15 @@
 
 #include <string.h>
 
+bool ntpResult = false;
+uint32_t SNTP_Time;
 
 extern uint8_t DefCounter;
 extern BUTTON_NO_FIX_t defButton;
 
+extern uint8_t SetCounter;
+extern BUTTON_NO_FIX_t setButton;
+
 // -------------------------------------------------------------------------- //
 //                              __weak функции
 
@@ -184,6 +190,84 @@ void vTest_DEF(void *params)
     
 }
 
+/**
+  * @brief
+  */
+void vTest_SET(void *params)
+{
+    static uint32_t timeout_set = 0;
+
+    for (;;)
+    {
+        if (timeout_set++ > BUTTON_TIMEOUT) {
+            timeout_set = 0;
+            SetCounter = 0;
+            LED_Off(LED_INIT_G);
+			LED_Off(LED_MINOR_G);
+            printf("SET FAIL\r\n");
+            TEST_SetTest(TEST_WAIT);
+            ifTest_SET = false;
+            vTaskDelete(NULL);
+        }
+
+        BUTTON_NoFixHandler(&setButton);
+
+        if (SetCounter == 3)
+        {
+            timeout_set = 0;
+            SetCounter = 0;
+            printf("SET OK\r\n");
+
+            /* Завершение теста T0 */
+            /* Устанавливаем статус T0READY, сохраняем статус во флеш */
+            COM_SetTestState(T0READY);
+
+            TEST_SetTest(TEST_WAIT);
+            ifTest_SET = false;
+            vTaskDelete(NULL);
+        }
+
+        vTaskDelay(10);
+    }
+
+}
+
+/**
+  * @brief  Тестирование RTC
+  */
+void COM_TestRtc(void)
+{
+  /* Пытаемся синхронизироваться с NTP сервером */
+  SNTP_Enable(true);
+  SNTP_Poll();
+  vTaskDelay(1000);
+
+  /* Синхронизация удалась */
+  if (ntpResult) {
+    printf("RTC OK\r\n");
+  }
+  else
+    printf("RTC FAIL SYNC\r\n");
+
+  TEST_SetTest(TEST_WAIT);
+}
+
+/**
+  * @brief  Тестирование SPIFLASH
+  */
+void COM_TestSPIflash(void)
+{
+
+  if (spi_flash_test()) {
+    printf("SPIFLASH OK\r\n");
+  }
+  else
+    printf("SPIFLASH FAIL SYNC\r\n");
+
+  TEST_SetTest(TEST_WAIT);
+}
+
+
 /**
   * @brief  
   */

+ 16 - 1
service_hw/Commands/commands_api.c

@@ -47,6 +47,7 @@ static TEST_t testState = TEST_WAIT;
 
 
 bool ifTest_DEF = false;
+bool ifTest_SET = false;
 bool macWaiting = false;
 bool macIsInstalled = false;
 bool fUpdatable = false;
@@ -107,13 +108,27 @@ void vTestCommands(void *params)
             break;
 
             case TEST_DEF :
-                
                 if (!ifTest_DEF) {
                     ifTest_DEF = true;
                     xTaskCreate(vTest_DEF, "DEF_Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
                 }
             break;
 
+            case TEST_SET :
+            	if (!ifTest_SET) {
+					ifTest_SET = true;
+					xTaskCreate(vTest_SET, "SET_Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+				}
+            break;
+
+            case TEST_RTC :
+            	COM_TestRtc();
+            break;
+
+            case TEST_SPIFLASH :
+            	COM_TestSPIflash();
+            break;
+
             case TEST_ETHERNET :
                 Test_Ethernet();
             break;

+ 8 - 3
service_hw/Commands/commands_api.h

@@ -22,14 +22,15 @@
 typedef enum
 {
     TEST_WAIT = 0,
-    TEST_U232U485,
     TEST_DRY,
     TEST_U232F,
     TEST_DEF,
+    TEST_SET,
+    TEST_RTC,
+    TEST_SPIFLASH,
     TEST_ETHERNET,
     TEST_SERNO,
-    
-    
+
 } TEST_t;
 
 typedef enum
@@ -52,6 +53,9 @@ void Test_U232U485(void);
 void Test_DRY(void);
 void Test_U232F(void);
 void vTest_DEF(void *params);
+void vTest_SET(void *params);
+void COM_TestRtc(void);
+void COM_TestSPIflash(void);
 void Test_Ethernet(void);
 void Test_Serno(void);
 
@@ -68,6 +72,7 @@ void TEST_SetTest(TEST_t state);
 
 
 extern bool ifTest_DEF;
+extern bool ifTest_SET;
 extern bool macWaiting;
 extern bool macIsInstalled;
 extern bool fUpdatable;

+ 18 - 3
service_hw/Console/port_microrl.c

@@ -79,6 +79,8 @@
 
 #define _CMD_RST         "reset"
 
+#define _CMD_SPIFLASH    "SPIFLASH"
+
 // arguments for set/clear
 #define _SCMD_PB  "port_b"
 #define _SCMD_PD  "port_d"
@@ -132,7 +134,9 @@ char * keyworld [] = {
   _CMD_DRY,
   _CMD_U232F,
   
-  _CMD_RST
+  _CMD_RST,
+
+  _CMD_SPIFLASH
 };
 
 // 'set/clear' command argements
@@ -232,7 +236,8 @@ int execute (int argc, const char * const * argv)
 	  /* Тест кнопки SET */
 	  else if (strcmp (argv[i], _CMD_SET) == 0) 
       {
-		testSet = true;
+		//testSet = true;
+		TEST_SetTest(TEST_SET);
 		print ("\n\r");
 		return 0;
       }
@@ -252,7 +257,8 @@ int execute (int argc, const char * const * argv)
           len = strlen(argv[i]);
           strncpy(param, argv[i], len);
 		  SNTP_SetServerAddr(param);
-		  testRtc = true;
+		  TEST_SetTest(TEST_RTC);
+		 // testRtc = true;
           print ("\n\r");
           return 0;
         }
@@ -294,6 +300,15 @@ int execute (int argc, const char * const * argv)
 		print ("\n\r");
 		return 0;
       }
+
+	  /* Тест spi flash */
+	  else if (strcmp (argv[i], _CMD_SPIFLASH) == 0)
+	   {
+		//testSet = true;
+		 TEST_SetTest(TEST_SPIFLASH);
+		print ("\n\r");
+		return 0;
+	   }
       
 	  /* -------------------------------------------------------------------- */
 	  /*                          Тесты этапа Т2                              */

+ 1 - 1
service_hw/Ethernet/netconf.c

@@ -56,7 +56,7 @@ void LwIP_Init(void)
   /* Проверяем наличие линка */
   reg = ETH_ReadPHYRegister(0, 1);
 
-  if (reg & 4) 
+ // if (reg & 4)
     xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,
                 tskIDLE_PRIORITY + 2, &xHandleDHCP);
 }

+ 27 - 2
service_hw/buttons/buttons.c

@@ -20,8 +20,10 @@
 #include "task.h"
 
 BUTTON_NO_FIX_t defButton;
+BUTTON_NO_FIX_t setButton;
 
 uint8_t DefCounter = 0;
+uint8_t SetCounter = 0;
 
 /**
   * @brief  
@@ -38,6 +40,16 @@ void BUTTON_Init(void)
   defButton.fActivation       = false;
     
   defButton.stateOld     = BUTTON_GetState(&defButton);
+
+  setButton.id_pin			  = MODE_JUMPER;
+  setButton.timeDelay         = 5;
+  setButton.pressHandler      = BUTTON_SET_UpHandler;
+  setButton.unpressHandler    = BUTTON_SET_DownHandler;
+  setButton.counterActivation = 0;
+  setButton.timeActivation    = 40;
+  setButton.fActivation       = false;
+
+  setButton.stateOld     = BUTTON_GetState(&setButton);
 	
 }
 
@@ -176,11 +188,24 @@ void BUTTON_DEF_DownHandler(void)
 }
 
 /**
-  * @brief  Хендлер кнопки SET. Переход в bootloader
+  * @brief  Хендлер кнопки SET.
+  */
+void BUTTON_SET_UpHandler(void)
+{
+   LED_On(LED_INIT_G);
+	LED_On(LED_MINOR_G);
+}
+
+
+/**
+  * @brief  Хендлер кнопки SET
   */
 void BUTTON_SET_DownHandler(void)
 {
-  //HTTP_StartResetTask(true);
+	SetCounter++;
+
+    LED_Off(LED_INIT_G);
+	LED_Off(LED_MINOR_G);
 }
 
 

+ 5 - 0
service_hw/buttons/buttons.h

@@ -84,6 +84,11 @@ void BUTTON_DEF_UpHandler(void);
   */
 void BUTTON_DEF_DownHandler(void);
 
+/**
+  * @brief
+  */
+void BUTTON_SET_UpHandler(void);
+
 /**
   * @brief  Хендлер кнопки SET
   */