wulianwei 3 weeks ago
parent
commit
2cc6afc652

+ 2 - 2
code/device/console.h

@@ -5,8 +5,8 @@
  *      Author: wulianwei
  */
 
-#ifndef UITL_UART_UTIL_H_
-#define UITL_UART_UTIL_H_
+#ifndef CODE_DEVICE_LWIP_CONSOLE_H_
+#define CODE_DEVICE_LWIP_CONSOLE_H_
 
 #define UART_RECV_SIZE 1024   //
 

+ 41 - 11
code/device/lwip.c

@@ -37,7 +37,7 @@ void lwip_device_init(void)
     while (ipAddr == 0)
     {
 #if STATIC_IP_ADDRESS
-        ipAddr = lwIPInit(0, macArray, STATIC_IP_ADDRESS, 0, 0,
+        ipAddr = lwIPInit(0, macArray, STATIC_IP_ADDRESS, STATIC_NET_MASK, 0,
         IPADDR_USE_STATIC);
 #else
     ipAddr = lwIPInit(0, macArray, 0, 0, 0, IPADDR_USE_DHCP);
@@ -45,6 +45,7 @@ void lwip_device_init(void)
         if (retry_count++ > 5)
         {
             ConsolePrintf("lwIPInit failed!.\r\n\r\n");
+            break;
         }
     }
 
@@ -86,6 +87,10 @@ err_t lwip_tcp_init(int port)
     return ERR_OK;
 }
 
+// 连接错误回调(可选)
+static void tcp_server_conn_err(void *arg, err_t err) {
+  ConsolePrintf("TCP 连接错误:%s\n", lwip_strerr(err));
+}
 
 
 /**
@@ -99,7 +104,7 @@ static err_t tcp_accept_handle(void *arg, struct tcp_pcb *pcb, err_t err)
     tcp_setprio(pcb, TCP_PRIO_MAX);
     /* Set up the various callback functions */
     tcp_recv(pcb, tcp_recv_handle);
-    tcp_err(pcb, NULL);
+    tcp_err(pcb, tcp_server_conn_err);
     tcp_poll(pcb, NULL, TCP_POLL_INTERVAL);
     tcp_sent(pcb, NULL);
 
@@ -122,7 +127,7 @@ static err_t tcp_recv_handle(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
         tcp_recved(pcb, p->tot_len);
     }
 
-    if ((err != ERR_OK) || (p == NULL))
+    if ((err != ERR_OK))
     {
         /* error or closed by other side */
         if (p != NULL)
@@ -134,7 +139,11 @@ static err_t tcp_recv_handle(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
     }
     cur_conn = pcb;
     //tcp_send_data(pcb ,p);
-    err_send = queue_send_data(p);
+    if(p!=NULL)
+    {
+        err_send = queue_send_data(p);
+    }
+
     return err_send;
 }
 
