Forráskód Böngészése

[service_sw] rewrite rs-485 test

balbekova 5 éve
szülő
commit
3db77733ba

+ 1 - 20
service_hw/Commands/commands_api.c

@@ -62,7 +62,6 @@ bool testRtc = false;
 bool testSerno = false;
 bool testT2Ready = false;
 bool testSet = false;
-bool testRS485 = false;
 
 #define MSG_LEN   300
 char msg[MSG_LEN];
@@ -205,25 +204,7 @@ void TEST_SetTest(TEST_t state)
     if (state == TEST_WAIT)
         testState = state;
 }
-#ifdef PORTGW_ENABLE
-/**
-  * @brief  Отправка данных по интерфейсу RS485
-  */
-void COM_TestRS485(char *str, uint8_t len)
-{
-  if (str) {
-    for (uint8_t i = 0; i < len; i ++) {
-      str[i] = ~str[i];
-    }
-    uint8_t sent = rs485_send_block((uint8_t *)str, len);
-    sprintf(msg, "RS485 sent %d bytes", sent);
-    print(msg);
-  }
-  print("\r\n");
-  testRS485 = false;
-  return;
-}
-#endif
+
 /**
   * @brief  Считать статут тестирования (T0, T1, etc)
   */

+ 1 - 21
service_hw/Console/port_microrl.c

@@ -81,7 +81,6 @@
 
 #define _CMD_SPIFLASH    "SPIFLASH"
 #define _CMD_U232        "U232"
-#define _CMD_U485        "U485"
 
 // arguments for set/clear
 #define _SCMD_PB  "port_b"
@@ -139,8 +138,7 @@ char * keyworld [] = {
   _CMD_RST,
 
   _CMD_SPIFLASH,
-  _CMD_U232,
-  _CMD_U485
+  _CMD_U232
 };
 
 // 'set/clear' command argements
@@ -321,24 +319,6 @@ int execute (int argc, const char * const * argv)
         print ("\n\r");
         return 0;
       }
-#endif
-#ifdef PORTGW_ENABLE
-      /* Отправка данных по интерфейсу RS485 (прием не проверяется) */
-      else if (strcmp (argv[i], _CMD_U485) == 0)
-      {
-        if (++i < argc)
-        {
-          len = strlen(argv[i]);
-          len = len < PARAM_LEN ? len : PARAM_LEN - 1;
-          strncpy(param, argv[i], len);
-          COM_TestRS485(param, len);
-        }
-        else {
-          COM_TestRS485(NULL, 0);
-        }
-        //print ("\n\r");
-        return 0;
-      }
 #endif
 	  /* -------------------------------------------------------------------- */
 	  /*                          Тесты этапа Т2                              */

+ 8 - 0
service_hw/Hardware/hw_init.c

@@ -25,6 +25,9 @@
 #include "spi_flash.h"
 #include "stm32_uid.h"
 #include "port_microrl.h"
+#ifdef RS485_USART
+#include "rs485_echo.h"
+#endif
 
 #include "FreeRTOS.h"
 #include "task.h"
@@ -88,6 +91,11 @@ void BT_6702_Init(void)
 
     time_test = RTC_GetUnixTime();
 
+#ifdef RS485_USART
+    /* RS485 echo loop */
+    rs485echo_init();
+#endif
+
     xTaskCreate(service_com_task, ( char * ) "service_com_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
     // Создает таски для выполнения команд тестера 
     xTaskCreate(vTestCommands, "TestProcessing", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);

+ 2 - 0
service_hw/Makefile

@@ -33,6 +33,7 @@ INCLUDES += -IHardware
 INCLUDES += -ICommands
 INCLUDES += -ISettings
 INCLUDES += -IConsole
+INCLUDES += -Irs_485
 INCLUDES += -I.
 
 CSRC = $(wildcard ../stm32/stm32f4xx_spl/src/*.c)
@@ -44,6 +45,7 @@ CSRC += $(wildcard Hardware/*.c)
 CSRC += $(wildcard Commands/*.c)
 CSRC += $(wildcard Settings/*.c)
 CSRC += $(wildcard Console/*.c)
+CSRC += $(wildcard rs_485/*.c)
 CSRC += $(wildcard *.c)
 
 INCLUDES += -Ileds

+ 51 - 0
service_hw/rs_485/rs485_echo.c

@@ -0,0 +1,51 @@
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include "queue.h"
+
+#include <stdint.h>
+#include "tinystdio.h"
+
+#include "usart.h"
+
+#ifdef RS485_USART
+
+#undef DBG
+#define DBG if(0)
+
+#define RS485_BUFSIZE   256
+
+static uint8_t buf[RS485_BUFSIZE];
+
+
+static void rs485_thread(void *arg)
+{
+    (void)arg;
+
+    while (1) {
+        /* Get packet */
+        uint16_t n = 0;
+        xQueueReceive(rs485RxQ, &buf[n++], portMAX_DELAY);
+        while (xQueueReceive(rs485RxQ, &buf[n], 10) == pdTRUE && n < RS485_BUFSIZE) {
+            n++;
+        }
+        /* Echo inverted packet */
+        uint16_t i = 0;
+        while (i < n) {
+            uint8_t byte = ~buf[i++];
+            if (xQueueSend(rs485TxQ, &byte, 1000) == pdTRUE) {
+                rs485_enable_tx();
+            } else {
+                DBG printf("[echo] rx data lost\r\n");
+                return;
+            }
+        }
+    }
+}
+
+void rs485echo_init(void)
+{
+    xTaskCreate(rs485_thread, ( char * ) "rs485_thr", configMINIMAL_STACK_SIZE,
+        NULL, tskIDLE_PRIORITY, NULL);
+}
+#endif

+ 7 - 0
service_hw/rs_485/rs485_echo.h

@@ -0,0 +1,7 @@
+
+#include "common_config.h" 
+#include "usart.h"
+
+#ifdef RS485_USART  
+void rs485echo_init(void);
+#endif