@@ -143,6 +152,7 @@ static err_t tcp_recv_handle(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
  */
 static void tcp_close_conn(struct tcp_pcb *pcb)
 {
+    ConsolePuts("tcp close", -1);
     tcp_recv(pcb, NULL);
     tcp_close(pcb);
     /* closing succeeded */
@@ -211,8 +221,11 @@ err_t queue_send_data(struct pbuf *p)
         char* data = (char*) p->payload;
         len = p->len;
         ConsolePuts("\r\ntcp rec data:\r\n", -1);
-        ConsolePutsHexStr(data, len);
-        enqueueFromEthernet(data, len);
+        if(len>0)
+        {
+            ConsolePutsHexStr(data, len);
+            enqueueFromEthernet(data, len);
+        }
         p = p->next;
     }
     while (p != NULL);
@@ -296,22 +309,34 @@ void lwip_udp_send_gui_signal(float *data, int flen, char channelFlag)
 
 /**
  * udp 向gui发送数据
- * data 浮点数据指针,  flen 数据数量, channelFlag 有效通道
+ * data 浮点数据指针,  len 数据数量, channelFlag 有效通道
  */
-void lwip_udp_send_gui_signal2(float *data1,float *data2,float *data3,float *data4, int flen, char channelFlag)
+void lwip_udp_send_gui_signal2(float *data1,float *data2,float *data3,float *data4, char channelFlag, int len)
 {
     unsigned char head[8]={'T','R',1,3,1,1};
-    int clen = sizeof(float)*flen;
+    int clen = sizeof(float)*len*4;
     int head_len = sizeof(head);
     int total_len = head_len+1+clen;
     head[6] = total_len>>8;
     head[7] = total_len;
-    unsigned char* fdata = malloc(total_len);
+    unsigned char* const fdata = malloc(total_len);
     memcpy(fdata,&head,head_len);
     fdata[head_len] = channelFlag;
+    unsigned char* cp = fdata+head_len+1;
+    int i = 0;
+    for(i=0; i<len; i++)
+    {
+        memcpy(cp+(i*sizeof(float)*4),data1++,sizeof(float));
+        memcpy(cp+(i*sizeof(float)*4)+4,data2++,sizeof(float));
+        memcpy(cp+(i*sizeof(float)*4)+8,data3++,sizeof(float));
+        memcpy(cp+(i*sizeof(float)*4)+12,data4++,sizeof(float));
+    }
+
     struct pbuf *pbuf = pbuf_alloc(PBUF_TRANSPORT, total_len,
                                    PBUF_REF);
     pbuf->payload = fdata;
+//    ConsolePuts("signal data:\n", -1);
+//    ConsolePutsHexStr(pbuf->payload, total_len);
     udp_send(gui_udp_pcb, pbuf);
     pbuf_free(pbuf);
     free(fdata);
@@ -336,7 +361,9 @@ void lwip_udp_send_vofa(float *data, int len)
     struct pbuf *pbuf = pbuf_alloc(PBUF_TRANSPORT, flen,
                                    PBUF_REF);
     pbuf->payload = fdata;
-    udp_send(gui_udp_pcb, pbuf);
+    ConsolePuts("signal data2:\n", -1);
+    ConsolePutsHexStr(pbuf->payload, flen);
+    //udp_send(gui_udp_pcb, pbuf);
     pbuf_free(pbuf);
     free(fdata);
 }
@@ -362,6 +389,7 @@ void lwip_udp_send_vofa2(float *data1, float *data2, int len)
     }
     struct pbuf *pbuf = pbuf_alloc(PBUF_TRANSPORT, flen,
                                    PBUF_REF);
+
     pbuf->payload = fdata;
     udp_send(gui_udp_pcb, pbuf);
     pbuf_free(pbuf);
@@ -393,6 +421,8 @@ void lwip_udp_send_vofa4(float *data1, float *data2,float *data3, float *data4,
     struct pbuf *pbuf = pbuf_alloc(PBUF_TRANSPORT, flen,
                                    PBUF_REF);
     pbuf->payload = fdata;
+//    ConsolePuts("\nsignal data2:\n", -1);
+//    ConsolePutsHexStr(pbuf->payload, flen);
     udp_send(gui_udp_pcb, pbuf);
     pbuf_free(pbuf);
     free(fdata);

+ 4 - 2
code/device/lwip.h

@@ -7,8 +7,8 @@
 #include "lwiplib.h"
 #include "lwipopts.h"
 
-#ifndef UITL_LWIP_UTIL_H_
-#define UITL_LWIP_UTIL_H_
+#ifndef CODE_DEVICE_LWIP_H_
+#define CODE_DEVICE_LWIP_H_
 
 #define LWIP_DEBUG   1
 
@@ -28,6 +28,8 @@ void lwip_udp_send_gui(unsigned char* data,int len);
 
 void lwip_udp_send_gui_signal(float *data, int flen, char channelFlag);
 
+void lwip_udp_send_gui_signal2(float *data1,float *data2,float *data3,float *data4, char channelFlag, int len);
+
 void lwip_udp_send_vofa2(float *data1, float *data2, int len);
 
 void lwip_udp_send_vofa4(float *data1, float *data2,float *data3, float *data4, int len);

+ 93 - 0
code/device/touch.c

@@ -0,0 +1,93 @@
+/*
+ * switch.c
+ *
+ *  Created on: 2025年11月6日
+ *      Author: wulianwei
+ */
+#include "nim_config.h"
+#include "tr_protocol.h"
+extern unsigned int TocuhTime; //触控时间
+
+extern unsigned char TocuhTrigger; //触控触发
+
+static char gui_power_status = 0; //gui开机状态,1:开机,0:关机
+
+void touch_opengui();
+
+void touch_deivce_init()
+{
+    GPIOBank0Pin11Init();
+    GPIOBank5Pin5Init();
+}
+
+/**
+ * 中断调用函数,尽快结束
+ */
+void touch_switch(int len)
+{
+    if(len)
+    {
+        TocuhTrigger = 0;
+        TocuhTime = TOUCH_TIME;
+        ConsolePuts("swith 1", -1);
+    }
+    else
+    {   TocuhTrigger = 1;
+        TocuhTime = TOUCH_TIME;
+        ConsolePuts("swith 0", -1);
+    }
+}
+
+
+
+/**
+ * 设置gui电源状态
+ */
+void setGuiPowerStatus(char value)
+{
+    gui_power_status = value;
+}
+void touch_askgui()
+{
+    trProtocol verPro;
+    ProtocolInit(&verPro);
+    ProtocolSetDestAddress(&verPro,3);
+    ProtocolSetSourceAddress(&verPro,1);
+    ProtocolSetType(&verPro,2);
+    ProtocolSetOptionChar(&verPro, 99, 2);//关机请求
+    ProtocolPackage(&verPro);
+    ConsolePuts("\n===shutdown request to gui\n", -1);
+    ConsolePutsHexStr(verPro.message, verPro.length);
+    lwip_tcp_send_gui(verPro.message,verPro.length);
+}
+
+//gui上电
+void touch_opengui()
+{
+    ConsolePuts("\n===open gui\n", -1);
+    GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_HIGH);
+    gui_power_status = 1;
+}
+//gui断电
+void touch_closegui()
+{
+    ConsolePuts("\n===close gui\n", -1);
+    GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_LOW);
+    gui_power_status = 0;
+}
+
+void touch_task()
+{
+    if(TocuhTime == 0)
+    {
+        TocuhTime = TOUCH_TIME;
+        if(gui_power_status)
+        {
+            touch_askgui();
+        }
+        else
+        {
+            touch_opengui();
+        }
+    }
+}

+ 19 - 0
code/device/touch.h

@@ -0,0 +1,19 @@
+/*
+ * switch.h
+ *
+ *  Created on: 2025Äê11ÔÂ6ÈÕ
+ *      Author: wulianwei
+ */
+
+#ifndef CODE_DEVICE_TOUCH_H_
+#define CODE_DEVICE_TOUCH_H_
+
+void touch_deivce_init();
+void touch_switch(int len);
+void setGuiPowerStatus(char value);
+void touch_opengui();
+void touch_closegui();
+void touch_task();
+
+
+#endif /* CODE_DEVICE_TOUCH_H_ */

+ 82 - 0
code/hal/nim_gpio.c

@@ -6,12 +6,17 @@
 
 #include "soc_C6748.h"
 #include "hw_syscfg0_C6748.h"
+#include "nim_config.h"
+
+int flag = 0;
 
 /****************************************************************************/
 /*                                                                          */
 /*              宏定义                                                      */
 /*                                                                          */
 /****************************************************************************/
+#define PINMUX0_GPIO0_11_ENABLE    (SYSCFG_PINMUX0_PINMUX0_19_16_GPIO0_11      << \
+                                    SYSCFG_PINMUX0_PINMUX0_19_16_SHIFT)
 
 #define PINMUX4_GPIO1_0_ENABLE    (SYSCFG_PINMUX4_PINMUX4_31_28_GPIO1_0      << \
                                     SYSCFG_PINMUX4_PINMUX4_31_28_SHIFT)
@@ -25,11 +30,24 @@
 #define PINMUX4_GPIO1_3_ENABLE    (SYSCFG_PINMUX4_PINMUX4_19_16_GPIO1_3      << \
                                     SYSCFG_PINMUX4_PINMUX4_19_16_SHIFT)
 
+#define PINMUX12_GPIO5_5_ENABLE    (SYSCFG_PINMUX12_PINMUX12_11_8_GPIO5_5      << \
+                                    SYSCFG_PINMUX12_PINMUX12_11_8_SHIFT)
+
+static void Bank0Handle(void);
+static void GPIOBank0InterruptInit();
 /****************************************************************************/
 /*                                                                          */
 /*              管脚复用配置                                                */
 /*                                                                          */
 /****************************************************************************/
+void GOIOBank0Pin11MuxMuxSetup(void)
+{
+    unsigned int savePinmux = 0;
+    savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) &
+            ~(SYSCFG_PINMUX0_PINMUX0_19_16));
+    HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) =
+             (PINMUX0_GPIO0_11_ENABLE | savePinmux);
+}
 
 void GOIOBank1Pin0MuxMuxSetup(void)
 {
@@ -67,3 +85,67 @@ void GOIOBank1Pin3MuxMuxSetup(void)
              (PINMUX4_GPIO1_3_ENABLE | savePinmux);
 }
 
+void GOIOBank5Pin5MuxMuxSetup(void)
+{
+    unsigned int savePinmux = 0;
+    savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(12)) &
+            ~(SYSCFG_PINMUX12_PINMUX12_11_8));
+    HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(12)) =
+             (PINMUX12_GPIO5_5_ENABLE | savePinmux);
+}
+
+/**
+ * GPIO0[11] 配置程输入模式,触控
+ */
+void GPIOBank0Pin11Init()
+{
+    GOIOBank0Pin11MuxMuxSetup();
+    // 触控输入
+    GPIODirModeSet(SOC_GPIO_0_REGS, 12, GPIO_DIR_INPUT);    // GPIO0[11]
+
+    GPIOBank0InterruptInit();
+}
+
+/**
+ * GPIO5[5] 配置程输入模式,GUI电源
+ */
+void GPIOBank5Pin5Init()
+{
+    GOIOBank5Pin5MuxMuxSetup();
+    // gui控制
+    GPIODirModeSet(SOC_GPIO_0_REGS, 86, GPIO_DIR_OUTPUT);    // GPIO5[5]
+
+    GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_LOW);
+
+}
+
+static void GPIOBank0InterruptInit()
+{
+    // 配置 触控 为上升沿及下降沿触发
+   GPIOIntTypeSet(SOC_GPIO_0_REGS, 12, GPIO_INT_TYPE_BOTHEDGE);
+    // 使能 GPIO BANK0 中断
+   GPIOBankIntEnable(SOC_GPIO_0_REGS, 0);
+   IntRegister(C674X_MASK_INT11, Bank0Handle);
+   IntEventMap(C674X_MASK_INT11, SYS_INT_GPIO_B0INT);
+   IntEnable(C674X_MASK_INT11);
+}
+
+static void Bank0Handle(void)
+{
+    // 禁用 GPIO BANK 0 中断
+    GPIOBankIntDisable(SOC_GPIO_0_REGS, 0);
+
+    // 清除 GPIO BANK 0 中断事件
+    IntEventClear(SYS_INT_GPIO_B0INT);
+
+    if(GPIOPinIntStatus(SOC_GPIO_0_REGS, 12) == GPIO_INT_PEND)
+    {
+        // 清除中断状态
+        GPIOPinIntClear(SOC_GPIO_0_REGS, 12);
+        int value = GPIOPinRead(SOC_GPIO_0_REGS, 12);
+        touch_switch(value);
+    }
+
+    // 使能 GPIO BANK 0 中断
+    GPIOBankIntEnable(SOC_GPIO_0_REGS, 0);
+}

+ 3 - 1
code/hal/nim_gpio.h

@@ -7,12 +7,14 @@
 
 #ifndef HAR_NIM_GPIO_H_
 #define HAR_NIM_GPIO_H_
-
+void GOIOBank0Pin11MuxMuxSetup(void);
 void GOIOBank1Pin0MuxMuxSetup();
 void GOIOBank1Pin1MuxMuxSetup();
 void GOIOBank1Pin2MuxMuxSetup();
 void GOIOBank1Pin3MuxMuxSetup();
 
+void GPIOBank0Pin11Init();
+void GPIOBank5Pin5Init();
 
 
 #endif /* HAR_NIM_GPIO_H_ */

+ 1 - 1
code/hlx/tr_led.c

@@ -18,7 +18,7 @@
 void LedInit(void){
     // 使能 GPIO 模块
     // 对相应外设模块的使能也可以在 BootLoader 中完成
-    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
+   // PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
 
     // 管脚复用配置,配置相应的 GPIO 口功能为普通输入输出口
     // 底板 LED

+ 1 - 1
code/hlx/tr_protocol.c

@@ -276,7 +276,7 @@ uint16_t ProtocolGetOption(uint8_t* message, uint16_t messageLength, uint16_t op
     trOptionStruct option_struct = getOption(message, messageLength, optionNumber);
     if (option_struct.valid)
     {
-        uint8_t i;
+        uint16_t i;
         for (i = 0; i < option_struct.length; i++)
         {
             optionValue[i] = message[option_struct.pos + option_struct.delta_ext + option_struct.length_ext + 1 + i];

+ 83 - 124
code/hlx/tr_queue_handler.c

@@ -25,6 +25,8 @@ void handleGUI(unsigned char *s, unsigned short sl);
 void dataForwardedHandle(unsigned char *s, unsigned short sl, unsigned char da)
 {
 //    printf("进入到数据转发!\r\n");
+    ConsolePuts("\n===dataForwardedHandle\n", -1);
+    ConsolePutsHexStr(s, sl);
     if (da == F4_ADDRESS)
     {
         // 执行发送到F4的逻辑
@@ -33,7 +35,7 @@ void dataForwardedHandle(unsigned char *s, unsigned short sl, unsigned char da)
     else if (da == GUI_ADDRESS)
     {
         // 执行发送到GUI的逻辑
-        lwip_udp_send_gui(s, sl);
+        lwip_tcp_send_gui(s, sl);
     }
     else if (da == UART_ADDRESS)
     {
@@ -111,78 +113,59 @@ void handleSign(unsigned char *s, unsigned short sl)
     }
 
     int dataCount = sl / FRAME_LEN; //每个通道数据量, 每三个字节代表一个采集信号. 大端模式.
-
-    float *const cd1 = malloc(sizeof(float) * dataCount);
-    float *const cd2 = malloc(sizeof(float) * dataCount);
-    float *const cd3 = malloc(sizeof(float) * dataCount);
-    float *const cd4 = malloc(sizeof(float) * dataCount);
-
-    static float fd1[COUNT_SIZE] = { 0.0 };
-    static float fd2[COUNT_SIZE] = { 0.0 };
-    static float fd3[COUNT_SIZE] = { 0.0 };
-    static float fd4[COUNT_SIZE] = { 0.0 };
-    static float fdgui[COUNT_SIZE * 4] = { 0.0 };
+    float *const fdata = malloc(sizeof(float) * dataCount*CHANNEL_COUNT*2);
+    float *const cd1 = fdata+dataCount*0;
+    float *const cd2 = fdata+dataCount*1;
+    float *const cd3 = fdata+dataCount*2;
+    float *const cd4 = fdata+dataCount*3;
+    float *const fd1 = fdata+dataCount*4;
+    float *const fd2 = fdata+dataCount*5;
+    float *const fd3 = fdata+dataCount*6;;
+    float *const fd4 = fdata+dataCount*7;
 
     const int FULL = 0x007fffff;
     const float FFULL = (float) FULL;
+    struct Frame *fm = NULL;
     int i = 0;
-    static int scount = 0;
     for (i = 0; i < dataCount; i++)
     {
-        struct Frame *fm = (struct Frame*) (s + FRAME_LEN * i);
+        fm = (struct Frame*) (s + FRAME_LEN * i);
         int origenData1 = fm->d1[0] << 24 | fm->d1[1] << 16 | fm->d1[2] << 8;
-        *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL) * 5000000+530; //将采集数据转成uV
 
         int origenData2 = fm->d2[0] << 24 | fm->d2[1] << 16 | fm->d2[2] << 8;
-        *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000000+570; //将采集数据转成uV
 
         int origenData3 = fm->d3[0] << 24 | fm->d3[1] << 16 | fm->d3[2] << 8;
-        *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000000+450; //将采集数据转成uV
 
         int origenData4 = fm->d4[0] << 24 | fm->d4[1] << 16 | fm->d4[2] << 8;
-        *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000000+440; //将采集数据转成uV
 
-        fd1[scount] = *(cd1 + i);
-        fd2[scount] = *(cd2 + i);
-        fd3[scount] = *(cd3 + i);
-        fd4[scount] = *(cd4 + i);
-        scount++;
-        if (scount == COUNT_SIZE)
-        {
-            scount = 0;
-            if (fm->sign & 0x01)
-            {
-                emg_denoised(cd1, COUNT_SIZE, 1000, fd1);
-            }
-            if (fm->sign & 0x02)
-            {
-                emg_denoised(cd2, COUNT_SIZE, 1000, fd2);
-            }
-            if (fm->sign & 0x04)
-            {
-                emg_denoised(cd3, COUNT_SIZE, 1000, fd3);
-            }
-            if (fm->sign & 0x08)
-            {
-                emg_denoised(cd4, COUNT_SIZE, 1000, fd4);
-            }
-            int m = 0;
-            for(m = 0; m<COUNT_SIZE; m++)
-            {
-                fdgui[m*CHANNEL_COUNT] = fd1[m];
-                fdgui[m*CHANNEL_COUNT+1] = fd2[m];
-                fdgui[m*CHANNEL_COUNT+2] = fd3[m];
-                fdgui[m*CHANNEL_COUNT+3] = fd4[m];
-            }
-            lwip_udp_send_gui_signal(fdgui,  COUNT_SIZE*CHANNEL_COUNT, fm->sign);
-        }
+    }
+    memcpy(fd1, cd1, dataCount);
+    memcpy(fd2, cd2, dataCount);
+    memcpy(fd3, cd3, dataCount);
+    memcpy(fd4, cd4, dataCount);
+    if (fm->sign & 0x01)
+    {
+        emg_denoised(cd1, dataCount, 1000, fd1);
+    }
+    if (fm->sign & 0x02)
+    {
+        emg_denoised(cd2, dataCount, 1000, fd2);
+    }
+    if (fm->sign & 0x04)
+    {
+        emg_denoised(cd3, dataCount, 1000, fd3);
+    }
+    if (fm->sign & 0x08)
+    {
+        emg_denoised(cd4, dataCount, 1000, fd4);
     }
 
-    free(cd1);
-    free(cd2);
-    free(cd3);
-    free(cd4);
-
+    lwip_udp_send_gui_signal2(fd1,fd2,fd3,fd4, fm->sign,dataCount);
+    free(fdata);
 }
 
 void handleSign2(unsigned char *s, unsigned short sl)
@@ -204,85 +187,57 @@ void handleSign2(unsigned char *s, unsigned short sl)
     }
 
     int dataCount = sl / FRAME_LEN; //每个通道数据量, 每三个字节代表一个采集信号. 大端模式.
-
-    float *const cd1 = malloc(sizeof(float) * dataCount);
-    float *const cd2 = malloc(sizeof(float) * dataCount);
-    float *const cd3 = malloc(sizeof(float) * dataCount);
-    float *const cd4 = malloc(sizeof(float) * dataCount);
-    static float fd1[COUNT_SIZE] = { 0.0 };
-    static float fd2[COUNT_SIZE] = { 0.0 };
-    static float fd3[COUNT_SIZE] = { 0.0 };
-    static float fd4[COUNT_SIZE] = { 0.0 };
+    float *const fdata = malloc(sizeof(float) * dataCount*CHANNEL_COUNT*2);
+    float *const cd1 = fdata+dataCount*0;
+    float *const cd2 = fdata+dataCount*1;
+    float *const cd3 = fdata+dataCount*2;
+    float *const cd4 = fdata+dataCount*3;
+    float *const fd1 = fdata+dataCount*4;
+    float *const fd2 = fdata+dataCount*5;
+    float *const fd3 = fdata+dataCount*6;;
+    float *const fd4 = fdata+dataCount*7;
 
     const int FULL = 0x007fffff;
     const float FFULL = (float) FULL;
+    struct Frame *fm = NULL;
     int i = 0;
-    static int scount = 0;
-
     for (i = 0; i < dataCount; i++)
     {
-        struct Frame *fm = (struct Frame*) (s + FRAME_LEN * i);
+        fm = (struct Frame*) (s + FRAME_LEN * i);
         int origenData1 = fm->d1[0] << 24 | fm->d1[1] << 16 | fm->d1[2] << 8;
-        *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL)  * 5000000+530; //将采集数据转成mV
 
         int origenData2 = fm->d2[0] << 24 | fm->d2[1] << 16 | fm->d2[2] << 8;
-        *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000000+470; //将采集数据转成mV
 
         int origenData3 = fm->d3[0] << 24 | fm->d3[1] << 16 | fm->d3[2] << 8;
-        *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000; //将采集数据转成mV
+        *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000000+450; //将采集数据转成mV
 
         int origenData4 = fm->d4[0] << 24 | fm->d4[1] << 16 | fm->d4[2] << 8;
-        *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000; //将采集数据转成mV
-        fd1[scount] = *(cd1 + i);
-        fd2[scount] = *(cd2 + i);
-        fd3[scount] = *(cd3 + i);
-        fd4[scount] = *(cd4 + i);
-        scount++;
-        if (scount == COUNT_SIZE)
-        {
-            scount = 0;
-            if (fm->sign & 0x01)
-            {
-                emg_denoised(cd1, COUNT_SIZE, 1000, fd1);
-            }
-            if (fm->sign & 0x02)
-            {
-                emg_denoised(cd2, COUNT_SIZE, 1000, fd2);
-            }
-            if (fm->sign & 0x04)
-            {
-                emg_denoised(cd3, COUNT_SIZE, 1000, fd3);
-            }
-            if (fm->sign & 0x08)
-            {
-                emg_denoised(cd4, COUNT_SIZE, 1000, fd4);
-            }
-            const int STEP = 100;
-            int pos = 0;
-            int left = 0;
-            do
-            {
-                int left = COUNT_SIZE - pos;
-                if (left <= STEP)
-                {
-                    lwip_udp_send_vofa4(cd1 + pos, cd2 + pos, cd3 + pos,
-                                        cd4 + pos, left);
-                }
-                else
-                {
-                    lwip_udp_send_vofa4(cd1 + pos, cd2 + pos, cd3 + pos,
-                                        cd4 + pos, STEP);
-                    pos += STEP;
-                }
-            }
-            while (left > STEP);
-        }
+        *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000000+440; //将采集数据转成mV
     }
-
-    free(cd1);
-    free(cd2);
-    free(cd3);
-    free(cd4);
+    memcpy(fd1, cd1, dataCount);
+    memcpy(fd2, cd2, dataCount);
+    memcpy(fd3, cd3, dataCount);
+    memcpy(fd4, cd4, dataCount);
+    if (fm->sign & 0x01)
+    {
+        emg_denoised(cd1, dataCount, 1000, fd1);
+    }
+    if (fm->sign & 0x02)
+    {
+        emg_denoised(cd2, dataCount, 1000, fd2);
+    }
+    if (fm->sign & 0x04)
+    {
+        emg_denoised(cd3, dataCount, 1000, fd3);
+    }
+    if (fm->sign & 0x08)
+    {
+        emg_denoised(cd4, dataCount, 1000, fd4);
+    }
+    lwip_udp_send_vofa4(fd1, fd2 , fd3 ,fd4 , dataCount);
+    free(fdata);
 
 }
 
@@ -292,7 +247,7 @@ void handleGUI(unsigned char *s, unsigned short sl)
     ConsolePutsHexStr(s, sl);
     unsigned char check = 0;
     int a = ProtocolGetOption(s,sl,99,&check);
-    if(a)
+    if(a == 1)
     {
         unsigned char udpAdd[8] = {0};
         trProtocol verPro;
@@ -300,12 +255,16 @@ void handleGUI(unsigned char *s, unsigned short sl)
         ProtocolSetDestAddress(&verPro,3);
         ProtocolSetSourceAddress(&verPro,1);
         ProtocolSetType(&verPro,2);
-        //ProtocolSetOption(&verPro,98,sizeof(udpAdd),udpAdd);
         ProtocolSetOptionChar(&verPro, 100, 1);
+        ProtocolSetPayload(&verPro,sizeof(udpAdd),udpAdd);
         ProtocolPackage(&verPro);
         ConsolePuts("\n===handleGUI to gui version\n", -1);
         ConsolePutsHexStr(verPro.message, verPro.length);
         lwip_tcp_send_gui(verPro.message,verPro.length);
     }
+    else if(a == 3)
+    {
+        touch_closegui();
+    }
 }
 

+ 14 - 0
code/hlx/tr_timer.c

@@ -6,6 +6,12 @@
  *      定时不大准,需要精准定时,试用芯片提供的定时器
  */
 #include "tr_timer.h"
+#include "nim_config.h"
+
+// 定时器
+unsigned int TocuhTime = TOUCH_TIME; //触控时间
+
+unsigned char TocuhTrigger = 0; //触控触发
 
 // 定时器
 static unsigned int BaseTime = 0;
@@ -13,6 +19,14 @@ static unsigned int BaseTime = 0;
 void BaseTimeIncremental(void)
 {
     BaseTime++;
+
+    if(TocuhTrigger && TocuhTime--)
+    {
+        if(TocuhTime == 0)
+        {
+            TocuhTrigger = 0;
+        }
+    }
 }
 
 unsigned int GetPassedTime(struct TimerStruct * timer)

+ 3 - 1
code/hlx/usbhspecific.c

@@ -237,10 +237,12 @@ unsigned int USBHSPECIFICWrite(unsigned char *pucData, unsigned int ulSize)
 //
 //*****************************************************************************
 #include <stdio.h>
+#include "device/console.h"
 unsigned char DataBuffer1[64] = {'\0'};
 static void *
 SPECIFICDriverOpen(tUSBHostDevice *pDevice, unsigned int ulInstance)
 {
+    ConsolePuts("SPECIFICDriverOpen...\r\n",-1);
     printf("SPECIFICDriverOpen...\r\n");
     unsigned int ulIndex = 0;
 
@@ -278,7 +280,7 @@ static void
 SPECIFICDriverClose(void *pvInstance)
 {    
     g_SPECIFICInstance.isConnected = false;
-
+    ConsolePuts("SPECIFICDriverClose...\r\n",-1);
     printf("SPECIFICDriverClose...\r\n");
 //    tSPECIFICInstance *pSPECIFICInstance;
 //    pSPECIFICInstance = (tSPECIFICInstance *)pvInstance;

+ 2 - 2
led_test.c

@@ -12,7 +12,7 @@ void Delay(unsigned int n);
 
 void LedTest()
 {
-    PSCInit();
+    //PSCInit();
     GPIOBankPinMuxSet();
     GPIOBankPinInit();
     for(; ;)
@@ -44,7 +44,7 @@ void PSCInit(void)
 {
     // 使能 GPIO 模块
     // 对相应外设模块的使能也可以在 BootLoader 中完成
-    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
+    //PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
 }
 
 void GPIOBankPinMuxSet()

+ 12 - 3
main.c

@@ -8,16 +8,16 @@
 
 #define LEN_IP_ADDR                    (4u)
 #define ASCII_NUM_IDX                  (48u)
-
+extern int flag ;
 void DeviceInit();
 
 int main()
 {
+    printf("======DSP START======\n");
     DeviceInit();
-    ConsolePuts("\r\n ============NIM DSP START===========.\r\n", -1);
-    lwip_tcp_init(TCP_SERVER_PORT); //开启本设备TCP服务器
     for (;;)
     {
+        touch_task();
         HlxMain();
     }
 }
@@ -34,14 +34,23 @@ void InterruptInit(void)
     IntGlobalEnable();
 }
 
+void PSCIni()
+{
+    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
+}
+
 /**
  * 设备初始化
  */
 void DeviceInit()
 {
     InterruptInit();
+    PSCIni();
     ConsoleDeviceInit();//控制台初始化
+    ConsolePuts("\r\n ============NIM DSP START===========.\r\n", -1);
+    touch_deivce_init();
     lwip_device_init(); //以太网模块初始化
+    lwip_tcp_init(TCP_SERVER_PORT); //开启本设备TCP服务器
     HlxInit();
 }
 

+ 10 - 3
nim_config.h

@@ -8,6 +8,7 @@
 #ifndef NIM_CONFIG_H_
 #define NIM_CONFIG_H_
 
+#include <device/touch.h>
 #include <string.h>
 #include <stdio.h>
 
@@ -16,12 +17,15 @@
 #include "hw_syscfg0_C6748.h"
 #include "soc_C6748.h"
 #include "psc.h"
+#include "gpio.h"
 #include "interrupt.h"
+#include "hal/nim_gpio.h"
 #include "hal/nim_uart.h"
 #include "hal/nim_ethernet.h"
 #include "util/sys_util.h"
 #include "device/console.h"
 #include "device/lwip.h"
+#include "device/touch.h"
 #include "algorithm/emg_util.h"
 
 
@@ -33,12 +37,15 @@
 
 #define TCP_SERVER_PORT                   2000
 
-//#define STATIC_IP_ADDRESS               0xC0A801C8  //192.168.1.200
+//#define STATIC_IP_ADDRESS               0xC0A80164  //192.168.1.100
 
-//#define UI_IP_ADDRESS               0xC0A801C9  //192.168.1.201
-#define UI_IP_ADDRESS               0xC0A80169  //192.168.1.101
+#define STATIC_NET_MASK               0xFFFFFF00  //255.255.255.0
+
+#define UI_IP_ADDRESS               0xC0A80196  //192.168.1.10
 
 #define UI_UDP_PORT                 8000
 
+#define TOUCH_TIME                  3000    //´¥¿ØÊ±¼ä 3s
+
 
 #endif /* NIM_CONFIG_H_ */