樊春春 1 سال پیش
والد
کامیت
ae50c8c1a2
45فایلهای تغییر یافته به همراه2556 افزوده شده و 3485 حذف شده
  1. 2 1
      .gitignore
  2. 4 2
      CMakeLists.txt
  3. 17 10
      Project/GCC/STM32F417IG_FLASH.ld
  4. 6 0
      Project/GCC/cmake/gcc-arm-none-eabi.cmake
  5. 43 26
      Project/conf/lwip/lwip_dm9k.c
  6. 2 2
      Project/conf/lwip/lwip_init.c
  7. 54 138
      Project/conf/lwip/port/ethernetif_dm9k.c
  8. 117 26
      Project/main.c
  9. 6 3
      Project/main.h
  10. 12 0
      Project/stm32f4xx_it.c
  11. 3 4
      User/Bsp/armfly_bsp.c
  12. 1 1
      User/Bsp/armfly_bsp.h
  13. 34 52
      User/Bsp/dm9k/dm9k.c
  14. 3 2
      User/Bsp/dm9k/dm9k.h
  15. 1 1
      User/Bsp/ext_sram/ext_sram.c
  16. 14 40
      User/Bsp/interface/interface.c
  17. 1 4
      User/Bsp/interface/interface.h
  18. 11 11
      User/Bsp/iwdg/iwdg.c
  19. 3 3
      User/Bsp/iwdg/iwdg.h
  20. 0 214
      User/Bsp/uart/uart6.c
  21. 0 20
      User/Bsp/uart/uart6.h
  22. 616 0
      User/app/air/air.c
  23. 139 0
      User/app/air/air.h
  24. 0 92
      User/app/esp8266/esp8266.c
  25. 0 18
      User/app/esp8266/esp8266.h
  26. 8 8
      User/app/fly_param.c
  27. 14 15
      User/app/fly_param.h
  28. 0 1358
      User/app/iec104/iec101.c
  29. 0 199
      User/app/iec104/iec101.h
  30. 231 242
      User/app/iec104/iec104.c
  31. 52 52
      User/app/iec104/iec104.h
  32. 9 11
      User/app/iec104/iec104_conf.h
  33. 59 26
      User/app/iec104/iec104_init.c
  34. 334 0
      User/app/iec104/iec104_queue.c
  35. 88 129
      User/app/iec104/iec104_queue.h
  36. 0 2
      User/app/iec104/iec104_types.h
  37. 0 213
      User/app/iec104/iec10x.c
  38. 0 148
      User/app/iec104/iec10x_prio_queue.c
  39. 0 6
      User/app/iec104/iec10x_prio_queue.h
  40. 83 297
      User/app/modbus/modbus.c
  41. 48 68
      User/app/modbus/modbus.h
  42. 187 40
      User/app/net/net.c
  43. 15 1
      User/app/net/net.h
  44. 228 0
      User/app/pcs/pcs.c
  45. 111 0
      User/app/pcs/pcs.h

+ 2 - 1
.gitignore

@@ -10,6 +10,7 @@
 .idea
 .idea/
 
+.cache
 Project/GCC/build
-
+compile_commands.json
 **/Thumbs.db

+ 4 - 2
CMakeLists.txt

@@ -14,6 +14,9 @@ set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS ON)
 
+#添加的部分,关闭警告
+add_definitions(-w)
+
 # MCU 参数设置
 set(MCU_PARAMS
         -mthumb
@@ -107,7 +110,6 @@ set(INC_C_DIRS
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/eth
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/ext_sram
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/dwt
-        ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/esp8266
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/interface
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/iwdg
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/lcd
@@ -119,7 +121,6 @@ set(INC_C_DIRS
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/uart
         ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/usbh
         ${CMAKE_CURRENT_SOURCE_DIR}/User/app
-        ${CMAKE_CURRENT_SOURCE_DIR}/User/app/esp8266
         ${CMAKE_CURRENT_SOURCE_DIR}/User/app/iec104
         ${CMAKE_CURRENT_SOURCE_DIR}/User/app/key
         ${CMAKE_CURRENT_SOURCE_DIR}/User/app/queue
@@ -197,6 +198,7 @@ target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
         -Wno-unused-but-set-variable
         -Wno-unused-function
         -Wno-unused-parameter
+        -Wno-format=
         # -Wno-volatile
         # -Wold-style-cast
         # -Wuseless-cast

+ 17 - 10
Project/GCC/STM32F417IG_FLASH.ld

@@ -41,8 +41,9 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
 MEMORY
 {
 FLASH (rx)      : ORIGIN = 0x8010000, LENGTH = 1024K
-RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K
-CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 64K
+RW_IRAM1 (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K
+RW_IRAM2 (rw)      : ORIGIN = 0x10000000, LENGTH = 64K
+EXTSRAM (rw)     : ORIGIN = 0x68000000,  LENGTH = 2048K
 }
 
 /* Define output sections */
@@ -123,7 +124,7 @@ SECTIONS
 
     . = ALIGN(4);
     _edata = .;        /* define a global symbol at data end */
-  } >RAM AT> FLASH
+  } >RW_IRAM1 AT> FLASH
 
   _siccmram = LOADADDR(.ccmram);
 
@@ -137,12 +138,10 @@ SECTIONS
   {
     . = ALIGN(4);
     _sccmram = .;       /* create a global symbol at ccmram start */
-    KEEP(*(ccmram))
+    KEEP(*(RAM_ERR))
     . = ALIGN(4);
     _eccmram = .;       /* create a global symbol at ccmram end */
-  } >CCMRAM AT> FLASH
-
-  
+  } >RW_IRAM2 AT> FLASH
   /* Uninitialized data section */
   . = ALIGN(4);
   .bss :
@@ -157,7 +156,7 @@ SECTIONS
     . = ALIGN(4);
     _ebss = .;         /* define a global symbol at bss end */
     __bss_end__ = _ebss;
-  } >RAM
+  } >RW_IRAM1
 
   /* User_heap_stack section, used to check that there is enough RAM left */
   ._user_heap_stack :
@@ -168,9 +167,17 @@ SECTIONS
     . = . + _Min_Heap_Size;
     . = . + _Min_Stack_Size;
     . = ALIGN(4);
-  } >RAM
+  } >RW_IRAM1
 
-  
+    /* external sram data, do not initialize at startup  */
+  .ext_sram(NOLOAD) :
+  {
+    . = ALIGN(4);
+    _sext_sram = .;        /* create a global symbol at ext_sram start */
+    KEEP(*(EXT_SRAM))
+    . = ALIGN(4);
+    _eext_sram = .;        /* define a global symbol at ext_sram end */
+  } >EXTSRAM AT> FLASH
 
   /* Remove information from the standard libraries */
   /DISCARD/ :

+ 6 - 0
Project/GCC/cmake/gcc-arm-none-eabi.cmake

@@ -18,3 +18,9 @@ set(CMAKE_EXECUTABLE_SUFFIX_C       ".elf")
 set(CMAKE_EXECUTABLE_SUFFIX_CXX     ".elf")
 
 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
+if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+  execute_process(
+    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json
+  )
+endif()

+ 43 - 26
Project/conf/lwip/lwip_dm9k.c

@@ -6,7 +6,7 @@
 #include "malloc.h"
 #include "memory_manager.h"
 
-struct netif dm9k_netif = {0}; // 定义一个网络接口
+struct netif dm9k_netif; // 定义一个网络接口
 
 #define DM9K_TASK_PRIO     10
 #define DM9K_TASK_STK_SIZE 512
@@ -16,39 +16,39 @@ static void ethernet_link_status_updated(struct netif *netif);
 void lwip_dm9k_default_ip_set(__lwip_dev *lwipx)
 {
 
-    //默认远端IP为:192.168.1.100
+    // 默认远端IP为:192.168.1.100
     lwipx->remoteip[0] = 192;
     lwipx->remoteip[1] = 168;
     lwipx->remoteip[2] = 1;
     lwipx->remoteip[3] = 10;
 
     // MAC地址设置(高三字节固定为:2.0.0,低三字节用STM32唯一ID)
-    lwipx->mac[0] = 2; //高三字节(IEEE称之为组织唯一ID,OUI)地址固定为:2.0.0
+    lwipx->mac[0] = 2; // 高三字节(IEEE称之为组织唯一ID,OUI)地址固定为:2.0.0
     lwipx->mac[1] = 0;
     lwipx->mac[2] = 0;
-    lwipx->mac[3] = 0x90; //低三字节用STM32的唯一ID
+    lwipx->mac[3] = 0x90; // 低三字节用STM32的唯一ID
     lwipx->mac[4] = 0x00;
     lwipx->mac[5] = 0xae;
 
-    //默认本地IP为:192.168.1.30
+    // 默认本地IP为:192.168.1.30
     lwipx->ip[0] = 192;
     lwipx->ip[1] = 168;
     lwipx->ip[2] = 1;
     lwipx->ip[3] = 40;
 
-    //默认子网掩码:255.255.255.0
+    // 默认子网掩码:255.255.255.0
     lwipx->netmask[0] = 255;
     lwipx->netmask[1] = 255;
     lwipx->netmask[2] = 255;
     lwipx->netmask[3] = 0;
 
-    //默认网关:192.168.1.1
+    // 默认网关:192.168.1.1
     lwipx->gateway[0] = 192;
     lwipx->gateway[1] = 168;
     lwipx->gateway[2] = 1;
     lwipx->gateway[3] = 1;
 
-    lwipx->dhcpstatus = 0; //没有DHCP
+    lwipx->dhcpstatus = 0; // 没有DHCP
 }
 
 void ethernet_dm9k_link_thread(void const *argument)
@@ -68,39 +68,56 @@ void lwip_dm9k_init(void)
     ip4_addr_t ipaddr;
     ip4_addr_t netmask;
     ip4_addr_t gw;
+    uint8_t    linkchanged = 0;
 
-    lwip_dm9k_default_ip_set(&dm9kdev); //设置默认IP等信息
+    lwip_dm9k_default_ip_set(&dm9kdev); // 设置默认IP等信息
     dm9k_init();
 
-#ifdef USE_DHCP //使用动态IP
+#ifdef USE_DHCP // 使用动态IP
     ip_addr_set_zero_ip4(&ipaddr);
     ip_addr_set_zero_ip4(&netmask);
     ip_addr_set_zero_ip4(&gw);
-#else //使用静态IP
+#else // 使用静态IP
     IP4_ADDR(&ipaddr, dm9kdev.ip[0], dm9kdev.ip[1], dm9kdev.ip[2], dm9kdev.ip[3]);
     IP4_ADDR(&netmask, dm9kdev.netmask[0], dm9kdev.netmask[1], dm9kdev.netmask[2], dm9kdev.netmask[3]);
     IP4_ADDR(&gw, dm9kdev.gateway[0], dm9kdev.gateway[1], dm9kdev.gateway[2], dm9kdev.gateway[3]);
 #endif
 
-    netif_add(&dm9k_netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_dm9k_init, &tcpip_input); //向网卡列表中添加一个网口
-    netif_set_default(&dm9k_netif);                                                            //设置netif为默认网口
-
+    netif_add(&dm9k_netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_dm9k_init, &tcpip_input); // 向网卡列表中添加一个网口
+    netif_set_default(&dm9k_netif);                                                            // 设置netif为默认网口
+    printf("LwIP Registers dm9k_netif default network interface....\r\n");
     /* Set the link callback function, this function is called on change of link status*/
 #if LWIP_NETIF_LINK_CALLBACK
     netif_set_link_callback(&dm9k_netif, ethernet_link_status_updated);
 #endif
 
-    OSTaskCreateExt((void (*)(void *))ethernet_dm9k_link_thread,
-                    (void const *)&dm9k_netif,
-                    (OS_STK *)&dm9k_task_stk[DM9K_TASK_STK_SIZE - 1],
-                    (INT8U)DM9K_TASK_PRIO,
-                    (INT16U)DM9K_TASK_PRIO,
-                    (OS_STK *)&dm9k_task_stk[0],
-                    (INT32U)DM9K_TASK_STK_SIZE,
-                    (void *)0,
-                    (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
-
-    // if (DM9K_LINK_STATUS == 1)
+    // OSTaskCreateExt((void (*)(void *))ethernet_dm9k_link_thread,
+    //                 (void const *)&dm9k_netif,
+    //                 (OS_STK *)&dm9k_task_stk[DM9K_TASK_STK_SIZE - 1],
+    //                 (INT8U)DM9K_TASK_PRIO,
+    //                 (INT16U)DM9K_TASK_PRIO,
+    //                 (OS_STK *)&dm9k_task_stk[0],
+    //                 (INT32U)DM9K_TASK_STK_SIZE,
+    //                 (void *)0,
+    //                 (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
+
+    linkchanged = dm9k_linkstat();
+
+    if (netif_is_link_up(&dm9k_netif) && (linkchanged == 0))
+    {
+        printf("dm9k LwIP Error interface....\r\n");
+        netif_set_down(&dm9k_netif);
+        netif_set_link_down(&dm9k_netif);
+    }
+    else if (!netif_is_link_up(&dm9k_netif) && (linkchanged == 1))
+    {
+        printf("dm9k LwIP Finish interface....\r\n");
+        netif_set_up(&dm9k_netif);
+        netif_set_link_up(&dm9k_netif);
+    }
+
+    // ethernet_link_check_state(&dm9k_netif);
+    //  if (ethernet_link_check_state() == 1)
     // {
     //     dm9k_netif.flags |= NETIF_FLAG_LINK_UP;
     //     netif_set_up(&dm9k_netif);
@@ -137,7 +154,7 @@ static void ethernet_link_status_updated(struct netif *netif)
         IP4_ADDR(&netmask, dm9kdev.netmask[0], dm9kdev.netmask[1], dm9kdev.netmask[2], dm9kdev.netmask[3]);
         IP4_ADDR(&gw, dm9kdev.gateway[0], dm9kdev.gateway[1], dm9kdev.gateway[2], dm9kdev.gateway[3]);
 
-        dm9kdev.dhcpstatus = DHCP_ADDRESS_ASSIGNED; //标记网络开启成功。
+        dm9kdev.dhcpstatus = DHCP_ADDRESS_ASSIGNED; // 标记网络开启成功。
 #endif /* USE_DHCP */
     }
     else

+ 2 - 2
Project/conf/lwip/lwip_init.c

@@ -8,10 +8,10 @@ __lwip_dev dm9kdev = {0}; // lwip控制结构体
 // LWIP初始化(LWIP启动的时候使用)
 void lwip_setup(void)
 {
-    //初始化tcp ip内核,该函数里面会创建tcpip_thread内核任务
+    // 初始化tcp ip内核,该函数里面会创建tcpip_thread内核任务
     tcpip_init(NULL, NULL);
 
     lwip_eth_setup();
 
-    lwip_dm9k_init();
+    // lwip_dm9k_init();
 }

+ 54 - 138
Project/conf/lwip/port/ethernetif_dm9k.c

@@ -4,12 +4,11 @@
 #include "lwip/tcpip.h"
 #include "lwip/timeouts.h"
 #include "lwip_dm9k.h"
-#include "memory_manager.h"
+#include "lwip_init.h"
 #include "netif/etharp.h"
 #include "netif/ethernet.h"
-// #include "snmp.h"
-#include "lwip_init.h"
 #include "string.h"
+#include <stdio.h>
 
 #define DM9K_RX_TASK_PRIO     4
 #define DM9K_RX_TASK_STK_SIZE 2048
@@ -32,38 +31,17 @@ static void pbuf_free_custom(struct pbuf *p);
 static void ethernetif_input(void *pvParameters);
 // static void ethernet_link_check_state(struct netif *netif);
 
-static OS_EVENT     *g_dm9k_rx_sem = NULL;
-static OS_EVENT     *dm9k_mutex    = NULL;
-static struct netif *low_netif     = NULL;
-/*
-*********************************************************************************************************
-*	函 数 名: VariableMemInit
-*	功能说明: 申请串口相关的变量内存
-*	形    参: 无
-*	返 回 值: 无
-*********************************************************************************************************
-*/
-static void VariableMemInit(void)
-{
-    uint16_t idx = 0;
+static OS_EVENT *g_dm9k_rx_sem = NULL;
+static OS_EVENT *g_dm9k_tx_sem = NULL;
+// static OS_EVENT     *dm9k_mutex    = NULL;
+static struct netif *low_netif = NULL;
 
-    for (idx = 0; idx < DM9K_RX_DESC_CNT; idx++)
-    {
-        if (Rx_Buff[idx] == 0)
-            Rx_Buff[idx] = pMemoryMalloc(&SRAM0, DM9K_RX_Lenth); // 因为不释放,避免重复申请
-        if (custom_pbuf[idx] == 0)
-            custom_pbuf[idx] = pMemoryMalloc(&SRAM0, sizeof(struct pbuf_custom)); // 因为不释放,避免重复申请
-    }
-}
 static void low_level_init(struct netif *netif)
 {
-    INT32U idx = 0;
-    VariableMemInit();
-    INT8U err;
     /* set MAC hardware address length */
     netif->hwaddr_len = ETHARP_HWADDR_LEN;
 
-    /* set MAC hardware address */ /* 网卡的 MAC 修改2 */
+    /* 网卡的 MAC 修改2 */
     netif->hwaddr[0] = dm9kdev.mac[0];
     netif->hwaddr[1] = dm9kdev.mac[1];
     netif->hwaddr[2] = dm9kdev.mac[2];
@@ -80,16 +58,6 @@ static void low_level_init(struct netif *netif)
 
     low_netif = netif;
 
-    for (idx = 0; idx < DM9K_RX_DESC_CNT; idx++)
-    {
-        custom_pbuf[idx]->custom_free_function = pbuf_free_custom;
-    }
-
-    if (NULL == dm9k_mutex)
-    {
-        dm9k_mutex = OSMutexCreate(1, &err);
-    }
-
     /* create binary semaphore used for informing ethernetif of frame reception */
     if (NULL == g_dm9k_rx_sem)
     {
@@ -105,27 +73,10 @@ static void low_level_init(struct netif *netif)
                     (INT32U)DM9K_RX_TASK_STK_SIZE,
                     (void *)0,
                     (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
-    // ethernet_link_check_state(netif);
 }
 
-/**
- * @brief This function should do the actual transmission of the packet. The packet is
- * contained in the pbuf that is passed to the function. This pbuf
- * might be chained.
- *
- * @param netif the lwip network interface structure for this ethernetif
- * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
- * @return ERR_OK if the packet could be sent
- *         an err_t value if the packet couldn't be sent
- *
- * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
- *       strange results. You might consider waiting for space in the DMA queue
- *       to become available since the stack doesn't retry to send a packet
- *       dropped because of memory failure (except for the TCP timers).
- */
 static err_t low_level_output(struct netif *netif, struct pbuf *p)
 {
-
     INT8U        err;
     err_t        errval = ERR_OK;
     uint32_t     i = 0, framelen = 0, calc_len = 0;
@@ -133,10 +84,16 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
 
     SYS_ARCH_DECL_PROTECT(sr);
 
-    OSMutexPend(dm9k_mutex, 1000, &err);
+    if (NULL == g_dm9k_tx_sem)
+    {
+        g_dm9k_tx_sem = OSSemCreate(1);
+    }
+
+    OSSemPend(g_dm9k_tx_sem, 0, &err);
+
     SYS_ARCH_PROTECT(sr);
 
-    dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 dm9kA 中断 */
+    // dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 dm9kA 中断 */
 
     NET_REG_ADDR = DM9K_REG_MWCMD;
 
@@ -157,41 +114,40 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
     dm9k_WriteReg(DM9K_REG_TCR, DM9K_TCR_SET); /* 进行传送 */
 
     while ((dm9k_ReadReg(DM9K_REG_ISR) & 0x02) == 0)
-        ;                                      /* 等待发送完成	 */
-    dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 开启 dm9kA 中断 */
+        ; /* 等待发送完成	 */
+    // dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 开启 dm9kA 中断 */
 
     SYS_ARCH_UNPROTECT(sr);
 
-    OSMutexPost(dm9k_mutex);
+    // OSSemPost(g_dm9k_tx_sem);
     return errval;
 }
 
 static struct pbuf *low_level_input(struct netif *netif)
 {
     struct pbuf *p        = NULL;
-    uint32_t     framelen = 0;
+    uint16_t     framelen = 0;
 
-    dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 DM9000A 中断 */
+    // dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 DM9000A 中断 */
     framelen = etherdev_read(Rx_Buff[current_pbuf_idx]);
-    dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 开启 DM9000A 中断 */
+    // dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 开启 DM9000A 中断 */
     if (framelen)
     {
-
-        // p = pbuf_alloc(PBUF_RAW, framelen, PBUF_POOL);
-        p = pbuf_alloced_custom(PBUF_RAW, framelen, PBUF_REF, custom_pbuf[current_pbuf_idx], Rx_Buff[current_pbuf_idx], Max_Ethernet_Lenth);
-        if (current_pbuf_idx < (DM9K_RX_DESC_CNT - 1))
-        {
-            current_pbuf_idx++;
-        }
-        else
-        {
-            current_pbuf_idx = 0;
-        }
+        printf("REC LEM: %d\r\n", framelen);
+        p = pbuf_alloc(PBUF_RAW, framelen, PBUF_POOL);
+        // p = pbuf_alloced_custom(PBUF_RAW, framelen, PBUF_REF, custom_pbuf[current_pbuf_idx], Rx_Buff[current_pbuf_idx], Max_Ethernet_Lenth);
+        // if (current_pbuf_idx < (DM9K_RX_DESC_CNT - 1))
+        // {
+        //     current_pbuf_idx++;
+        // }
+        // else
+        // {
+        //     current_pbuf_idx = 0;
+        // }
     }
     return p;
 }
 
-#if 1
 void ethernetif_input(void *pvParameters)
 {
     struct pbuf *p;
@@ -222,43 +178,7 @@ TRY_GET_NEXT_FRAME:
         }
     }
 }
-#else
-void ethernetif_input(void *argument)
-{
-    struct pbuf *p;
-    // struct netif *netif = (struct netif *)argument;
-    INT8U err;
-    for (;;)
-    {
-        OSSemPend(g_dm9k_rx_sem, 0, &err);
-        // if (err == OS)
-        // {
-        if (err == ERR_OK)
-        {
-            do
-            {
-                LOCK_TCPIP_CORE();
-
-                p = low_level_input(low_netif);
-                if (p != NULL)
-                {
-                    err = low_netif->input(p, low_netif);
-                    if (err != ERR_OK)
-                    {
-                        LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
-                        pbuf_free(p);
-                    }
-                }
-
-                UNLOCK_TCPIP_CORE();
-
-            } while (p != NULL);
-        }
 
-        // }
-    }
-}
-#endif
 err_t ethernetif_dm9k_init(struct netif *netif)
 {
     LWIP_ASSERT("netif != NULL", (netif != NULL));
@@ -295,13 +215,13 @@ err_t ethernetif_dm9k_init(struct netif *netif)
  * @param  pbuf: pbuf to be freed
  * @retval None
  */
-static void pbuf_free_custom(struct pbuf *p)
-{
-    if (p != NULL)
-    {
-        memset(p, 0, sizeof(struct pbuf));
-    }
-}
+// static void pbuf_free_custom(struct pbuf *p)
+// {
+//     if (p != NULL)
+//     {
+//         memset(p, 0, sizeof(struct pbuf));
+//     }
+// }
 void dm9k_interrupt(void)
 {
     uint8_t  save_reg;
@@ -309,8 +229,8 @@ void dm9k_interrupt(void)
 
     save_reg = NET_REG_ADDR; /* 暂存所使用的位置 */
 
-    dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 DM9KA 中断 */
-    isr_status = dm9k_ReadReg(DM9K_REG_ISR);   /* 取得中断产生值 */
+    // dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* 关闭 DM9KA 中断 */
+    isr_status = dm9k_ReadReg(DM9K_REG_ISR); /* 取得中断产生值 */
     // isr_status = isr_status & DM9K_RX_INTR;
     if (isr_status & DM9K_RX_INTR)
     { /* 检查是否为接收中断 */
@@ -342,43 +262,37 @@ void BSP_GPIO15_EXTI_Callback(void)
     {
         OSSemPost(g_dm9k_rx_sem); /* 执行接收处理程序 */
     }
+    if (isr_status & DM9K_TX_INTR) // 发送中断
+    {
+        OSSemPost(g_dm9k_tx_sem);
+        // 发送完成中断,用户自己添加代码
+    }
 
     NET_REG_ADDR = save_reg; /* 回复所使用的位置 */
 }
 
-//中断处理函数,注意不是中断服函数,需要在中断服务函数中调用
+// 中断处理函数,注意不是中断服函数,需要在中断服务函数中调用
 void DMA9K_ISRHandler(void)
 {
     u16 int_status;
     u16 last_io;
     last_io    = NET_REG_ADDR;
     int_status = dm9k_ReadReg(DM9K_REG_ISR);
-    dm9k_WriteReg(DM9K_REG_ISR, int_status); //清除中断标志位
+    dm9k_WriteReg(DM9K_REG_ISR, int_status); // 清除中断标志位
 
-    if (int_status & DM9K_RX_INTR) //接收中断
+    if (int_status & DM9K_RX_INTR) // 接收中断
     {
         OSSemPost(g_dm9k_rx_sem);
-        //接收完成中断,用户自己添加代码
+        // 接收完成中断,用户自己添加代码
     }
-    if (int_status & DM9K_TX_INTR) //发送中断
+    if (int_status & DM9K_TX_INTR) // 发送中断
     {
         // OSSemPost(g_dm9k_tx_sem);
-        //发送完成中断,用户自己添加代码
+        // 发送完成中断,用户自己添加代码
     }
     NET_REG_ADDR = last_io;
 }
 
-void EXTI15_10_IRQHandler(void)
-{
-    OSIntEnter();
-    EXTI_ClearITPendingBit(EXTI_Line15); /* 清除中断标志位 */
-    if (EXTI_GetITStatus(EXTI_Line15) != RESET)
-    {
-        BSP_GPIO15_EXTI_Callback();
-    }
-    OSIntExit();
-}
-
 void ethernet_link_check_state(struct netif *netif)
 {
     uint8_t linkchanged = 0;
@@ -387,11 +301,13 @@ void ethernet_link_check_state(struct netif *netif)
 
     if (netif_is_link_up(netif) && (linkchanged == 0))
     {
+        printf("dm9k LwIP Error interface....\r\n");
         netif_set_down(netif);
         netif_set_link_down(netif);
     }
     else if (!netif_is_link_up(netif) && (linkchanged == 1))
     {
+        printf("dm9k LwIP Finish interface....\r\n");
         netif_set_up(netif);
         netif_set_link_up(netif);
     }

+ 117 - 26
Project/main.c

@@ -8,9 +8,12 @@
 */
 
 #include "main.h"
-#include "bsp_fatfs.h"
+#include "net.h"
+#include "os_cpu.h"
 
-void DumpHEX(uint8_t *buffer, uint32_t len)
+int32_t g_recv_msg_flag = 0;
+
+void dump_hex(uint8_t *buffer, uint32_t len)
 {
 
     uint32_t i;
@@ -70,7 +73,7 @@ int main(void)
     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
     OSInit();
     bsp_init();
-    RegisterIec10x();
+    iec10x_regist();
 
     /* init task */
     /* 创建一个启动任务(也就是主任务)。启动任务会创建所有的应用程序任务 */
@@ -127,34 +130,33 @@ void init_task(void *pvParameters)
     //                 (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 
     /* 485 modbus从机模式 */
-    OSTaskCreateExt((void (*)(void *))modbus_slave_task,
-                    (void *)0,
-                    (OS_STK *)&uart3_task_stk[UART3_TASK_STK_SIZE - 1],
-                    (INT8U)UART3_TASK_PRIO,
-                    (INT16U)UART3_TASK_PRIO,
-                    (OS_STK *)&uart3_task_stk[0],
-                    (INT32U)UART3_TASK_STK_SIZE,
-                    (void *)0,
-                    (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
+    // OSTaskCreateExt((void (*)(void *))modbus_slave_task,
+    //                 (void *)0,
+    //                 (OS_STK *)&uart3_task_stk[UART3_TASK_STK_SIZE - 1],
+    //                 (INT8U)UART3_TASK_PRIO,
+    //                 (INT16U)UART3_TASK_PRIO,
+    //                 (OS_STK *)&uart3_task_stk[0],
+    //                 (INT32U)UART3_TASK_STK_SIZE,
+    //                 (void *)0,
+    //                 (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 
-    OSTaskCreateExt((void (*)(void *))net_task,
+    OSTaskCreateExt((void (*)(void *))iec104_task,
                     (void *)0,
-                    (OS_STK *)&net_task_stk[NET_TASK_STK_SIZE - 1],
-                    (INT8U)NET_PRIO,
-                    (INT16U)NET_PRIO,
-                    (OS_STK *)&net_task_stk[0],
-                    (INT32U)NET_TASK_STK_SIZE,
+                    (OS_STK *)&iec104_task_stk[IEC_TASK_STK_SIZE - 1],
+                    (INT8U)IEC_PRIO,
+                    (INT16U)IEC_PRIO,
+                    (OS_STK *)&iec104_task_stk[0],
+                    (INT32U)IEC_TASK_STK_SIZE,
                     (void *)0,
                     (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 
-    /* ESP8266 STA任务*/
-    OSTaskCreateExt((void (*)(void *))esp_8266_task,
+    OSTaskCreateExt((void (*)(void *))modbus_tcp_task,
                     (void *)0,
-                    (OS_STK *)&uart6_task_stk[UART6_TASK_STK_SIZE - 1],
-                    (INT8U)UART6_TASK_PRIO,
-                    (INT16U)UART6_TASK_PRIO,
-                    (OS_STK *)&uart6_task_stk[0],
-                    (INT32U)UART6_TASK_STK_SIZE,
+                    (OS_STK *)&tcp_task_stk[TCP_TASK_STK_SIZE - 1],
+                    (INT8U)TCP_PRIO,
+                    (INT16U)TCP_PRIO,
+                    (OS_STK *)&tcp_task_stk[0],
+                    (INT32U)TCP_TASK_STK_SIZE,
                     (void *)0,
                     (INT16U)OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR | OS_TASK_OPT_SAVE_FP);
 }
@@ -224,7 +226,7 @@ void misc_task(void)
             // }
             // else
             // {
-            ret = am2303_read_data(&temperature, &humidity); //读取温湿度值
+            ret = am2303_read_data(&temperature, &humidity); // 读取温湿度值
             // if (ret == 1)
             // {
             //     printf("Temp: (%d).\n", temperature);
@@ -257,6 +259,95 @@ void misc_task(void)
         {
             save_cnt++;
         }
+        if (g_iec104_socket > 0)
+        {
+            iec104_scheduled(g_iec104_socket);
+        }
+
+        iec104_state_machine();
         OSTimeDly(20);
     };
+}
+
+// void iec104_task(void)
+// {
+//     INT8U  buf[MAX_RECV_SIZE] = {0};
+//     INT32S ret                = 0;
+//     INT32U len                = 0;
+
+//     while (1)
+//     {
+//         if (g_iec104_socket < 0)
+//         {
+//             ret = iec104_connect_module();
+//             if (ret < 0)
+//             {
+//                 goto TASK_DELAY;
+//             }
+//             g_data_req_flag = 0;
+//         }
+//         else
+//         {
+//             ret = iec104_rec_master(buf);
+//             if (ret <= 0)
+//             {
+//                 closesocket(g_iec104_socket);
+//                 goto TASK_DELAY;
+//             }
+//         }
+// TASK_DELAY:
+//         OSTimeDly(100);
+//     }
+// }
+
+void modbus_tcp_task(void)
+{
+    INT8U  buf[MAX_RECV_SIZE] = {0};
+    INT32S ret                = 0;
+    INT16U temp_buf_len;
+    INT16U msg_data_len;
+    INT32U len;
+
+    while (1)
+    {
+        if (g_modbus_tcp_socket < 0)
+        {
+            ret = modbus_tcp_connect_module();
+            if (ret < 0)
+            {
+                goto TASK_DELAY;
+            }
+            g_data_req_flag = 0;
+        }
+        else
+        {
+            ret = modbus_tcp_rec_module(buf);
+            if (ret < 2)
+            {
+                if (g_recv_msg_flag == 1)
+                {
+                    fly_mosbus_init_flag();
+                    closesocket(g_iec104_socket);
+                    g_recv_msg_flag = 0;
+                }
+
+                goto TASK_DELAY;
+            }
+            g_recv_msg_flag = 0;
+            temp_buf_len    = 0;
+            while (temp_buf_len < ret)
+            {
+                len          = 0;
+                msg_data_len = ((buf[temp_buf_len + 1] & 0xff) | ((buf[temp_buf_len + 2] << 8) & 0xff00));
+                len          = msg_data_len + 3;
+                if (fly_test_process(&(buf[temp_buf_len]), len) != 0)
+                {
+                    goto TASK_DELAY;
+                }
+                temp_buf_len += msg_data_len + 3;
+            }
+        }
+TASK_DELAY:
+        OSTimeDly(100);
+    }
 }

+ 6 - 3
Project/main.h

@@ -3,16 +3,17 @@
 
 #include "ad7606.h"
 #include "am2303.h"
-#include "esp8266.h"
+#include "bsp_fatfs.h"
 #include "fly_param.h"
-#include "iec10x_type.h"
 #include "includes.h"
 #include "interface.h"
+#include "iwdg.h"
 #include "key.h"
 #include "modbus.h"
 #include "nand_flash.h"
 #include "net.h"
 #include "nor_flash.h"
+#include "os_cpu.h"
 #include "stm32f4x7_phy.h"
 #include "stm32f4xx.h"
 #include "usbh_bsp_msc.h"
@@ -21,6 +22,8 @@
 void bsp_init(void);
 void init_task(void *pvParameters);
 void misc_task(void);
+// void iec104_task(void);
+void modbus_tcp_task(void);
 
-iec_32u RegisterIec10x(void);
+INT32U iec10x_regist(void);
 #endif

+ 12 - 0
Project/stm32f4xx_it.c

@@ -29,6 +29,7 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f4xx_it.h"
+#include "ethernetif_dm9k.h"
 #include "includes.h"
 #include "lwip_eth.h"
 #include "stm32f4x7_eth.h"
@@ -194,4 +195,15 @@ void ETH_IRQHandler(void)
 }
 #endif /* USE_ETH_INTERRUPT */
 
+void EXTI15_10_IRQHandler(void)
+{
+    OSIntEnter();
+    EXTI_ClearITPendingBit(EXTI_Line15); /* 清除中断标志位 */
+    if (EXTI_GetITStatus(EXTI_Line15) != RESET)
+    {
+        BSP_GPIO15_EXTI_Callback();
+    }
+    OSIntExit();
+}
+
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 3 - 4
User/Bsp/armfly_bsp.c

@@ -6,7 +6,6 @@ void bsp_init(void)
     net_mutex  = OSMutexCreate(15, &err);
     uart1_mbox = OSMboxCreate(NULL);
     uart3_mbox = OSMboxCreate(NULL);
-    uart6_mbox = OSMboxCreate(NULL);
 
     InitQueue(&CanQueueCan1);
     InitQueue(&CanQueueCan2);
@@ -22,10 +21,10 @@ void bsp_init(void)
     uart3_init();
     LCD_Init();
     key_init();
-    uart6_init();
     nor_flash_init();
+    ext_sram_init();
 
-/* Init Host Library */
+// 初始化USBH
 #ifdef USE_USB_OTG_FS
     USBH_Init(&USB_OTG_Core,
               USB_OTG_FS_CORE_ID,
@@ -43,5 +42,5 @@ void bsp_init(void)
     lwip_setup();
     // can初始化
     can_network_init();
-    iwdg_init();
+    // iwdg_init();
 }

+ 1 - 1
User/Bsp/armfly_bsp.h

@@ -6,6 +6,7 @@
 #include "bsp_fatfs.h"
 #include "can.h"
 #include "dwt.h"
+#include "ext_sram.h"
 #include "fly_param.h"
 #include "interface.h"
 #include "iwdg.h"
@@ -19,6 +20,5 @@
 #include "timer.h"
 #include "uart1.h"
 #include "uart3.h"
-#include "uart6.h"
 #include "usbh_bsp_msc.h"
 #endif

+ 34 - 52
User/Bsp/dm9k/dm9k.c

@@ -37,7 +37,7 @@
 #include "Lwip_init.h"
 
 /* DM9KA 接收函数设置宏 */
-//#define Rx_Int_enable
+// #define Rx_Int_enable
 #define Max_Int_Count 1
 
 #define Broadcast_Jump
@@ -46,27 +46,22 @@
 /* DM9KA 传送函数设置宏 */
 #define Max_Send_Pack 2
 
-//#define FifoPointCheck
-//#define DM9KA_FLOW_CONTROL
-//#define DM9KA_UPTO_100M
-//#define Fifo_Point_Check
-//#define Point_Error_Reset
+// #define FifoPointCheck
+// #define DM9KA_FLOW_CONTROL
+// #define DM9KA_UPTO_100M
+// #define Fifo_Point_Check
+// #define Point_Error_Reset
 #define Fix_Note_Address
 /*=============================================================================
   系统全域的变量
   =============================================================================*/
 uint8_t SendPackOk = 0;
 
-uint8_t s_FSMC_Init_Ok = 0; /* 用于指示FSMC是否初始化 */
+// uint8_t s_FSMC_Init_Ok = 0; /* 用于指示FSMC是否初始化 */
 
-//#define printk(...)
+// #define printk(...)
 #define printk myprintf
 
-void dm9k_debug_test(void);
-void dm9k_udelay(uint16_t time);
-
-static void dm9k_fsmc(void);
-
 /*******************************************************************************
  *	函数名: dm9k_udelay
  *	参  数: time : 延迟时间,不精确,us级别
@@ -203,12 +198,12 @@ uint16_t dm9k_phy_read(uint8_t phy_reg)
     dm9k_WriteReg(DM9K_REG_EPAR, phy_reg | DM9K_PHY);
 
     /* 设置写入 PHY 寄存器的值 */
-    dm9k_WriteReg(DM9K_REG_EPCR, 0x0C); //选中PHY,发送读命令
+    dm9k_WriteReg(DM9K_REG_EPCR, 0x0C); // 选中PHY,发送读命令
 
     while (dm9k_ReadReg(DM9K_REG_EPCR) & 0x01)
         ; /* 查寻是否执行结束 */
 
-    dm9k_WriteReg(DM9K_REG_EPCR, 0x00); //清除读命令
+    dm9k_WriteReg(DM9K_REG_EPCR, 0x00); // 清除读命令
     temp = (dm9k_ReadReg(DM9K_REG_EPDRH) << 8) | (dm9k_ReadReg(DM9K_REG_EPDRL));
 
     return temp;
@@ -245,17 +240,17 @@ uint8_t DM9K_Get_SpeedAndDuplex(void)
     uint8_t temp;
     uint8_t i = 0;
 
-    while (!(dm9k_phy_read(DM9K_PHY_BMSR) & 0x0020)) //等待自动协商完成
+    while (!(dm9k_phy_read(DM9K_PHY_BMSR) & 0x0020)) // 等待自动协商完成
     {
         ms_delay(100);
         i++;
 
         if (i > 100)
-            return 0XFF; //自动协商失败
+            return 0XFF; // 自动协商失败
     }
 
-    temp = ((dm9k_ReadReg(DM9K_REG_NSR) >> 6) & 0x02);  //获取DM9K的连接速度 0:100M 1:10M
-    temp |= ((dm9k_ReadReg(DM9K_REG_NCR) >> 3) & 0x01); //获取DM9K的双工状态
+    temp = ((dm9k_ReadReg(DM9K_REG_NSR) >> 6) & 0x02);  // 获取DM9K的连接速度 0:100M 1:10M
+    temp |= ((dm9k_ReadReg(DM9K_REG_NCR) >> 3) & 0x01); // 获取DM9K的双工状态
 
     return temp;
 }
@@ -268,10 +263,10 @@ uint8_t DM9K_Get_SpeedAndDuplex(void)
  */
 void dm9k_initnic(void)
 {
-    //	uint8_t temp;
+    uint8_t temp;
 
-    if (DM9KA_ID != dm9k_ReadID()) /* 进行 设备ID读取判断 */
-        return;
+    // if (DM9KA_ID != dm9k_ReadID()) /* 进行 设备ID读取判断 */
+    //     return;
 
     dm9k_WriteReg(DM9K_REG_GPCR, 0x01); /* 设置GPCR bit[0]=1,使DM9K为GPIO0为输出 */
     dm9k_WriteReg(DM9K_REG_GPR, 0x00);  /* GPR bit[0]=0,使GPIO0输出低电平以激活内部PHY */
@@ -314,15 +309,15 @@ void dm9k_initnic(void)
 
     dm9k_WriteReg(DM9K_REG_GPR, DM9K_PHY_ON); /* 结束 PHY 设置, 开启 PHY */
 
-    //	temp = DM9K_Get_SpeedAndDuplex();				/* 获取DM9K的连接速度和双工状态 */
-    //	if(temp != 0xFF)								/* 连接成功,通过串口显示连接速度和双工状态 */
-    //	{
-    //		myprintf("DM9K Speed:%dMbps,Duplex:%s duplex mode\r\n", (temp & 0x02) ? 10 : 100, (temp & 0x01) ? "Full" : "Half");
-    //	}
-    //	else
-    //	{
-    //		myprintf("DM9K Establish Link Failed!\r\n");
-    //	}
+    temp = DM9K_Get_SpeedAndDuplex(); /* 获取DM9K的连接速度和双工状态 */
+    if (temp != 0xFF)                 /* 连接成功,通过串口显示连接速度和双工状态 */
+    {
+        printf("DM9K Speed:%dMbps,Duplex:%s duplex mode\r\n", (temp & 0x02) ? 10 : 100, (temp & 0x01) ? "Full" : "Half");
+    }
+    else
+    {
+        printf("DM9K Establish Link Failed!\r\n");
+    }
 
     dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 设置中断 */
 
@@ -340,7 +335,7 @@ void dm9k_initnic(void)
     EXTI_ClearITPendingBit(EXTI_Line15);
 
     NVIC_InitStructure.NVIC_IRQChannel                   = EXTI15_10_IRQn;
-    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
+    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0;
     NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
@@ -533,7 +528,7 @@ void dm9k_init(void)
 {
     dm9k_fsmc();
 
-    s_FSMC_Init_Ok = 1;
+    // s_FSMC_Init_Ok = 1;
 
     dm9k_initnic();
 }
@@ -582,14 +577,6 @@ uint32_t dm9k_ReadID(void)
 {
     uint8_t vid1, vid2, pid1, pid2;
 
-    if (s_FSMC_Init_Ok == 0)
-    {
-
-        dm9k_fsmc();
-
-        s_FSMC_Init_Ok = 1;
-    }
-
     vid1 = dm9k_ReadReg(DM9K_REG_VID_L) & 0xFF;
     vid2 = dm9k_ReadReg(DM9K_REG_VID_H) & 0xFF;
     pid1 = dm9k_ReadReg(DM9K_REG_PID_L) & 0xFF;
@@ -598,25 +585,22 @@ uint32_t dm9k_ReadID(void)
     return (pid2 << 24) | (pid1 << 16) | (vid2 << 8) | vid1;
 }
 
-static void dm9k_fsmc(void)
+void dm9k_fsmc(void)
 {
     FSMC_NORSRAMInitTypeDef       FSMC_NORSRAMInitStructure;
     FSMC_NORSRAMTimingInitTypeDef p;
 
-    /*-- FSMC Configuration ------------------------------------------------------*/
-    /*----------------------- SRAM Bank 3 ----------------------------------------*/
-    /*-- FSMC Configuration ------------------------------------------------------*/
-    p.FSMC_AddressSetupTime      = 3; /* 设置为2会出错; 3正常 */
-    p.FSMC_AddressHoldTime       = 0;
-    p.FSMC_DataSetupTime         = 3; /* 设置为1出错,2正常 */
-    p.FSMC_BusTurnAroundDuration = 0;
+    p.FSMC_AddressSetupTime      = 6;
+    p.FSMC_AddressHoldTime       = 2;
+    p.FSMC_DataSetupTime         = 4;
+    p.FSMC_BusTurnAroundDuration = 1;
     p.FSMC_CLKDivision           = 0;
     p.FSMC_DataLatency           = 0;
     p.FSMC_AccessMode            = FSMC_AccessMode_A;
 
     FSMC_NORSRAMInitStructure.FSMC_Bank                  = FSMC_Bank1_NORSRAM3;
     FSMC_NORSRAMInitStructure.FSMC_DataAddressMux        = FSMC_DataAddressMux_Disable;
-    FSMC_NORSRAMInitStructure.FSMC_MemoryType            = FSMC_MemoryType_SRAM; // FSMC_MemoryType_PSRAM;
+    FSMC_NORSRAMInitStructure.FSMC_MemoryType            = FSMC_MemoryType_SRAM;
     FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth       = FSMC_MemoryDataWidth_16b;
     FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode       = FSMC_BurstAccessMode_Disable;
     FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait      = FSMC_AsynchronousWait_Disable;
@@ -631,7 +615,5 @@ static void dm9k_fsmc(void)
     FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct     = &p;
 
     FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
-
-    /*!< Enable FSMC Bank1_SRAM3 Bank */
     FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
 }

+ 3 - 2
User/Bsp/dm9k/dm9k.h

@@ -64,7 +64,7 @@
 #define DM9K_REG_IMR    0xFF
 
 /* 相关宏设置 */
-#define DM9KA_ID 0x90000A46
+#define DM9KA_ID 0x0A469000
 
 #define DM9K_BYTE_MODE 0x01
 #define DM9K_WORD_MODE 0x00
@@ -117,9 +117,10 @@
 
 #define Max_Ethernet_Lenth 1536
 
-/* EXPORTED SUBPROGRAM SPECIFICATIONS */
 void    dm9k_init(void);
 uint8_t dm9k_linkstat(void);
+void    dm9k_udelay(uint16_t time);
+void    dm9k_fsmc(void);
 
 uint8_t dm9k_ReadReg(uint8_t reg);
 void    dm9k_WriteReg(uint8_t reg, uint8_t writedata);

+ 1 - 1
User/Bsp/ext_sram/ext_sram.c

@@ -91,7 +91,7 @@ void ext_sram_init(void)
 
     FSMC_NORSRAMInitStructure.FSMC_Bank                  = FSMC_Bank1_NORSRAM3;
     FSMC_NORSRAMInitStructure.FSMC_DataAddressMux        = FSMC_DataAddressMux_Disable;
-    FSMC_NORSRAMInitStructure.FSMC_MemoryType            = FSMC_MemoryType_SRAM; // FSMC_MemoryType_PSRAM;
+    FSMC_NORSRAMInitStructure.FSMC_MemoryType            = FSMC_MemoryType_SRAM;
     FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth       = FSMC_MemoryDataWidth_16b;
     FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode       = FSMC_BurstAccessMode_Disable;
     FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait      = FSMC_AsynchronousWait_Disable;

+ 14 - 40
User/Bsp/interface/interface.c

@@ -13,27 +13,18 @@
 #include "stm32f4xx_gpio.h"
 
 Gpio_Clock clock_info[] = {
-    // {.type = kI2C0, .AXBPeriph_Clock = RCC_I2C0},
     {.type = kI2C1, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_APB1Periph_I2C1},
-    // {.type = kI2C2, .AXBPeriph_Clock = RCU_I2C2},
-    // {.type = kADC0, .AXBPeriph_Clock = RCU_ADC0},
-    // {.type = kADC3, .AXBPeriph_Clock = RCU_ADC2},
     {.type = kSPI1, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_SPI1},
     {.type = kUart1, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_USART1},
     {.type = kUart3, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_USART3},
-    {.type = kUart6, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_USART6},
     {.type = kCAN1, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN1},
     {.type = kCAN2, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN2},
-    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
-    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
-    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
-    {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
+    {.type = kEthernet_dm9161, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
+    {.type = kEthernet_dm9161, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
+    {.type = kEthernet_dm9161, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
+    {.type = kEthernet_dm9161, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
     {.type = kFSMC, .RCC_AXBPeriph = RCC_AHB3Periph, .AF_Clock = RCC_AHB3Periph_FSMC},
-    //    {.type = kUSB, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_OTG_HS},
-    //    {.type = kSDIO, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_SDIO},
-    // {.type = kPMU, .AXBPeriph_Clock = RCU_PMU},
     {.type = kDMA1, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_DMA1},
-    // //    {.type = kTIMER1,   .AXBPeriph_Clock = RCU_TIMER1},
 };
 
 Interface_struct interface_info[] = {
@@ -77,22 +68,17 @@ Interface_struct interface_info[] = {
     {.type = kUart3, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_USART3}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
     {.type = kUart3, .GPIOx = UART3_ENABLE_PORT, .GPIO_Pin = UART3_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
 
-    // uart6
-    {.type = kUart6, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    {.type = kUart6, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    // {.type = kUart6, .GPIOx = UART6_ENABLE_PORT, .GPIO_Pin = UART6_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-
     // ethernet-dm9161
-    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource2, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    // {.type = kEthernet_dm9101, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    {.type = kEthernet_dm9101, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource2, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
+    {.type = kEthernet_dm9161, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
 
     // fsmc
     {.type = kFSMC, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_0, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource0, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
@@ -146,18 +132,6 @@ Interface_struct interface_info[] = {
     // am2303
     {.type = kOutput, .Out_Type = kAM2303, .GPIOx = AM2303_PORT, .GPIO_Pin = AM2303_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_OD, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
 
-    // USB U盘
-    //    {.type = kUSB, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_OTG2_FS}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    //    {.type = kUSB, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_15, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource15, .GPIO_AF = GPIO_AF_OTG2_FS}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-
-    // sdio
-    //    {.type = kSDIO, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_8,  .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource8,  .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    //    {.type = kSDIO, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_9,  .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource9,  .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    //    {.type = kSDIO, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    //    {.type = kSDIO, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-    //    {.type = kSDIO, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource12, .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
-    //    {.type = kSDIO, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_2,  .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource2,  .GPIO_AF = GPIO_AF_SDIO}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
-
     // input
     {.type = kInput, .In_Type = DM9K_INIT, .GPIOx = DM9K_RESET_PORT, .GPIO_Pin = DM9K_RESET_PIN, .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
     {.type = kInput, .In_Type = NOR_FLASH_STATE, .GPIOx = NOR_FLASH_STATE_PORT, .GPIO_Pin = NOR_FLASH_STATE_PIN, .GPIO_Mode = GPIO_Mode_IN, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},

+ 1 - 4
User/Bsp/interface/interface.h

@@ -15,18 +15,15 @@ typedef enum
     kSPI1,
     kUart1,
     kUart3,
-    kUart6,
     kCAN1,
     kCAN2,
-    kEthernet_dm9101,
+    kEthernet_dm9161,
     kFSMC,
     kInput,
     kOutput,
     kPMU,
     kDMA1,
     kAM2303,
-    kUSB,
-    kSDIO,
     //    kTIMER1,
     kInterfaceEnd,
 } interface_type;

+ 11 - 11
User/Bsp/iwdg/iwdg.c

@@ -3,29 +3,29 @@
 INT32U    g_dog      = 0;
 OS_EVENT *iwdg_mutex = NULL;
 
-//初始化独立看门狗
-// prer:分频数:0~7(只有低3位有效!)
-// rlr:自动重装载值,0~0XFFF.
-//分频因子=4*2^prer.但最大值只能是256!
-// rlr:重装载寄存器值:低11位有效.
-//时间计算(大概):Tout=((4*2^prer)*rlr)/32 (ms).
+// 初始化独立看门狗
+//  prer:分频数:0~7(只有低3位有效!)
+//  rlr:自动重装载值,0~0XFFF.
+// 分频因子=4*2^prer.但最大值只能是256!
+//  rlr:重装载寄存器值:低11位有效.
+// 时间计算(大概):Tout=((4*2^prer)*rlr)/32 (ms).
 void iwdg_init(void)
 {
-    IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //使能对IWDG->PR IWDG->RLR的写
+    IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); // 使能对IWDG->PR IWDG->RLR的写
 
-    IWDG_SetPrescaler(IWDG_Prescaler_128); //设置IWDG分频系数
+    IWDG_SetPrescaler(IWDG_Prescaler_128); // 设置IWDG分频系数
 
-    IWDG_SetReload(0X9C4); //设置IWDG装载值
+    IWDG_SetReload(0X9C4); // 设置IWDG装载值
 
     IWDG_ReloadCounter(); // reload
 
-    IWDG_Enable(); //使能看门狗
+    IWDG_Enable(); // 使能看门狗
 }
 
 void iwdg_feed(INT32U dog)
 {
     INT8U  err     = 0;
-    INT32U all_dog = UART3_DOG | UART6_DOG | MISC_DOG;
+    INT32U all_dog = UART3_DOG | MISC_DOG;
     // INT32U all_dog = CURRENT_DOG | SOC_DOG | ADC_DOG | INCAN_RX_DOG | INCAN_TX_DOG | INCAN_INFO_DOG | CAN2_TX_DOG | CAN2_RX_DOG | FAULT_DIG_DOG | UART1_DOG | UART3_DOG | BALANCE_DOG | MISC_DOG | PROCESS_DOG;
     OSMutexPend(iwdg_mutex, 0, &err);
     g_dog |= dog;

+ 3 - 3
User/Bsp/iwdg/iwdg.h

@@ -14,9 +14,9 @@
 #define FAULT_DIG_DOG  0x00000100
 #define UART1_DOG      0x00000200
 #define UART3_DOG      0x00000400
-#define UART6_DOG      0x00000800
-#define MISC_DOG       0x00001000
-#define PROCESS_DOG    0x00002000
+// #define UART6_DOG      0x00000800
+#define MISC_DOG    0x00001000
+#define PROCESS_DOG 0x00002000
 
 extern OS_EVENT *wtdg_mutex;
 

+ 0 - 214
User/Bsp/uart/uart6.c

@@ -1,214 +0,0 @@
-/**
-************************************************************************************************
-* @文件    : uart3.c
-* @作者    : 樊春春
-* @版本    : V1.0
-* @时间    : 2022/05/31 20:15:29
-* @邮箱    : [email protected]
-* @说明    : 485底层驱动
-************************************************************************************************
-**/
-
-#include "uart6.h"
-
-static uint8_t uart6_tx_buf[UART6_TX_LEN]  = {0};
-static uint8_t uart6_rx_buf[UART6_REC_LEN] = {0};
-
-UartFrame_TypeDef Uart6FrameStruct[UART6_MAX_MSG_NUM];
-
-extern OS_EVENT *uart6_mbox;
-
-void uart6_nvic_config(void)
-{
-    NVIC_InitTypeDef NVIC_InitStructure;
-    // Usart3 NVIC 配置
-    NVIC_InitStructure.NVIC_IRQChannel                   = USART6_IRQn; //串口3中断通道
-    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;           //抢占优先级
-    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0;           //子优先级
-    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;      // IRQ通道使能
-    NVIC_Init(&NVIC_InitStructure);
-}
-
-void uart6_dma_init(void)
-{
-    DMA_InitTypeDef DMA_InitStructure;
-    if ((uint32_t)UART6_DMA_TXCH > (uint32_t)DMA2)
-    {
-        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); // DMA2时钟使能
-    }
-    else
-    {
-        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); // DMA1时钟使能
-    }
-    DMA_DeInit(UART6_DMA_TXCH);
-    while (DMA_GetCmdStatus(UART6_DMA_TXCH) != DISABLE)
-    {
-    } //等待DMA可配置
-    /* 配置 DMA Stream */
-    DMA_InitStructure.DMA_Channel            = UART6_DMA;                   //通道选择
-    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART6->DR;       // DMA外设地址
-    DMA_InitStructure.DMA_Memory0BaseAddr    = (uint32_t)uart6_tx_buf;      // DMA 存储器0地址
-    DMA_InitStructure.DMA_DIR                = DMA_DIR_MemoryToPeripheral;  //存储器到外设模式
-    DMA_InitStructure.DMA_BufferSize         = UART6_TX_LEN;                //数据传输量
-    DMA_InitStructure.DMA_PeripheralInc      = DMA_PeripheralInc_Disable;   //外设非增量模式
-    DMA_InitStructure.DMA_MemoryInc          = DMA_MemoryInc_Enable;        //存储器增量模式
-    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设数据长度:8位
-    DMA_InitStructure.DMA_MemoryDataSize     = DMA_MemoryDataSize_Byte;     //存储器数据长度:8位
-    DMA_InitStructure.DMA_Mode               = DMA_Mode_Normal;             // 使用普通模式
-    DMA_InitStructure.DMA_Priority           = DMA_Priority_Medium;         //中等优先级6
-    DMA_InitStructure.DMA_FIFOMode           = DMA_FIFOMode_Disable;
-    DMA_InitStructure.DMA_FIFOThreshold      = DMA_FIFOThreshold_Full;
-    DMA_InitStructure.DMA_MemoryBurst        = DMA_MemoryBurst_Single;     //存储器突发单次传输
-    DMA_InitStructure.DMA_PeripheralBurst    = DMA_PeripheralBurst_Single; //外设突发单次传输
-    DMA_Init(UART6_DMA_TXCH, &DMA_InitStructure);                          //初始化DMA Stream
-
-    if ((uint32_t)UART6_DMA_RXCH > (uint32_t)DMA2) //得到当前stream是属于DMA2还是DMA1
-    {
-        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); // DMA2时钟使能
-    }
-    else
-    {
-        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); // DMA1时钟使能
-    }
-
-    DMA_DeInit(UART6_DMA_RXCH);
-    while (DMA_GetCmdStatus(UART6_DMA_RXCH) != DISABLE)
-    {
-    } //等待DMA可配置
-    /* 配置 DMA Stream */
-    DMA_InitStructure.DMA_Channel            = UART6_DMA;                   //通道选择
-    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART6->DR;       // DMA外设地址
-    DMA_InitStructure.DMA_Memory0BaseAddr    = (uint32_t)uart6_rx_buf;      // DMA 存储器0地址
-    DMA_InitStructure.DMA_DIR                = DMA_DIR_PeripheralToMemory;  //外设到存储器模式
-    DMA_InitStructure.DMA_BufferSize         = UART6_REC_LEN;               //数据传输量
-    DMA_InitStructure.DMA_PeripheralInc      = DMA_PeripheralInc_Disable;   //外设非增量模式
-    DMA_InitStructure.DMA_MemoryInc          = DMA_MemoryInc_Enable;        //存储器增量模式
-    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设数据长度:8位
-    DMA_InitStructure.DMA_MemoryDataSize     = DMA_MemoryDataSize_Byte;     //存储器数据长度:8位
-    DMA_InitStructure.DMA_Mode               = DMA_Mode_Circular;           // 使用循环模式
-    DMA_InitStructure.DMA_Priority           = DMA_Priority_Medium;         //中等优先级
-    DMA_InitStructure.DMA_FIFOMode           = DMA_FIFOMode_Disable;
-    DMA_InitStructure.DMA_FIFOThreshold      = DMA_FIFOThreshold_Full;
-    DMA_InitStructure.DMA_MemoryBurst        = DMA_MemoryBurst_Single;     //存储器突发单次传输
-    DMA_InitStructure.DMA_PeripheralBurst    = DMA_PeripheralBurst_Single; //外设突发单次传输
-    DMA_Init(UART6_DMA_RXCH, &DMA_InitStructure);
-}
-
-void uart6_config(void)
-{
-    USART_InitTypeDef USART_InitStructure;
-    USART_InitStructure.USART_BaudRate            = 115200;                         //波特率设置
-    USART_InitStructure.USART_WordLength          = USART_WordLength_8b;            //字长为8位数据格式
-    USART_InitStructure.USART_StopBits            = USART_StopBits_1;               //一个停止位
-    USART_InitStructure.USART_Parity              = USART_Parity_No;                //无奇偶校验位
-    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件数据流控制
-    USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;  //收发模式
-    USART_Init(USART6, &USART_InitStructure);                                       //初始化串口1
-
-    USART_Cmd(USART6, ENABLE); //使能串口3
-}
-
-void Uart6DMA_Enable(DMA_Stream_TypeDef *DMA_Streamx, u16 count)
-{
-    DMA_Cmd(DMA_Streamx, DISABLE); //关闭DMA传输
-    while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE)
-    {
-    } //确保DMA可以被设置
-
-    DMA_SetCurrDataCounter(DMA_Streamx, count); //数据传输量
-    DMA_Cmd(DMA_Streamx, ENABLE);               //开启DMA传输
-}
-
-void uart6_init(void)
-{
-    uart6_config();
-    uart6_dma_init();
-    uart6_nvic_config();
-    /* USART DMA enable*/
-    USART_DMACmd(USART6, USART_DMAReq_Rx, ENABLE); // 使能串口DMA接收数据
-    Uart6DMA_Enable(UART6_DMA_RXCH, UART6_REC_LEN);
-
-    /*configure DMA interrupt*/
-    USART_ITConfig(USART6, USART_IT_IDLE, ENABLE); //开启空闲中断
-    USART_ITConfig(USART6, USART_IT_TC, ENABLE);
-
-    // UART6_RX_ENABLE;
-}
-
-/****************************************************
- *  函 数 名:Uart6_Send_Data
- *  函数功能:串口3发送数据
- *  入口参数:buf 待发送数据  len 数据长度
- *  说    明:
- *****************************************************/
-void Uart6_Send_Data(const uint8_t *buf, uint16_t len)
-{
-    uint8_t i;
-
-    // UART6_TX_ENABLE;          // 485 发送使能
-    for (i = 0; i < len; i++) //循环发送数据
-    {
-        while (USART_GetFlagStatus(USART6, USART_FLAG_TC) == RESET)
-            ;
-        USART_SendData(USART6, buf[i]);
-    }
-    while (USART_GetFlagStatus(USART6, USART_FLAG_TC) == RESET)
-        ;
-
-    // UART6_RX_ENABLE; // 接收使能
-}
-
-void uart6_dma_send(const uint8_t *buf, uint16_t len)
-{
-    if (DMA_GetFlagStatus(UART6_DMA_TXCH, DMA_FLAG_TCIF6) != RESET)
-    {
-        DMA_ClearFlag(UART6_DMA_TXCH, DMA_FLAG_TCIF6);
-    }
-
-    // UART6_TX_ENABLE; // 485 发送使能
-    if (len > UART6_TX_LEN)
-    {
-        len = UART6_TX_LEN;
-    }
-    memcpy(uart6_tx_buf, buf, len);
-    USART_DMACmd(USART6, USART_DMAReq_Tx, ENABLE);
-    Uart6DMA_Enable(UART6_DMA_TXCH, len);
-}
-
-void USART6_IRQHandler(void)
-{
-    static uint8_t   u3_index = 0;
-    volatile uint8_t clear    = 0;
-    uint8_t          rec_cnt  = 0;
-    if (RESET != USART_GetITStatus(USART6, USART_IT_IDLE))
-    {
-        clear = USART6->SR;
-        clear = USART6->DR; // 先读SR, 再读DR, 就是为了消除IDLE中断
-        DMA_Cmd(UART6_DMA_RXCH, DISABLE);
-        DMA_ClearFlag(UART6_DMA_RXCH, DMA_FLAG_TCIF2);
-        rec_cnt = UART6_REC_LEN - DMA_GetCurrDataCounter(UART6_DMA_RXCH);
-
-        memcpy(Uart6FrameStruct[u3_index].buf, uart6_rx_buf, rec_cnt);
-        Uart6FrameStruct[u3_index].len = rec_cnt;
-
-        OSMboxPost(uart6_mbox, &Uart6FrameStruct[u3_index]);
-        if (u3_index < UART6_MAX_MSG_NUM - 1)
-        {
-            u3_index++;
-        }
-        else
-        {
-            u3_index = 0;
-        }
-        DMA_SetCurrDataCounter(UART6_DMA_RXCH, UART6_REC_LEN);
-        DMA_Cmd(UART6_DMA_RXCH, ENABLE);
-    }
-    else if (RESET != USART_GetITStatus(USART6, USART_IT_TC))
-    {
-        USART_ClearITPendingBit(USART6, USART_IT_TC);
-        // UART6_RX_ENABLE;
-        Uart6DMA_Enable(UART6_DMA_RXCH, UART6_REC_LEN); // DMA接收使能
-        DMA_Cmd(UART6_DMA_TXCH, DISABLE);               // 关闭发送DMA
-        DMA_SetCurrDataCounter(UART6_DMA_TXCH, 0);      // 清除发送数据长度
-    }
-}

+ 0 - 20
User/Bsp/uart/uart6.h

@@ -1,20 +0,0 @@
-#ifndef __UART6_H
-#define __UART6_H
-
-#include "interface.h"
-#include "queue.h"
-#include "stm32f4xx_usart.h"
-#include "string.h"
-
-#define UART6_REC_LEN     128
-#define UART6_TX_LEN      128
-#define UART6_MAX_MSG_NUM 10
-
-#define UART6_DMA      DMA_Channel_5
-#define UART6_DMA_RXCH DMA2_Stream2
-#define UART6_DMA_TXCH DMA2_Stream6
-
-void uart6_init(void);
-void uart6_dma_send(const uint8_t *buf, uint16_t len);
-
-#endif // __UART3_H

+ 616 - 0
User/app/air/air.c

@@ -0,0 +1,616 @@
+// /**
+// ************************************************************************************************
+// * @file   		air.c
+// * @author  		国轩储能
+// * @version 		V1.0
+// * @date    		2018-11-20
+// * @brief   		空调通讯
+// * @attention
+// ************************************************************************************************
+// **/
+// #include "air.h"
+// #include "ModbusRtu.h"
+// #include "ff.h"
+// #include "i104_addr.h"
+// #include "os_my_var.h"
+// #include "uart1.h"
+// #include <string.h>
+
+// union Data_Air_Union_TypeDef    Data_Air[2];
+// union Par_Set_Air_Union_TypeDef Par_Set_Air1;                                                                                                                                                                                                                                        // 空调1
+// union Par_Set_Air_Union_TypeDef Par_Set_Air2;                                                                                                                                                                                                                                        // 空调2
+//                                                                                                                                                                                                                                                                                      // 制冷设定温度      制冷设定灵敏度    高温告警点      低温告警点       加热设定温度      加热设定灵敏度    远程开空调
+// const u16 ADDR_CONV_HMI2AIR[ADDR_CONV_COUNT][2] = {{0x1830, 0x8202}, {0x1832, 0x8204}, {0x1834, 0x0E}, {0x1836, 0x10}, {0x1838, 0x820B}, {0x183A, 0x1E}, {0x1840, 0x0202}};                                                                                                          // 空调参数设置,触摸屏、空调485地址转换
+//                                                                                                                                                                                                                                                                                      // 制冷设定温度      制冷设定灵敏度    高温告警点      低温告警点       加热设定温度      加热设定灵敏度    远程开空调
+// const u16 ADDR_CONV_104IEC2AIR1[ADDR_CONV_COUNT][2] = {{REMOTE_REGULATE_ADDR_COOL_TEMP_AIR1, 0x8202}, {REMOTE_REGULATE_ADDR_COOL_SEN_AIR1, 0x8204}, {0, 0x0E}, {0, 0x10}, {REMOTE_REGULATE_ADDR_HOT_TEMP_AIR1, 0x820B}, {REMOTE_REGULATE_ADDR_HOT_SEN_AIR1, 0x1E}, {24618, 0x0202}}; // 空调参数设置,104地址转空调485地址
+//                                                                                                                                                                                                                                                                                      // 制冷设定温度      制冷设定灵敏度    高温告警点      低温告警点       加热设定温度      加热设定灵敏度    远程开空调
+// const u16 ADDR_CONV_104IEC2AIR2[ADDR_CONV_COUNT][2] = {{25093, 0x8202}, {25094, 0x8204}, {0, 0x0E}, {0, 0x10}, {25095, 0x820B}, {25096, 0x1E}, {24620, 0x0202}};                                                                                                                     // 空调参数设置,104地址转空调485地址
+
+// //// 写单寄存器命令格式:        控制器地址  	命令类型	  寄存器起始地址H	 寄存器起始地址L    数据1H    数据1L      CRC-L  CRC-H
+// // u8 frame_air_set[16] =         {0x01,       0x06,      0x00,              0x01,        0x00,    0x00};
+
+// const Modbus_Frame_TypeDef Air_Frame[AIR_FRAME_COUNT] = {{0x1000, 42, 3}, {0xA004, 1, 3}, {0xA013, 1, 3}, {0x0300, 17, 3}, {0x8202, 4, 3}, {0x000e, 4, 3}, {0x820b, 1, 3}, {0x1E, 1, 3}};
+
+// void Air1_HandleFrame_1st(const u8 *p, u16 size);
+// void Air1_HandleFrame_2nd(const u8 *p, u16 size);
+// void Air1_HandleFrame_3rd(const u8 *p, u16 size);
+// void Air1_HandleFrame_4th(const u8 *p, u16 size);
+// void Air1_HandleFrame_5th(const u8 *p, u16 size);
+// void Air1_HandleFrame_6th(const u8 *p, u16 size);
+// void air1_handle_frame_7th(const u8 *p, u16 size);
+// void Air1_HandleFrame_8th(const u8 *p, u16 size);
+
+// void (*Func_AirHandleFrame[AIR_FRAME_COUNT])(const u8 *p, u16 size) = {Air1_HandleFrame_1st, Air1_HandleFrame_2nd, Air1_HandleFrame_3rd, Air1_HandleFrame_4th,
+//                                                                        Air1_HandleFrame_5th, Air1_HandleFrame_6th, Air1_HandleFrame_7th, Air1_HandleFrame_8th}; //
+
+// extern os_mbx_declare(uart1_mailbox, 10); // 声明消息邮箱  读取空调数据
+
+// /****************************************************
+//  *  函 数 名:ReadAirData
+//  *  函数功能:读取空调数据
+//  *  入口参数:register_addr 寄存器地址   count 数量  p 缓冲区指针
+//  *  说    明:无
+//  *****************************************************/
+// void CopyAirData(u16 register_addr, u16 count, u16 *p)
+// {
+//     u16 offset, i;
+//     offset = register_addr - MODBUS_ADDR_AIR_READ;
+
+//     for (i = 0; i < count; i++)
+//         *p++ = Data_Air[0].data_air_buf_u16[offset + i];
+// }
+
+// /****************************************************
+//  *  函 数 名:CopyAirDataSet
+//  *  函数功能:读取空调设置参数
+//  *  入口参数:register_addr 寄存器地址   count 浮点数据数量  p 缓冲区指针
+//  *  说    明:无
+//  *****************************************************/
+// void CopyAirDataSet(u16 register_addr, u16 count, float *pFloat)
+// {
+//     u16 offset, i;
+//     u8 *pU8;
+//     offset = register_addr - MODBUS_ADDR_AIR_WRITE;
+//     pU8    = (u8 *)pFloat;
+
+//     for (i = 0; i < count * 4; i++)
+//         *pU8++ = Par_Set_Air1.par_buff_u8[4 * offset + i]; // 直接用par_buff_float赋值,硬件故障
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_1st
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_1st(const u8 *p, u16 size)
+// {
+//     u8  index = 0, slave_id = 0;
+//     u8  temp1, temp2;
+//     u16 crc;
+//     //	  OS_ERR err;
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         slave_id = 0;
+//     }
+//     else
+//     {
+//         slave_id = 1;
+//     }
+
+//     p = p + 3;
+
+//     for (index = 0; index < 14; index++) // 设备工作状态、室内风机状态、室外风机状态、压缩机状态  柜内回风温度    水泵状态    柜外温度   冷凝器温度...交流运行电流
+//     {
+//         temp1                                      = *p++;
+//         temp2                                      = *p++;
+//         Data_Air[slave_id].data_air_buf_u16[index] = (temp1 << 8) + temp2;
+//         p                                          = p + 2;
+//     }
+
+//     // 设备运行时间、压缩机运行时间、内风机运行时间、压缩机运行次数
+//     for (; index < 22; index++)
+//     {
+//         temp1                                        = *p++;
+//         temp2                                        = *p++;
+//         Data_Air[slave_id].data_air_buf_u16[index++] = (temp1 << 8) + temp2;
+//         temp1                                        = *p++;
+//         temp2                                        = *p++;
+//         Data_Air[slave_id].data_air_buf_u16[index]   = (temp1 << 8) + temp2;
+//         p += 4;
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_2nd
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_2nd(const u8 *p, u16 size)
+// {
+//     u8  temp1, temp2, slave_id = 0;
+//     u16 crc;
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         slave_id = 0;
+//     }
+//     else
+//     {
+//         slave_id = 1;
+//     }
+
+//     p                                       = p + 3;
+//     temp1                                   = (*p++);
+//     temp2                                   = (*p++);
+//     Data_Air[slave_id].data_air_buf_u16[22] = (temp1 << 8) + temp2;
+// }
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_3rd
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_3rd(const u8 *p, u16 size)
+// {
+//     u8  temp1, temp2, slave_id = 0;
+//     u16 crc;
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         slave_id = 0;
+//     }
+//     else
+//     {
+//         slave_id = 1;
+//     }
+
+//     p                                       = p + 3;
+//     temp1                                   = *p++;
+//     temp2                                   = *p++;
+//     Data_Air[slave_id].data_air_buf_u16[23] = (temp1 << 8) + temp2;
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_4th
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_4th(const u8 *p, u16 size)
+// {
+//     u8  i, slave_id = 0, temp1 = 0, temp2 = 0;
+//     u16 crc;
+
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         slave_id = 0;
+//     }
+//     else
+//     {
+//         slave_id = 1;
+//     }
+
+//     p = p + 3;
+//     for (i = 0; i < 17; i++)
+//     {
+//         temp1                                       = (*p++);
+//         temp2                                       = (*p++);
+//         Data_Air[slave_id].data_air_buf_u16[24 + i] = (temp1 << 8) + temp2;
+//         if (Data_Air[slave_id].data_air_buf_u16[24 + i] == 0x01)
+//         {
+//             Data_Air[slave_id].Data_Air_Union.serious_alarm = TRUE;
+//         }
+//     }
+//     if (Data_Air[slave_id].Data_Air_Union.serious_alarm == TRUE)
+//     {
+//         bams_set_air_status(TRUE);
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_5th
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_5th(const u8 *p, u16 size)
+// {
+//     u8                               i;
+//     u8                               temp1, temp2;
+//     u16                              crc;
+//     union Par_Set_Air_Union_TypeDef *param = NULL;
+
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         param = &Par_Set_Air1;
+//     }
+//     else
+//     {
+//         param = &Par_Set_Air2;
+//     }
+
+//     p = p + 3;
+//     for (i = 0; i < 2; i++)
+//     {
+//         temp1                    = *p++;
+//         temp2                    = *p++;
+//         param->par_buff_float[i] = (float)((temp1 << 8) + temp2) / 10.0f;
+//         p                        = p + 2;
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_6th
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_6th(const u8 *p, u16 size)
+// {
+//     u8                               i;
+//     u8                               temp1, temp2;
+//     u16                              crc;
+//     union Par_Set_Air_Union_TypeDef *param = NULL;
+
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         param = &Par_Set_Air1;
+//     }
+//     else
+//     {
+//         param = &Par_Set_Air2;
+//     }
+
+//     p = p + 3;
+//     for (i = 0; i < 2; i++)
+//     {
+//         temp1                        = (*p++);
+//         temp2                        = (*p++);
+//         param->par_buff_float[i + 2] = (float)((temp1 << 8) + temp2) / 10.0f;
+//         p                            = p + 2;
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:air1_handle_frame_7th
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void air1_handle_frame_7th(const u8 *p, u16 size)
+// {
+//     u8                               temp1, temp2;
+//     u16                              crc;
+//     union Par_Set_Air_Union_TypeDef *param = NULL;
+
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         param = &Par_Set_Air1;
+//     }
+//     else
+//     {
+//         param = &Par_Set_Air2;
+//     }
+
+//     p                        = p + 3;
+//     temp1                    = (*p++);
+//     temp2                    = (*p++);
+//     param->par_buff_float[4] = ((temp1 << 8) + temp2) / 10.0f;
+// }
+
+// /****************************************************
+//  *  函 数 名:Air1_HandleFrame_7th
+//  *  函数功能:处理空调第一帧
+//  *  入口参数: p 数据指针, size  数据个数
+//  *  说    明:无
+//  ****************************************************/
+// void Air1_HandleFrame_8th(const u8 *p, u16 size)
+// {
+//     u8                               temp1, temp2;
+//     u16                              crc;
+//     union Par_Set_Air_Union_TypeDef *param = NULL;
+
+//     // 空调返回命令格式: 控制器地址  	命令类型	  字节数n	 数据1H    数据1L     数据2H    数据2L   CRC-L  CRC-H
+
+//     crc = Count_CRC(p, size - 2);
+//     if (crc != ((p[size - 1] << 8) + (p[size - 2])))
+//         return;
+
+//     if (*p == 1)
+//     {
+//         param = &Par_Set_Air1;
+//     }
+//     else
+//     {
+//         param = &Par_Set_Air2;
+//     }
+
+//     p                        = p + 3;
+//     temp1                    = (*p++);
+//     temp2                    = (*p++);
+//     param->par_buff_float[5] = ((temp1 << 8) + temp2) / 10.0f;
+// }
+
+// /****************************************************
+//  *  函 数 名:SendFrame_SetAirParSingle
+//  *  函数功能:设置空调运行参数
+//  *  入口参数:p 数据指针,  register_addr 寄存器地址,   count 数量
+//  *  说    明:无
+//  ****************************************************/
+// void SendFrame_SetAirParSingle(float dat_float, u16 register_addr)
+// {
+//     OS_RESULT          result;
+//     UartFrame_TypeDef *pMsg;
+//     // 写单寄存器命令格式:        控制器地址  	命令类型	  寄存器起始地址H	 寄存器起始地址L    数据1H    数据1L      CRC-L  CRC-H
+//     //    u8 frame_air_set[16] =         {0x01,       0x06,      0x00,              0x01,        0x00,    0x00};
+//     u16 data = (u16)(dat_float * 10); // 下发给空调参数需放大10倍
+//     // 写多寄存器命令格式:   控制器地址  	命令类型	  寄存器起始地址H	 寄存器起始地址L   寄存器个数H	  寄存器个数L   字节数n   数据1H    数据1L     数据2H    数据2L    CRC-L  CRC-H
+//     // 写单寄存器命令格式:   控制器地址  	命令类型	  寄存器起始地址H	 寄存器起始地址L    数据1H    数据1L      CRC-L  CRC-H
+//     os_mut_wait(&mutex_uart1, 0xffff); // 永久等待互斥资源
+//     ModbusRtu_SendFrame06(register_addr, data, Uart1DMA_SendData);
+
+//     result = os_mbx_wait(&uart1_mailbox, (void *)&pMsg, TIME_200MS);
+//     if (result == OS_R_OK || result == OS_R_MBX) // 成功获得消息
+//     {
+//         pMsg = pMsg; // 添加该语句,防止if被优化掉
+//     }
+//     os_mut_release(&mutex_uart1); // 释放互斥资源
+// }
+
+// /****************************************************
+//  *  函 数 名:ReadAirData
+//  *  函数功能:读取空调数据数据帧
+//  *  入口参数:register_addr 寄存器地址   count 数量   frame_style 报文类型
+//  *  说    明:无
+//  *****************************************************/
+// void ReadAirData(void)
+// {
+//     OS_RESULT          result;
+//     UartFrame_TypeDef *pMsg;
+//     static u8          air1_index = 0; // 1#空调帧序号
+//     void (*ModbusSendFrame)(u16 register_addr, u16 count, void (*Func_Send)(const u8 *data, u16 count));
+//     const Modbus_Frame_TypeDef *air_frame;
+
+//     air_frame       = &Air_Frame[air1_index];
+//     ModbusSendFrame = Func_ModbusRtu_SendFrame[air_frame->frame_style];                      // 指向具体发送帧函数
+//     ModbusSendFrame(air_frame->register_addr, air_frame->register_count, Uart1DMA_SendData); // 发送报文
+
+//     /* 等待uart1收到数据,不阻塞任务 */
+//     result = os_mbx_wait(&uart1_mailbox, (void *)&pMsg, TIME_200MS);
+//     if (result == OS_R_OK || result == OS_R_MBX) // 成功获得消息
+//     {
+//         if (pMsg->len > 2)
+//         {
+//             Func_AirHandleFrame[air1_index](pMsg->buf, pMsg->len); // 解析报文
+//         }
+//     }
+//     air1_index++;
+//     if (air1_index >= AIR_FRAME_COUNT)
+//         air1_index = 0;
+// }
+
+// /****************************************************
+//  *  函 数 名:Air_Find485Addr
+//  *  函数功能:空调参数设置,触摸屏485地址转换到空调485地址
+//  *  入口参数:hmi_addr 触摸屏485地址
+//  *  返回参数:空调485地址
+//  *  说    明:0 没找到对应空调485地址
+//  *****************************************************/
+// u16 AddrConv_Hmi2Air(u16 hmi_addr)
+// {
+//     u8 i;
+//     for (i = 0; i < ADDR_CONV_COUNT; i++)
+//     {
+//         if (ADDR_CONV_HMI2AIR[i][0] == hmi_addr)
+//         {
+//             return ADDR_CONV_HMI2AIR[i][1];
+//         }
+//     }
+//     return FALSE;
+// }
+
+// /****************************************************
+//  *  函 数 名:AddrConv_104IEC2Air1
+//  *  函数功能:空调1 104地址转换到485地址
+//  *  入口参数:i104_addr 104地址
+//  *  返回参数:空调485地址
+//  *  说    明:0 没找到对应空调485地址
+//  *****************************************************/
+// u16 AddrConv_104IEC2Air1(u16 i104_addr)
+// {
+//     u8 i;
+//     for (i = 0; i < ADDR_CONV_COUNT; i++)
+//     {
+//         if (ADDR_CONV_104IEC2AIR1[i][0] == i104_addr)
+//         {
+//             return ADDR_CONV_104IEC2AIR1[i][1];
+//         }
+//     }
+//     return FALSE;
+// }
+
+// /****************************************************
+//  *  函 数 名:AddrConv_104IEC2Air2
+//  *  函数功能:空调2 104地址转换到485地址
+//  *  入口参数:i104_addr 104地址
+//  *  返回参数:空调485地址
+//  *  说    明:0 没找到对应空调485地址
+//  *****************************************************/
+// u16 AddrConv_104IEC2Air2(u16 i104_addr)
+// {
+//     u8 i;
+//     for (i = 0; i < ADDR_CONV_COUNT; i++)
+//     {
+//         if (ADDR_CONV_104IEC2AIR2[i][0] == i104_addr)
+//         {
+//             return ADDR_CONV_104IEC2AIR2[i][1];
+//         }
+//     }
+//     return FALSE;
+// }
+
+// /****************************************************
+//  *  函 数 名:HMI_10Frame_ParSetAir
+//  *  函数功能:HMI 10帧空调参数设置
+//  *  入口参数:register_addr 寄存器地址   p 缓冲区指针
+//  *  说    明:一次只能设置一个参数
+//  *****************************************************/
+// void HMI_10Frame_ParSetAir(u16 register_addr, const float *pFloat)
+// {
+//     u16 offset, addr_air;
+//     offset = (register_addr - MODBUS_ADDR_AIR_WRITE) / 2; // 0x1830    0x1832     0x1834    0x1836
+//     memcpy((u8 *)&Par_Set_Air1.par_buff_float[offset], (u8 *)pFloat, 4);
+
+//     addr_air = AddrConv_Hmi2Air(register_addr);
+//     if (addr_air != DEF_FALSE)
+//         SendFrame_SetAirParSingle(Par_Set_Air1.par_buff_float[offset], addr_air);
+// }
+
+// /****************************************************
+//  *  函 数 名:I104_ParSetAir1
+//  *  函数功能:104设置空调1参数
+//  *  入口参数:i104_addr: 104地址   data :参数
+//  *  说    明:无
+//  *****************************************************/
+// void I104_ParSetAir1(u16 i104_addr, float data)
+// {
+//     u16 addr_air;
+//     addr_air = AddrConv_104IEC2Air1(i104_addr);
+//     if (addr_air != DEF_FALSE)
+//         SendFrame_SetAirParSingle(data, addr_air);
+// }
+
+// /****************************************************
+//  *  函 数 名:SendFrame_SwitchAir
+//  *  函数功能:发送数据帧,开关空调
+//  *  入口参数:addr_device:空调设备地址   addr_air: 寄存器地址   data:  开关指令
+//  *  说    明:无
+//  *****************************************************/
+// void SendFrame_SwitchAir(u8 addr_device, u16 addr_air, u16 data)
+// {
+//     OS_RESULT          result;
+//     UartFrame_TypeDef *pMsg;
+//     //// 写单寄存器命令格式:        控制器地址  	命令类型	  寄存器起始地址H	 寄存器起始地址L    数据1H    数据1L      CRC-L  CRC-H
+//     os_mut_wait(&mutex_uart1, 0xffff); // 永久等待互斥资源
+
+//     ModbusRtu_SendFrame06(addr_air, data, Uart1DMA_SendData);
+//     result = os_mbx_wait(&uart1_mailbox, (void *)&pMsg, TIME_200MS);
+//     if (result == OS_R_OK || result == OS_R_MBX) // 成功获得消息
+//     {
+//         pMsg = pMsg; // 添加该语句,防止if被优化掉
+//     }
+//     os_mut_release(&mutex_uart1); // 释放互斥资源
+// }
+
+// /****************************************************
+//  *  函 数 名:HMI_10Frame_ParSetAir
+//  *  函数功能:HMI开关空调
+//  *  入口参数:register_addr 寄存器地址   data  开关指令
+//  *  说    明:无
+//  *****************************************************/
+// void HMI_10Frame_SwitchAir(u16 addr_hmi, u16 data)
+// {
+//     u16 addr_air;
+
+//     addr_air = AddrConv_Hmi2Air(addr_hmi);
+//     if (addr_air != DEF_FALSE)
+//     {
+//         SendFrame_SwitchAir(1, addr_air, data);
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:I104_SwitchAir1
+//  *  函数功能:104开关空调1
+//  *  入口参数:addr_104: 104地址   data:  开关指令
+//  *  说    明:无
+//  *****************************************************/
+// void I104_SwitchAir1(u16 addr_104, u8 data)
+// {
+//     u16 addr_air;
+
+//     addr_air = AddrConv_104IEC2Air1(addr_104);
+//     if (addr_air != DEF_FALSE)
+//     {
+//         SendFrame_SwitchAir(1, addr_air, data);
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:Uart_air_test
+//  *  函数功能:Uart1通信测试
+//  *  入口参数:addr_104: 104地址   data:  开关指令
+//  *  说    明:无
+//  *****************************************************/
+// void Uart_air_test(void)
+// {
+//     OS_RESULT          result = OS_R_OK;
+//     UartFrame_TypeDef *pMsg;
+//     u8                 uart1_test_buf[3] = {0};
+//     result                               = os_mbx_wait(&uart1_mailbox, (void *)&pMsg, TIME_1000MS);
+//     if (result == OS_R_OK || result == OS_R_MBX) // 成功获得消息
+//     {
+//         if ((pMsg->buf[0] == 0xAA) && (pMsg->buf[1] == 0xBB))
+//         {
+//             uart1_test_buf[0] = 0xBB;
+//             uart1_test_buf[1] = 0xAA;
+//             Uart1DMA_SendData(uart1_test_buf, 2);
+//         }
+//         else if ((pMsg->buf[0] == 0xAB) && (pMsg->buf[1] == 0xAB))
+//         {
+//             uart1_test_buf[0] = 0xBA;
+//             uart1_test_buf[1] = 0xBA;
+//             Uart1DMA_SendData(uart1_test_buf, 2);
+//             bams_set_uart_flag(FALSE);
+//         }
+//         else if ((pMsg->buf[0] == 0x01) && (pMsg->buf[1] == 0xAA) && (pMsg->buf[2] == 0xBB))
+//         {
+//             uart1_test_buf[0] = 0x01;
+//             uart1_test_buf[1] = 0xBB;
+//             uart1_test_buf[2] = 0xAA;
+//             Uart1DMA_SendData(uart1_test_buf, 3);
+//         }
+//     }
+// }

+ 139 - 0
User/app/air/air.h

@@ -0,0 +1,139 @@
+// #ifndef __AIR_H
+// #define __AIR_H
+
+// #include "ModbusRtu.h"
+// #include "project_var.h"
+// #include "tcp_demo.h"
+
+// #pragma pack(1)
+// // 空调数据
+// typedef struct
+// {
+//     u16 air_work_state;              // 空调工作状态
+//     u16 fan_in_state;                // 室内风机状态
+//     u16 fan_out_state;               // 室外风机状态
+//     u16 compressor_state;            // 压缩机状态
+//     u16 return_air_temp;             // 回风温度
+//     u16 pump_state;                  //
+//     u16 outside_temp;                //
+//     u16 condenser_temp;              // 冷凝器温度
+//     u16 evaporator_temp;             // 蒸发器温度
+//     u16 speed_fan_in;                // 内风机转速
+//     u16 speed_fan_out;               // 外风机转速
+//     u16 voltage_ac_input;            // 交流输入电压
+//     u16 voltage_dc_input;            // 直流输入电压
+//     u16 current_ac_run;              // 交流允许电流
+//     u16 run_time1_air;               // 空调运行时间 高字节
+//     u16 run_time2_air;               // 空调运行时间 低字节
+//     u16 run_time1_compressor;        // 压缩机运行时间 高字节
+//     u16 run_time2_compressor;        // 压缩机运行时间 低字节
+//     u16 run_time1_fan_in;            // 室内风机运行时间 高字节
+//     u16 run_time2_fan_in;            // 室内风机行时间 低字节
+//     u16 action_time1_compressor;     // 室内风机运行次数  高字节
+//     u16 action_time2_compressor;     // 室内风机运行次数  低字节
+//     u16 blowing_temp;                // 送风温度
+//     u16 return_air_humidity;         // 回风湿度
+//     u16 alarm_high_temp;             // 高温报警   // 报警
+//     u16 fault_fan_in;                // 内风机故障
+//     u16 fault_fan_out;               // 外风机故障
+//     u16 fault_compressor;            // 压缩机故障
+//     u16 detector_temp;               // 回风温度探头故障
+//     u16 alarm_high_presure;          // 系统高压力报警
+//     u16 alarm_low_temp;              // 低温报警
+//     u16 alarm_dc_over;               // 直流过压报警
+//     u16 alarm_dc_under;              // 直流欠压报警
+//     u16 alarm_ac_over;               // 交流过压报警
+//     u16 alarm_ac_under;              // 交流欠压报警
+//     u16 alarm_ac_drop;               // 交流掉电报警
+//     u16 fault_evaporator_sensor;     // 蒸发器温度传感器故障
+//     u16 fault_condenser_sensor;      // 冷凝器故障温度传感器故障
+//     u16 fault_env_sensor;            // 环境温度传感器故障
+//     u16 alarm_evaporator_freeze;     // 蒸发器冻结报警
+//     u16 alarm_high_presure_frequent; // 频繁高压力报警
+//     u16 serious_alarm;               // 严重告警总状态
+
+// } Data_Air_TypeDef;
+
+// union Data_Air_Union_TypeDef
+// {
+//     u8               data_air_buf_u8[96];
+//     u16              data_air_buf_u16[48];
+//     Data_Air_TypeDef Data_Air_Union;
+// };
+
+// // 参数设置
+// typedef struct
+// {
+//     float cold_value;       // 设定制冷温度
+//     float cold_sensitivity; // 制冷设定灵敏度
+//     float hot_temp;         //  高温告警点
+//     float cold_temp;        // 低温告警点
+//     float hot_value;        // 加热设定温度
+//     float hot_sensitivity;  // 加热设定灵敏度
+//     u16   data5;
+//     u16   data6;
+//     u16   data9;
+//     u16   data10;
+//     u16   data11;
+//     u16   data12;
+//     u16   data13;
+//     u16   data14;
+//     u16   data15;
+//     u16   data16;
+// } Par_Set_Air_TypeDef;
+
+// union Par_Set_Air_Union_TypeDef
+// {
+//     u8                  par_buff_u8[32];
+//     float               par_buff_float[8];
+//     Par_Set_Air_TypeDef ParSet_AirUnion; //
+// };
+
+// ////空调 03请求帧
+// // typedef struct
+// //{
+// //	  u8   addr;       //
+// //		u8   function;   //
+// //	  u16  register_addr;
+// //	  u16  register_count;
+// //	  u16 crc;
+// // }Air_03Frame_Tx_TypeDef;
+
+// // union Air_03Frame_Tx_Union_TypeDef
+// //{
+// //	  Air_03Frame_Tx_TypeDef  Frame03;    //
+// //	  u8  send_buff[16];
+// // };
+
+// #pragma pack() // 取消自定义字节对齐方式
+
+// extern union Data_Air_Union_TypeDef Data_Air[2];
+// // extern union Par_Set_Air_Union_TypeDef   Par_Set_Air;
+
+// void CopyAirData(u16 register_addr, u16 count, u16 *p); // 读取空调数据
+
+// void SendFrame_ReadAirData(u16 register_addr, u16 count); // 发送读取空调数据数据帧
+
+// void HandleAirData(u8 *p, u8 frame_style, u16 size);
+// void HandleAirData1(u8 *p, u8 frame_style, u16 size);
+
+// void SendFrame_SetAirPar(u8 *p, u16 register_addr, u16 count); // 设置空调运行参数
+
+// void CopyAirDataSet(u16 register_addr, u16 count, float *p);
+
+// // void ReadAirData(u16 register_addr, u16 count, u8  frame_style);  // 读取空调数据数据帧
+// void ReadAirData(void); // 读取空调数据数据帧
+
+// void HMI_10Frame_ParSetAir(u16 register_addr, const float *p);
+
+// void HMI_10Frame_SwitchAir(u16 register_addr, u16 data);
+
+// void I104_SwitchAir1(u16 addr_104, u8 data); // 104开关空调1
+// void I104_SwitchAir2(u16 addr_104, u8 data); // 104开关空调2
+
+// void I104_ParSetAir1(u16 i104_addr, float data); // 104设置空调1参数
+// void I104_ParSetAir2(u16 i104_addr, float data); // 104设置空调2参数
+
+// void Uart_air_test(void);
+
+// #endif

+ 0 - 92
User/app/esp8266/esp8266.c

@@ -1,92 +0,0 @@
-#include "esp8266.h"
-
-void esp_8266_task(void)
-{
-    INT8U              err = 0;
-    UartFrame_TypeDef *msg;
-    INT8U              esp_state = 0;
-    while (1) //等待倒计时
-    {
-        iwdg_feed(UART6_DOG);
-        switch (esp_state)
-        {
-        case ESP_CWMODE:
-            uart6_dma_send("AT+CWMODE=1\r\n", sizeof("AT+CWMODE=1\r\n"));
-            OSTimeDly(1000);
-            break;
-        case ESP_RST:
-            uart6_dma_send("AT+RST\r\n", sizeof("AT+RST\r\n"));
-            OSTimeDly(1000);
-            OSTimeDly(1000);
-            OSTimeDly(1000);
-            break;
-        case ESP_CWJAP:
-            uart6_dma_send("AT+CWJAP=\"FCC\",\"347470868\"\r\n", sizeof("AT+CWJAP=\"FCC\",\"347470868\"\r\n"));
-            OSTimeDly(100);
-            break;
-        case ESP_MUX:
-            uart6_dma_send("AT+CIPMUX=1\r\n", sizeof("AT+CIPMUX=1\r\n"));
-            OSTimeDly(100);
-            break;
-        case ESP_SERVER:
-            uart6_dma_send("AT+CIPSERVER=1,8086\r\n", sizeof("AT+CIPSERVER=1,8086\r\n"));
-            OSTimeDly(100);
-            break;
-        case ESP_SEND_STATE:
-            uart6_dma_send("AT+CIPSEND=0,25\r\n", sizeof("AT+CIPSEND=0,25\r\n"));
-            OSTimeDly(200);
-            break;
-        case ESP_SEND_WORK:
-            uart6_dma_send("dsadsadsadsadsadasds\r\n", sizeof("sadsadsadsadsadasds\r\n"));
-            OSTimeDly(100);
-            break;
-        default:
-            break;
-        }
-
-        msg = (UartFrame_TypeDef *)OSMboxPend(uart6_mbox, 500, &err);
-        if ((err == OS_ERR_NONE) && (msg->len >= 0))
-        {
-            if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_CWMODE)
-            {
-                esp_state = ESP_RST;
-            }
-            else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_RST)
-            {
-                // printf(msg->buf);
-                esp_state = ESP_CWJAP;
-            }
-            else if (strstr((const char *)msg, (const char *)"WIFI GOT IP") && esp_state == ESP_CWJAP)
-            {
-                printf(msg->buf);
-                esp_state = ESP_MUX;
-            }
-            else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_MUX)
-            {
-                printf(msg->buf);
-                esp_state = ESP_SERVER;
-            }
-            else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SERVER)
-            {
-                printf(msg->buf);
-                esp_state = ESP_SEND_STATE;
-            }
-            else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SEND_STATE)
-            {
-                printf(msg->buf);
-                esp_state = ESP_SEND_WORK;
-            }
-            else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SEND_WORK)
-            {
-                printf(msg->buf);
-                esp_state = ESP_SEND_STATE;
-            }
-            else
-            {
-                printf(msg->buf);
-                // return;
-            }
-        }
-        OSTimeDly(100);
-    }
-}

+ 0 - 18
User/app/esp8266/esp8266.h

@@ -1,18 +0,0 @@
-#ifndef __ESP8266_H__
-#define __ESP8266_H__
-
-#include "fly_param.h"
-#include "interface.h"
-#include "iwdg.h"
-#include "uart6.h"
-
-#define ESP_CWMODE     0
-#define ESP_RST        1
-#define ESP_CWJAP      2
-#define ESP_MUX        3
-#define ESP_SERVER     4
-#define ESP_SEND_STATE 5
-#define ESP_SEND_WORK  6
-
-void esp_8266_task(void);
-#endif

+ 8 - 8
User/app/fly_param.c

@@ -10,14 +10,14 @@ OS_EVENT *can2_sem     = NULL;
 OS_EVENT *net_sem      = NULL;
 OS_EVENT *uart1_mbox   = NULL;
 OS_EVENT *uart3_mbox   = NULL;
-OS_EVENT *uart6_mbox   = NULL;
 
-SqQueue CanQueueCan1;
-SqQueue CanQueueCan2;
+SqQueue CanQueueCan1 __attribute__((section("EXT_SRAM")));
+SqQueue CanQueueCan2 __attribute__((section("EXT_SRAM")));
 
-CPU_STK uart1_task_stk[UART1_TASK_STK_SIZE];
-CPU_STK uart3_task_stk[UART3_TASK_STK_SIZE];
-CPU_STK uart6_task_stk[UART6_TASK_STK_SIZE];
+CPU_STK uart1_task_stk[UART1_TASK_STK_SIZE] __attribute__((section("EXT_SRAM")));
+CPU_STK uart3_task_stk[UART3_TASK_STK_SIZE] __attribute__((section("EXT_SRAM")));
 CPU_STK init_task_stk[INIT_STK_SIZE];
-CPU_STK net_task_stk[NET_TASK_STK_SIZE];
-CPU_STK misc_task_stk[MISC_TASK_STK_SIZE];
+CPU_STK iec104_task_stk[IEC_TASK_STK_SIZE]; //__attribute__((section("EXT_SRAM")));
+CPU_STK iec_state_task_stk[IEC_STATE_TASK_STK_SIZE];
+CPU_STK tcp_task_stk[TCP_TASK_STK_SIZE];
+CPU_STK misc_task_stk[MISC_TASK_STK_SIZE]; //__attribute__((section("EXT_SRAM")));

+ 14 - 15
User/app/fly_param.h

@@ -1,35 +1,33 @@
 #ifndef __FLY_PARAM_H
 #define __FLY_PARAM_H
 #include "includes.h"
-// #include "ext_flash.h"
 #include "queue.h"
-// #include "soc_out.h"
-// #include "bms_config.h"
 #include <string.h>
 
 #define CAN_MSG_LEN 8
 
 #define UART1_TASK_PRIO 23
 #define UART3_TASK_PRIO 24
-#define UART6_TASK_PRIO 25
 #define MISC_PRIO       28
-#define NET_PRIO        30
+#define IEC_PRIO        30
+#define IEC_STATE_PRIO  32
+#define TCP_PRIO        31
 #define INIT_TASK_PRIO  35
 
-#define INIT_STK_SIZE       128
-#define MISC_TASK_STK_SIZE  512
-#define NET_TASK_STK_SIZE   512
-#define LED1_STK_SIZE       512
-#define UART1_TASK_STK_SIZE 256
-#define UART3_TASK_STK_SIZE 256
-#define UART6_TASK_STK_SIZE 256
+#define INIT_STK_SIZE           128
+#define MISC_TASK_STK_SIZE      512
+#define IEC_TASK_STK_SIZE       1024
+#define IEC_STATE_TASK_STK_SIZE 512
+#define TCP_TASK_STK_SIZE       512
+#define LED1_STK_SIZE           512
+#define UART1_TASK_STK_SIZE     256
+#define UART3_TASK_STK_SIZE     256
 
 extern OS_EVENT *net_mutex;
 extern OS_EVENT *can1_sem;
 extern OS_EVENT *can2_sem;
 extern OS_EVENT *uart1_mbox;
 extern OS_EVENT *uart3_mbox;
-extern OS_EVENT *uart6_mbox;
 
 extern SqQueue CanQueueCan1;
 extern SqQueue CanQueueCan2;
@@ -37,8 +35,9 @@ extern SqQueue CanQueueCan2;
 extern CPU_STK init_task_stk[INIT_STK_SIZE];
 extern CPU_STK uart1_task_stk[UART1_TASK_STK_SIZE];
 extern CPU_STK uart3_task_stk[UART3_TASK_STK_SIZE];
-extern CPU_STK uart6_task_stk[UART6_TASK_STK_SIZE];
 extern CPU_STK misc_task_stk[MISC_TASK_STK_SIZE];
-extern CPU_STK net_task_stk[NET_TASK_STK_SIZE];
+extern CPU_STK iec104_task_stk[IEC_TASK_STK_SIZE];
+extern CPU_STK iec_state_task_stk[IEC_STATE_TASK_STK_SIZE];
+extern CPU_STK tcp_task_stk[TCP_TASK_STK_SIZE];
 
 #endif

+ 0 - 1358
User/app/iec104/iec101.c

@@ -1,1358 +0,0 @@
-
-
-#include "iec101.h"
-#include "iec10x_conf.h"
-#include "iec10x_type.h"
-
-#ifdef IEC101_SET
-/*
- * GLOABLE VARIALBLE
- */
-iec_8u Iec101_Respon_Confirm = 0;
-iec_8u Iec101_Sendbuf[IEC101_MAX_BUF_LEN];
-
-iec_8u  IEC10X_Call_AllQoi   = 0;
-iec_8u  IEC10X_Call_GroupQoi = 0;
-iec_16u IEC101_Pulse_Cnt     = 0;
-
-/*
- * STATE
- * */
-iec_8u IEC101_STATE_FLAG_INIT    = IEC101_FLAG_LINK_CLOSED;
-iec_8u IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_LINK_CLOSED;
-iec_8u IEC101_STATE_FLAG_GROUP   = IEC101_FLAG_LINK_CLOSED;
-iec_8u IEC101_STATE_FLAG_CLOCK   = IEC101_FLAG_LINK_CLOSED;
-iec_8u IEC101_STATE_FLAG_DELAY   = IEC101_FLAG_LINK_CLOSED;
-iec_8u IEC101_STATE_FLAG_PULSE   = IEC101_FLAG_LINK_CLOSED;
-
-iec_8u IEC10X_RetStatusOk(iec_16u addr)
-{
-
-    iec_16u      len;
-    PIEC101_10_T Iec10x = (PIEC101_10_T)Iec101_Sendbuf;
-
-    len = IEC101_STABLE_LEN;
-
-    Iec10x->_begin = IEC101_STABLE_BEGING;
-
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_SLAVE;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CAN_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_RES_LINK_STATUS;
-
-    Iec10x->_addr = addr;
-    Iec10x->_cs   = Iec101_Sendbuf[1] + Iec101_Sendbuf[2] + Iec101_Sendbuf[3];
-    Iec10x->_end  = IEC101_STABLE_END;
-
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_INITLINK, NULL, NULL);
-
-    return RET_SUCESS;
-}
-static iec_8u IEC10X_ResConfirm(iec_8u Prio)
-{
-
-    iec_16u len;
-
-    PIEC101_10_T Iec10x = (PIEC101_10_T)Iec101_Sendbuf;
-
-    len = IEC101_STABLE_LEN;
-
-    Iec10x->_begin = IEC101_STABLE_BEGING;
-
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_SLAVE;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CAN_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_RES_CONFIRM;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    Iec10x->_cs   = Iec101_Sendbuf[1] + Iec101_Sendbuf[2] + Iec101_Sendbuf[3];
-    Iec10x->_end  = IEC101_STABLE_END;
-
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, Prio, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC10X_ReqLinkStatus()
-{
-
-    iec_16u len;
-
-    PIEC101_10_T Iec10x = (PIEC101_10_T)Iec101_Sendbuf;
-
-    LOG("%s \n", __FUNCTION__);
-
-    len = IEC101_STABLE_LEN;
-
-    Iec10x->_begin = IEC101_STABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.down._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.down._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.down._fcb = IEC101_CTRL_FCB_OPPO_NONE;
-    Iec10x->_ctrl.down._fcv = IEC101_CTRL_FCV_DISABLE;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_REQ_LINK_STATUS;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    Iec10x->_cs   = Iec101_Sendbuf[1] + Iec101_Sendbuf[2] + Iec101_Sendbuf[3];
-    Iec10x->_end  = IEC101_STABLE_END;
-
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_INITLINK, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC10X_ResetLink(void)
-{
-
-    iec_16u len;
-
-    PIEC101_10_T Iec10x = (PIEC101_10_T)Iec101_Sendbuf;
-
-    len = IEC101_STABLE_LEN;
-
-    Iec10x->_begin = IEC101_STABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.down._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.down._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.down._fcb = IEC101_CTRL_FCB_OPPO_NONE;
-    Iec10x->_ctrl.down._fcv = IEC101_CTRL_FCV_DISABLE;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_RESET_LINK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    Iec10x->_cs   = Iec101_Sendbuf[1] + Iec101_Sendbuf[2] + Iec101_Sendbuf[3];
-    Iec10x->_end  = IEC101_STABLE_END;
-
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_INITLINK, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC101_BuildFinInit(void)
-{
-
-    iec_16u len     = 0;
-    iec_8u  cs_temp = 0, i;
-
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_WITH_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = Iec10x_M_EI_NA_1;
-    asdu->_num._num       = 1;
-    asdu->_reason._reason = IEC10X_ASDU_REASON_INIT;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr       = IEC10X_INFO_ADDR_NONE;
-    info->_element[0] = 0;
-
-    /*len*/
-    len          = IEC101_VARIABLE_LEN + asdu->_num._num;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_INITLINK, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC101_BuildActConfirm(iec_8u qoi, iec_8u Prio)
-{
-
-    iec_16u len     = 0;
-    iec_8u  cs_temp = 0, i;
-
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = IEC10X_C_IC_NA_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = 1;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_ASDU_REASON_ACTCON;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr       = IEC10X_INFO_ADDR_NONE;
-    info->_element[0] = qoi;
-    /*len*/
-    len          = IEC101_VARIABLE_LEN + asdu->_num._num;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, Prio, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC101_BuildActFinish(iec_8u qoi, iec_8u Prio)
-{
-
-    iec_16u len     = 0;
-    iec_8u  cs_temp = 0, i;
-
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_WITH_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = IEC10X_C_IC_NA_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = 1;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_ASDU_REASON_ACTTERM;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr       = IEC10X_INFO_ADDR_NONE;
-    info->_element[0] = qoi;
-
-    /*len*/
-    len          = IEC101_VARIABLE_LEN + asdu->_num._num;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, Prio, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC101_BuildSignal(iec_8u reason, iec_8u Prio)
-{
-
-    iec_16u len     = 0, addr;
-    iec_8u  cs_temp = 0, i, asdu_num = 0, *ptr = NULL, signal, sum;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    /*get value*/
-    IEC10X->GetStationInfo(&addr, 0, &asdu_num);
-    len = IEC101_STABLE_LEN;
-    LOG("-%s- total info (%d) \n\n", __FUNCTION__, asdu_num);
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_WITH_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = IEC10X_M_SP_NA_1;
-    asdu->_num._sq        = 1;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = reason;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr = IEC10X_INFO_ADDR_SIG_BASE + IEC10X_INFO_ADDR_SIG_TEMP_HX_OFF;
-
-    /*signal value*/
-    ptr = info->_element;
-    for (i = 0; i < asdu_num; i++)
-    {
-        if (IEC10X->GetStationInfo(&addr, i, &asdu_num) == RET_SUCESS)
-            *ptr = 1;
-        else
-            *ptr = 0;
-        ptr++;
-    }
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, Prio, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC101_BuildDetect(iec_8u reason, iec_8u type, iec_8u Prio)
-{
-
-    iec_16u            len     = 0, addr;
-    iec_8u             cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-    PIEC10X_DETECT_T   detect   = NULL;
-    PIEC10X_DETECT_F_T detect_f = NULL;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    /*get value*/
-    IEC10X->GetStationInfo(&addr, 0, &asdu_num);
-    LOG("-%s- total info (%d) \n\n", __FUNCTION__, asdu_num);
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = type;
-    asdu->_num._sq        = 1;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = reason;
-    asdu->_addr           = Iec10x_Sta_Addr;
-
-    /*info*/
-    info->_addr = IEC10X_INFO_ADDR_DET + IEC10X_INFO_ADDR_DET_TEMP_HX_OFF;
-
-    /*Detect value*/
-    ptr = info->_element;
-    for (i = 0; i < asdu_num; i++)
-    {
-        /*short int*/
-        if (type == IEC10X_M_ME_NA_1)
-        {
-            detect          = (PIEC10X_DETECT_T)ptr;
-            detect->_detect = IEC10X->GetStaTemp(i);
-            detect->_qds    = 0;
-            ptr += sizeof(IEC10X_DETECT_T);
-        }
-        /*float*/
-        else if (type == IEC10X_M_ME_NC_1)
-        {
-            detect_f          = (PIEC10X_DETECT_F_T)ptr;
-            detect_f->_detect = IEC10X->GetStaTemp(i);
-            detect_f->_qds    = 0;
-            ptr += sizeof(IEC10X_DETECT_F_T);
-        }
-    }
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;       /* add cs+end*/
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, Prio, NULL, NULL);
-
-    return RET_SUCESS;
-}
-
-iec_8u IEC101_BuildSignal_Spont(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV)
-{
-
-    iec_16u       len     = 0;
-    iec_8u        cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-    PCP56Time2a_T time = NULL;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    if (TimeFlag != 1 && TimeFlag != 0)
-    {
-        LOG("-%s-, error time flag(%d) \n", __FUNCTION__, TimeFlag);
-        return RET_ERROR;
-    }
-    LOG("-%s-, time flag(%d) signalV(%d) \n", __FUNCTION__, TimeFlag, signalV);
-    /*get value*/
-    asdu_num = 1;
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_WITH_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    if (TimeFlag == 0)
-        asdu->_type = IEC10X_M_SP_NA_1;
-    else
-        asdu->_type = IEC10X_M_SP_TB_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_COT_SPONT;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr = addrV;
-
-    /*signal value*/
-    ptr = info->_element;
-    for (i = 0; i < asdu_num; i++)
-    {
-        *ptr = signalV;
-        ptr++;
-    }
-    if (TimeFlag == 1)
-    {
-        time = (PCP56Time2a_T)ptr;
-        IEC10X->GetTime(time);
-        ptr += sizeof(CP56Time2a_T);
-    }
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_SPON, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC101_BuildDetect_Spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV)
-{
-
-    iec_16u          len     = 0;
-    iec_8u           cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-    PIEC10X_DETECT_T detect = NULL;
-    PCP56Time2a_T    time   = NULL;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    if (TimeFlag != 1 && TimeFlag != 0)
-    {
-        LOG("-%s-, error time flag(%d) \n", __FUNCTION__, TimeFlag);
-        return RET_ERROR;
-    }
-
-    /*get value*/
-    asdu_num = 1;
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    if (TimeFlag == 0)
-        asdu->_type = IEC10X_M_ME_NA_1;
-    else
-        asdu->_type = IEC10X_M_ME_TD_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_COT_SPONT;
-    asdu->_addr           = Iec10x_Sta_Addr;
-
-    /*info*/
-    info->_addr = addrV;
-
-    /*Detect value*/
-    ptr             = info->_element;
-    detect          = (PIEC10X_DETECT_T)ptr;
-    detect->_detect = detectV->_detect;
-    detect->_qds    = detectV->_qds;
-    ptr += sizeof(IEC10X_DETECT_T);
-    if (TimeFlag == 1)
-    {
-        time = (PCP56Time2a_T)ptr;
-        IEC10X->GetTime(time);
-        ptr += sizeof(CP56Time2a_T);
-    }
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;       /* add cs+end*/
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_SPON, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC101_BuildDetectF_Spont(iec_8u TimeFlag, float detectV, iec_16u addrV)
-{
-
-    iec_16u            len     = 0;
-    iec_8u             cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-    PIEC10X_DETECT_F_T detect = NULL;
-    PCP56Time2a_T      time   = NULL;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    if (TimeFlag != 1 && TimeFlag != 0)
-    {
-        LOG("-%s-, error time flag(%d) \n", __FUNCTION__, TimeFlag);
-        return RET_ERROR;
-    }
-
-    /*get value*/
-    asdu_num = 1;
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    if (TimeFlag == 0)
-        asdu->_type = IEC10X_M_ME_NC_1;
-    else
-        asdu->_type = IEC10X_M_ME_TF_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_COT_SPONT;
-    asdu->_addr           = Iec10x_Sta_Addr;
-
-    /*info*/
-    info->_addr = addrV;
-
-    /*Detect value*/
-    ptr             = info->_element;
-    detect          = (PIEC10X_DETECT_F_T)ptr;
-    detect->_detect = detectV;
-    detect->_qds    = 0;
-    ptr += sizeof(IEC10X_DETECT_F_T);
-    if (TimeFlag == 1)
-    {
-        time = (PCP56Time2a_T)ptr;
-        IEC10X->GetTime(time);
-        ptr += sizeof(CP56Time2a_T);
-    }
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;       /* add cs+end*/
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_SPON, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC101_BuildDelayAct(iec_16u delay_time)
-{
-
-    iec_16u len     = 0;
-    iec_8u  cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-    iec_16u cp16time2a = delay_time;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-
-    /*get value*/
-    asdu_num = 1;
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = IEC10X_C_CD_NA_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_COT_ACTCON;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr = IEC10X_INFO_ADDR_NONE;
-
-    /*delay value*/
-    ptr             = info->_element;
-    *(iec_16u *)ptr = IEC10X_Cp16time2a;
-    ptr += 2;
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_DELAY, NULL, NULL);
-
-    return RET_SUCESS;
-}
-iec_8u IEC101_BuildClockAct()
-{
-
-    iec_16u len     = 0;
-    iec_8u  cs_temp = 0, i, asdu_num = 0, *ptr = NULL;
-
-    /*init struct*/
-    PIEC101_68_T   Iec10x = (PIEC101_68_T)Iec101_Sendbuf;
-    PIEC10X_ASDU_T asdu   = (PIEC10X_ASDU_T)(Iec10x->_asdu);
-    PASDU_INFO_T   info   = (PASDU_INFO_T)(asdu->_info);
-    PCP56Time2a_T  time   = (PCP56Time2a_T)(info->_element);
-
-    /*get value*/
-    asdu_num = 1;
-
-    len = IEC101_STABLE_LEN;
-
-    /*head*/
-    Iec10x->_begin = Iec10x->_begin_cfm = IEC101_VARIABLE_BEGING;
-
-    /*Ctrol*/
-    Iec10x->_ctrl.up._dir = IEC101_CTRL_DIR_UP;
-    Iec10x->_ctrl.up._prm = IEC101_CTRL_PRM_MASTER;
-    Iec10x->_ctrl.up._acd = IEC101_CTRL_ACD_NONE_DATA;
-    Iec10x->_ctrl.up._dfc = IEC101_CTRL_DFC_CANNOT_REC;
-
-    Iec10x->_ctrl.up._func = IEC101_CTRL_SEND_USR_DATA_ACK;
-
-    Iec10x->_addr = Iec10x_Sta_Addr;
-    /*asdu*/
-    asdu->_type           = IEC10X_C_CS_NA_1;
-    asdu->_num._sq        = 0;
-    asdu->_num._num       = asdu_num;
-    asdu->_reason._pn     = 0;
-    asdu->_reason._test   = 0;
-    asdu->_reason._reason = IEC10X_COT_ACTCON;
-    asdu->_addr           = Iec10x_Sta_Addr;
-    /*info*/
-    info->_addr = IEC10X_INFO_ADDR_NONE;
-
-    /*clock value*/
-    ptr = info->_element;
-    // time;
-    IEC10X->GetTime(time);
-    ptr += sizeof(CP56Time2a_T);
-
-    /*len*/
-    len          = ptr + 2 - Iec101_Sendbuf;
-    Iec10x->_len = Iec10x->_len_cfm = len - 4 - 2; /*-start-len-len-start   -cs-end*/
-
-    /*end*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += Iec101_Sendbuf[i];
-    }
-    Iec101_Sendbuf[len - 2] = cs_temp;
-    Iec101_Sendbuf[len - 1] = IEC101_VARIABLE_END;
-
-    // DumpHEX(Iec101_Sendbuf,len);
-    /* enqueue to the transmisson queue */
-    IEC10X_Enqueue(Iec101_Sendbuf, len, IEC10X_PRIO_CLOCK, NULL, NULL);
-
-    return RET_SUCESS;
-}
-IEC10X_ASDU_CALL_Qoi(iec_8u qoi)
-{
-
-    switch (qoi)
-    {
-    case IEC10X_CALL_QOI_TOTAL:
-        LOG("-%s- call cmd active \n", __FUNCTION__);
-        IEC101_BuildSignal(IEC10X_COT_INTROGEN, IEC10X_PRIO_CALLALL);
-        IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_CALL_SIG_TOTAL;
-        break;
-    case IEC10X_CALL_QOI_GROUP1:
-        LOG("-%s- call cmd call group1 \n", __FUNCTION__);
-        IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_GROUP;
-        IEC101_BuildSignal(IEC10X_COT_INTRO1, IEC10X_PRIO_CALLGROUP);
-        break;
-    case IEC10X_CALL_QOI_GROUP2:
-        LOG("-%s- call cmd call group2 \n", __FUNCTION__);
-        IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_GROUP;
-        IEC101_BuildSignal(IEC10X_COT_INTRO2, IEC10X_PRIO_CALLGROUP);
-        break;
-    case IEC10X_CALL_QOI_GROUP9:
-        LOG("-%s- call cmd call group9 \n", __FUNCTION__);
-        IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_GROUP;
-        IEC101_BuildDetect(IEC10X_COT_INTRO9, IEC10X_M_ME_NA_1, IEC10X_PRIO_CALLGROUP);
-        break;
-    case IEC10X_CALL_QOI_GROUP10:
-        LOG("-%s- call cmd call group10 \n", __FUNCTION__);
-        IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_GROUP;
-        IEC101_BuildDetect(IEC10X_COT_INTRO10, IEC10X_M_ME_NA_1, IEC10X_PRIO_CALLGROUP);
-        break;
-    default:
-        LOG("-%s- call cmd active error(%d) \n", __FUNCTION__, qoi);
-        break;
-    }
-}
-
-iec_8u IEC10X_ASDU_Call(PIEC10X_ASDU_T Iec10x_Asdu)
-{
-
-    PASDU_INFO_T asdu_info = (PASDU_INFO_T)(Iec10x_Asdu->_info);
-    iec_8u       qoi       = asdu_info->_element[0];
-    iec_8u       Prio      = 0;
-
-    if (asdu_info->_addr != 0)
-    {
-        LOG("-%s- call cmd active error addr(%x) \n", __FUNCTION__, asdu_info->_addr);
-        return RET_ERROR;
-    }
-
-    switch (Iec10x_Asdu->_reason._reason)
-    {
-
-    case IEC10X_ASDU_REASON_ACT:
-        switch (qoi)
-        {
-        case IEC10X_CALL_QOI_TOTAL:
-            Prio                      = IEC10X_PRIO_CALLALL;
-            IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_CALL_ACT_RET;
-            IEC10X_Call_AllQoi        = qoi;
-            break;
-        case IEC10X_CALL_QOI_GROUP1:
-        case IEC10X_CALL_QOI_GROUP2:
-        case IEC10X_CALL_QOI_GROUP9:
-        case IEC10X_CALL_QOI_GROUP10:
-            Prio                    = IEC10X_PRIO_CALLGROUP;
-            IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_ACT_RET;
-            IEC10X_Call_GroupQoi    = qoi;
-            break;
-        default:
-            LOG("-%s- call cmd error qoi(%d) \n", __FUNCTION__, qoi);
-            return RET_ERROR;
-        }
-        IEC10X_ResConfirm(Prio);
-        IEC101_BuildActConfirm(qoi, Prio);
-        break;
-
-    default:
-        LOG("-%s- call cmd error reason(%d) \n", __FUNCTION__, Iec10x_Asdu->_reason._reason);
-        break;
-    }
-    return RET_SUCESS;
-}
-
-iec_8u IEC10X_ASDU_Delay(PIEC10X_ASDU_T Iec10x_Asdu)
-{
-
-    PASDU_INFO_T asdu_info = (PASDU_INFO_T)(Iec10x_Asdu->_info);
-
-    if (asdu_info->_addr != 0)
-    {
-        LOG("-%s- delay cmd error addr(%d) \n", __FUNCTION__, asdu_info->_addr);
-        return RET_ERROR;
-    }
-
-    switch (Iec10x_Asdu->_reason._reason)
-    {
-
-    case IEC10X_COT_ACT:
-        IEC10X_Cp16time2a = *(iec_16u *)(asdu_info->_element);
-        LOG("-%s- delay cmd (0x%x%x)(%d)ms \n", __FUNCTION__, asdu_info->_element[0], asdu_info->_element[1], IEC10X_Cp16time2a);
-        IEC101_STATE_FLAG_DELAY = IEC101_FLAG_DELAY_ACT;
-        IEC10X_ResConfirm(IEC10X_PRIO_DELAY);
-        IEC101_BuildDelayAct(IEC10X_Cp16time2a);
-        break;
-    case IEC10X_COT_SPONT:
-        IEC10X_Cp16time2a_V = *(iec_16u *)(asdu_info->_element);
-        LOG("-%s- delay cmd delay value(%d)ms \n", __FUNCTION__, IEC10X_Cp16time2a_V);
-        IEC10X_ResConfirm(IEC10X_PRIO_DELAY);
-        break;
-    default:
-        LOG("-%s- delay cmd error reason(%d) \n", __FUNCTION__, Iec10x_Asdu->_reason._reason);
-        break;
-    }
-    return RET_SUCESS;
-}
-
-iec_8u IEC10X_ASDU_CLOCK(PIEC10X_ASDU_T Iec10x_Asdu)
-{
-
-    PASDU_INFO_T  asdu_info = (PASDU_INFO_T)(Iec10x_Asdu->_info);
-    PCP56Time2a_T time      = (PCP56Time2a_T)(asdu_info->_element);
-
-    memcpy(&IEC10X_Cp56time2a, asdu_info->_element, sizeof(CP56Time2a_T));
-
-    if (asdu_info->_addr != 0)
-    {
-        LOG("-%s- Clock cmd error addr(%d) \n", __FUNCTION__, asdu_info->_addr);
-        return RET_ERROR;
-    }
-
-    switch (Iec10x_Asdu->_reason._reason)
-    {
-
-    case IEC10X_COT_ACT:
-        LOG("-%s- Clock cmd (20%d-%d-%d %d %d:%d:%d) delay(%d) \n", __FUNCTION__, IEC10X_Cp56time2a._year._year, IEC10X_Cp56time2a._month._month, IEC10X_Cp56time2a._day._dayofmonth,
-            IEC10X_Cp56time2a._day._dayofweek, IEC10X_Cp56time2a._hour._hours, IEC10X_Cp56time2a._min._minutes, IEC10X_Cp56time2a._milliseconds, IEC10X_Cp16time2a_V);
-        IEC10X_Cp56time2a._milliseconds += IEC10X_Cp16time2a_V;
-        /*get time*/
-        /*...*/
-        IEC10X->SetTime(&IEC10X_Cp56time2a);
-        IEC101_STATE_FLAG_DELAY = IEC101_FLAG_CLOCK_SYS;
-        IEC10X_ResConfirm(IEC10X_PRIO_CLOCK);
-        IEC101_BuildClockAct();
-        break;
-    case IEC10X_COT_SPONT:
-        LOG("-%s- Clock cmd spont \n", __FUNCTION__);
-        break;
-    default:
-        LOG("-%s- Clock cmd error reason(%d) \n", __FUNCTION__, Iec10x_Asdu->_reason._reason);
-        break;
-    }
-    return RET_SUCESS;
-}
-
-iec_8u Iec10x_Deal_10(iec_8u *buf, iec_16u len)
-{
-
-    iec_8u       cfun, sta, i;
-    iec_8u       cs_temp   = 0;
-    PIEC101_10_T Iec10x_10 = NULL;
-
-    Iec10x_10 = (PIEC101_10_T)buf;
-    /* check check_sum*/
-    for (i = 1; i < len - 2; i++)
-    {
-        cs_temp += buf[i];
-    }
-    if (Iec10x_10->_cs != cs_temp)
-    {
-        LOG("-%s-,check sum error(%x) \n", __FUNCTION__, cs_temp);
-        return RET_ERROR;
-    }
-    /* check end of the frame*/
-    if (Iec10x_10->_end != 0x16)
-    {
-        LOG("-%s-,iec10x_10 end error(%d) \n", __FUNCTION__, Iec10x_10->_end);
-        return RET_ERROR;
-    }
-    /*deal the function code*/
-    cfun = Iec10x_10->_ctrl.down._func;
-    sta  = Iec10x_10->_ctrl.down._prm;
-    // IEC10X->GetLinkAddr();
-#ifdef IEC10XLOCK
-    if (IEC10X->LOCK != NULL)
-        IEC10X->LOCK();
-#endif
-    if (sta == IEC101_CTRL_PRM_MASTER)
-    {
-        switch (cfun)
-        {
-
-        case IEC101_CTRL_RESET_LINK:
-            LOG("++++Reset link... \n");
-            IEC101_STATE_FLAG_INIT = IEC101_FLAG_RESET_LINK;
-            break;
-        case IEC101_CTRL_PULSE:
-            LOG("++++PULSE... \n");
-            IEC101_STATE_FLAG_PULSE = IEC101_FLAG_PULSE;
-            IEC10X_ResConfirm(IEC10X_PRIO_PULSE);
-            break;
-        case IEC101_CTRL_SEND_DATA:
-            LOG("++++Send data... \n");
-            break;
-        case IEC101_CTRL_REQ_LINK_STATUS:
-            LOG("++++Request link status... \n");
-            IEC101_STATE_FLAG_INIT = IEC101_FLAG_INIT_LINK;
-            // Iec10x_Sta_Addr = IEC10X->GetLinkAddr();
-
-            // Iec10x_Sta_Addr = 0x138a;
-            // IEC10X_RetStatusOk(Iec10x_Sta_Addr);
-            break;
-        default:
-            LOG("++++error DOWN function code (%d)... \n", cfun);
-            break;
-        }
-    }
-    else if (sta == IEC101_CTRL_PRM_SLAVE)
-    {
-
-        switch (cfun)
-        {
-        case IEC101_CTRL_RES_LINK_STATUS:
-            LOG("++++Respon link status... \n");
-            LOG("IEC101_FLAG_RESET_REMOTE_LINK \n");
-            IEC10X_ResetLink();
-            IEC101_STATE_FLAG_INIT = IEC101_FLAG_RESET_REMOTE_LINK;
-            break;
-        case IEC101_CTRL_RES_CONFIRM:
-            LOG("++++Respon confirm... \n");
-            Iec101_Respon_Confirm = 1;
-            break;
-        default:
-            LOG("++++error UP function code (%d)... \n", cfun);
-            break;
-        }
-    }
-#ifdef IEC10XLOCK
-    if (IEC10X->UNLOCK != NULL)
-        IEC10X->UNLOCK();
-#endif
-    return RET_SUCESS;
-}
-
-iec_8u Iec10x_Deal_68(iec_8u *buf, iec_16u len)
-{
-
-    iec_8u         cfun, sta, i;
-    iec_8u         cs_temp     = 0;
-    PIEC101_68_T   Iec10x_68   = NULL;
-    PIEC10X_ASDU_T Iec10x_Asdu = NULL;
-
-    Iec10x_68   = (PIEC101_68_T)buf;
-    Iec10x_Asdu = (PIEC10X_ASDU_T)Iec10x_68->_asdu;
-
-    /* check check_sum*/
-    for (i = 4; i < len - 2; i++)
-    {
-        cs_temp += buf[i];
-    }
-    if (buf[len - 2] != cs_temp)
-    {
-        LOG("-%s-,iec10x_68 check sum error (%d)(%d) \n", __FUNCTION__, buf[len - 2], cs_temp);
-        return RET_ERROR;
-    }
-    /* check end of the frame*/
-    if (buf[len - 1] != IEC101_VARIABLE_END)
-    {
-        LOG("-%s-,iec10x_68 end error(%d) \n", __FUNCTION__, buf[len - 1]);
-        return RET_ERROR;
-    }
-    /* check len of the receive frame */
-    if (Iec10x_68->_len + 6 != len)
-    {
-        LOG("-%s-,iec10x_68 rec len error(%d)(%d) \n", __FUNCTION__, Iec10x_68->_len, len);
-        return RET_ERROR;
-    }
-    /* check len of the frame */
-    if (Iec10x_68->_len != Iec10x_68->_len_cfm)
-    {
-        LOG("-%s-,iec10x_68 len error(%d)(%d) \n", __FUNCTION__, Iec10x_68->_len, Iec10x_68->_len_cfm);
-        return RET_ERROR;
-    }
-    /*deal the function code*/
-    cfun = Iec10x_68->_ctrl.down._func;
-    sta  = Iec10x_68->_ctrl.down._prm;
-#ifdef IEC10XLOCK
-    if (IEC10X->LOCK != NULL)
-        IEC10X->LOCK();
-#endif
-    switch (cfun)
-    {
-    case IEC101_CTRL_SEND_USR_DATA_ACK:
-        Iec101_Respon_Confirm = 0;
-        LOG("++++Send user data need ack... \n");
-        switch (Iec10x_Asdu->_type)
-        {
-        case IEC10X_C_IC_NA_1:
-            LOG("++++asdu type call cmd... \n");
-            IEC10X_ASDU_Call(Iec10x_Asdu);
-            break;
-        case IEC10X_C_CD_NA_1:
-            LOG("++++asdu type delay active... \n");
-            IEC10X_ASDU_Delay(Iec10x_Asdu);
-            break;
-        case IEC10X_C_CS_NA_1:
-            LOG("++++asdu type clock active... \n");
-            IEC10X_ASDU_CLOCK(Iec10x_Asdu);
-            break;
-        default:
-            break;
-        }
-        break;
-    default:
-        LOG("++++error function code (%d)... \n", cfun);
-        break;
-    }
-#ifdef IEC10XLOCK
-    if (IEC10X->UNLOCK != NULL)
-        IEC10X->UNLOCK();
-#endif
-    return RET_SUCESS;
-}
-
-void Iex101_main(iec_8u *buf, iec_16u len)
-{
-
-    iec_8u *BufTemp = NULL;
-    iec_16s LenRemain, LenTmp;
-
-    if (buf == NULL)
-    {
-        LOG("-%s-,buffer (null)", __FUNCTION__);
-        return;
-    }
-    if (len <= 0 || len > IEC101_MAX_BUF_LEN)
-    {
-        LOG("-%s-,buffer len error(%d) \n", __FUNCTION__, len);
-        return;
-    }
-
-    BufTemp   = buf;
-    LenRemain = len;
-    while (BufTemp < buf + len)
-    {
-
-        if (BufTemp[0] == IEC101_STABLE_BEGING)
-        {
-            LenTmp           = 6;
-            IEC101_Pulse_Cnt = 0;
-            if (LenRemain < 6)
-            {
-                LOG("_%s_,len error(%d) \n", __FUNCTION__, len);
-                return;
-            }
-            Iec10x_Deal_10(BufTemp, LenTmp);
-        }
-        else if (BufTemp[0] == IEC101_VARIABLE_BEGING)
-        {
-            LenTmp           = BufTemp[1] + 6;
-            IEC101_Pulse_Cnt = 0;
-            if (BufTemp[1] != BufTemp[2])
-            {
-                LOG("_%s_,len error(%d)(%d) \n", __FUNCTION__, BufTemp[1], BufTemp[2]);
-                return;
-            }
-            Iec10x_Deal_68(BufTemp, LenTmp);
-        }
-        else
-        {
-            LOG("-%s-,head type error(%d) \n", __FUNCTION__, BufTemp[0]);
-            return;
-        }
-        BufTemp += LenTmp;
-        LenRemain -= LenTmp;
-    }
-    return;
-}
-
-iec_8u Iec101_StateMachine(void)
-{
-
-    /*Init link*/
-
-    switch (IEC101_STATE_FLAG_INIT)
-    {
-
-    case IEC101_FLAG_LINK_CLOSED:
-        break;
-    case IEC101_FLAG_INIT_LINK:
-        LOG("IEC101_FLAG_INIT_LINK \n");
-        Iec101_Respon_Confirm = 0;
-        Iec10x_Sta_Addr       = IEC10X->GetLinkAddr();
-        IEC10X_RetStatusOk(Iec10x_Sta_Addr);
-        IEC101_STATE_FLAG_INIT = IEC101_FLAG_LINK_IDLE;
-        break;
-    case IEC101_FLAG_RESET_LINK:
-        LOG("IEC101_FLAG_RESET_LINK \n");
-        IEC10X_ClearQ();
-        IEC10X_ResConfirm(IEC10X_PRIO_INITLINK);
-
-        IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_LINK_CLOSED;
-        IEC101_STATE_FLAG_GROUP   = IEC101_FLAG_LINK_CLOSED;
-        IEC101_STATE_FLAG_DELAY   = IEC101_FLAG_LINK_CLOSED;
-        IEC101_STATE_FLAG_PULSE   = IEC101_FLAG_LINK_CLOSED;
-
-        IEC101_STATE_FLAG_INIT = IEC101_FLAG_REQ_LINK;
-        break;
-    case IEC101_FLAG_REQ_LINK:
-        LOG("IEC101_FLAG_REQ_LINK \n");
-        IEC10X_ReqLinkStatus();
-        IEC101_STATE_FLAG_INIT = IEC101_FLAG_LINK_IDLE;
-        break;
-    case IEC101_FLAG_RESET_REMOTE_LINK:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm  = 0;
-            IEC101_STATE_FLAG_INIT = IEC101_FLAG_INIT_FIN;
-            LOG("IEC101_FLAG_INIT_FIN! \n");
-            IEC101_BuildFinInit();
-        }
-        break;
-    case IEC101_FLAG_INIT_FIN:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm  = 0;
-            IEC101_STATE_FLAG_INIT = IEC101_FLAG_CONNECT_OK;
-        }
-        break;
-    case IEC101_FLAG_CONNECT_OK:
-    case IEC101_FLAG_LINK_IDLE:
-    default:
-        break;
-    }
-
-    /*total call*/
-    switch (IEC101_STATE_FLAG_CALLALL)
-    {
-    case IEC101_FLAG_CALL_ACT:
-        break;
-    case IEC101_FLAG_CALL_ACT_RET:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm = 0;
-            IEC10X_ASDU_CALL_Qoi(IEC10X_Call_AllQoi);
-        }
-        break;
-    case IEC101_FLAG_CALL_SIG_TOTAL:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm     = 0;
-            IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_CALL_DET_TOTAL;
-            IEC101_BuildDetect(IEC10X_COT_INTROGEN, IEC10X_M_ME_NA_1, IEC10X_PRIO_CALLALL);
-        }
-        break;
-    case IEC101_FLAG_CALL_DET_TOTAL:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm = 0;
-            IEC101_BuildActFinish(IEC10X_Call_AllQoi, IEC10X_PRIO_CALLALL);
-            IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_CALL_ACT_FIN;
-        }
-        break;
-    case IEC101_FLAG_CALL_ACT_FIN:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm     = 0;
-            IEC101_STATE_FLAG_CALLALL = IEC101_FLAG_LINK_IDLE;
-        }
-        break;
-    case IEC101_FLAG_LINK_IDLE:
-    default:
-        break;
-    }
-
-    /*group call*/
-    switch (IEC101_STATE_FLAG_GROUP)
-    {
-    case IEC101_FLAG_CALL_ACT:
-        break;
-    case IEC101_FLAG_CALL_ACT_RET:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm = 0;
-            IEC10X_ASDU_CALL_Qoi(IEC10X_Call_GroupQoi);
-        }
-        break;
-    case IEC101_FLAG_CALL_GROUP:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm   = 0;
-            IEC101_STATE_FLAG_GROUP = IEC101_FLAG_CALL_ACT_FIN;
-            IEC101_BuildActFinish(IEC10X_Call_GroupQoi, IEC10X_PRIO_CALLGROUP);
-        }
-        break;
-    case IEC101_FLAG_CALL_ACT_FIN:
-        if (Iec101_Respon_Confirm)
-        {
-            Iec101_Respon_Confirm   = 0;
-            IEC101_STATE_FLAG_GROUP = IEC101_FLAG_LINK_IDLE;
-        }
-        break;
-    case IEC101_FLAG_LINK_IDLE:
-    default:
-        break;
-    }
-
-    /*delay and clock*/
-    switch (IEC101_STATE_FLAG_DELAY)
-    {
-
-    case IEC101_FLAG_DELAY_ACT:
-        break;
-    case IEC101_FLAG_CLOCK_SYS:
-        IEC101_STATE_FLAG_DELAY = IEC101_FLAG_LINK_IDLE;
-        break;
-    case IEC101_FLAG_LINK_IDLE:
-    default:
-        break;
-    }
-
-    /*pulse*/
-    switch (IEC101_STATE_FLAG_PULSE)
-    {
-    case IEC101_FLAG_PULSE:
-        break;
-    case IEC101_FLAG_LINK_IDLE:
-        break;
-    default:
-        break;
-    }
-    return RET_SUCESS;
-}
-
-#endif

+ 0 - 199
User/app/iec104/iec101.h

@@ -1,199 +0,0 @@
-/*******************************************************************
-Copyright (C):
-File name    :    Iec101.h
-DESCRIPTION  :
-AUTHOR       :
-Version      :    1.0
-Date         :    2014/07/23
-Others       :
-History      :
-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-1) Date: 2014/07/23         Author: ChenDajie
-   content:
-
-*******************************************************************/
-
-#ifndef _IEC101_H
-#define _IEC101_H
-
-#include "iec10x.h"
-#include "iec10x_conf.h"
-#include "iec10x_prio_queue.h"
-#include "iec10x_type.h"
-#include <stdio.h>
-#include <string.h>
-
-#ifdef IEC101_SET
-#define ARM_PACK __packed
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-    /*
-    *********************************************************************************************************
-    *                           FUNCTION CODE
-    *********************************************************************************************************
-    */
-    /*
-     * down
-     * */
-#define IEC101_CTRL_RESET_LINK        0
-#define IEC101_CTRL_PULSE             2
-#define IEC101_CTRL_SEND_USR_DATA_ACK 3
-#define IEC101_CTRL_SEND_DATA         4
-#define IEC101_CTRL_REQ_LINK_STATUS   9
-
-/*
- * up
- * */
-#define IEC101_CTRL_RES_CONFIRM     0x00
-#define IEC101_CTRL_RES_LINK_STATUS 0x0B
-/*
- * DIR, PRM, FCB, FCV, ACD, DFC
- * */
-#define IEC101_CTRL_DIR_DOWN       0x01
-#define IEC101_CTRL_DIR_UP         0x00
-#define IEC101_CTRL_FCB_OPPO_BIT   0x01
-#define IEC101_CTRL_FCB_OPPO_NONE  0x00
-#define IEC101_CTRL_PRM_MASTER     0x01
-#define IEC101_CTRL_PRM_SLAVE      0x00
-#define IEC101_CTRL_FCV_ENABLE     0x01
-#define IEC101_CTRL_FCV_DISABLE    0x00
-#define IEC101_CTRL_ACD_WITH_DATA  0x01
-#define IEC101_CTRL_ACD_NONE_DATA  0x00
-#define IEC101_CTRL_DFC_CAN_REC    0x00
-#define IEC101_CTRL_DFC_CANNOT_REC 0x01
-
-    /*
-    *********************************************************************************************************
-    *                           FRAME  VALUE
-    *********************************************************************************************************
-    */
-#define IEC101_STABLE_BEGING 0X10
-#define IEC101_STABLE_END    0X16
-#define IEC101_STABLE_LEN    0X06
-/*
- * variable
- * */
-#define IEC101_VARIABLE_BEGING 0X68
-#define IEC101_VARIABLE_END    0X16
-    /*
-     * length of variable
-     * */
-#define IEC101_VARIABLE_HEAD_LEN (sizeof(IEC101_68_T) - 1)
-#define IEC101_VARIABLE_ASDU_LEN (sizeof(IEC10X_ASDU_T) - 1)
-#define IEC101_VARIABLE_INFO_LEN (sizeof(ASDU_INFO_T) - 1)
-#define IEC101_VARIABLE_LEN      (IEC101_VARIABLE_HEAD_LEN + IEC101_VARIABLE_ASDU_LEN + IEC101_VARIABLE_INFO_LEN + 2) /*add cs+end*/
-
-#pragma pack(1)
-
-#define IEC101_MAX_BUF_LEN 256
-
-    /*
-     * Control Code
-     * */
-    typedef __packed struct
-    {
-
-        iec_8u _func : 4; /* function */
-        iec_8u _fcv  : 1;
-        iec_8u _fcb  : 1; /* Frame calculate bit */
-        iec_8u _prm  : 1; /* 1:from start station, 0:from end station */
-        iec_8u _dir  : 1;
-
-    } CTRL_DOWN_T;
-
-    typedef __packed struct
-    {
-
-        iec_8u _func : 4; /*function*/
-        iec_8u _dfc  : 1;
-        iec_8u _acd  : 1;
-        iec_8u _prm  : 1;
-        iec_8u _dir  : 1;
-
-    } CTRL_UP_T;
-
-    typedef __packed union
-    {
-        CTRL_UP_T   up;
-        CTRL_DOWN_T down;
-        iec_8u      val;
-    } CTRL_T, *PCTRL_T;
-
-    /*
-     *  regular frame   head:10
-     * */
-    typedef __packed struct
-    {
-        iec_8u  _begin;
-        CTRL_T  _ctrl;
-        iec_16u _addr;
-        iec_8u  _cs;
-        iec_8u  _end;
-    } IEC101_10_T, *PIEC101_10_T;
-
-    /*
-     *  variable fram   head:68
-     * */
-    typedef __packed struct
-    {
-        iec_8u  _begin;
-        iec_8u  _len;
-        iec_8u  _len_cfm;
-        iec_8u  _begin_cfm;
-        CTRL_T  _ctrl;
-        iec_16u _addr;
-        iec_8u  _asdu[1];
-    } IEC101_68_T, *PIEC101_68_T;
-
-#pragma pack()
-
-    /* IEC101 STATE-MACHINE */
-    enum
-    {
-        IEC101_FLAG_LINK_CLOSED,
-        IEC101_FLAG_LINK_IDLE,
-        IEC101_FLAG_INIT_LINK,
-        IEC101_FLAG_RESET_LINK,
-        IEC101_FLAG_REQ_LINK,
-        IEC101_FLAG_RESET_REMOTE_LINK,
-        IEC101_FLAG_INIT_FIN,
-        IEC101_FLAG_CALL_ACT,
-        IEC101_FLAG_CALL_ACT_FIN,
-        IEC101_FLAG_CALL_ACT_RET,
-        IEC101_FLAG_CALL_SIG_TOTAL,
-        IEC101_FLAG_CALL_DET_TOTAL,
-        IEC101_FLAG_DELAY_ACT,
-        IEC101_FLAG_CLOCK_SYS,
-        IEC101_FLAG_PULSE,
-        IEC101_FLAG_CALL_GROUP,
-        IEC101_FLAG_CONNECT_OK,
-    };
-
-    /*
-    *********************************************************************************************************
-    *                                           GLOABLE VARIABLE
-    *********************************************************************************************************
-    */
-    extern iec_16u IEC101_Pulse_Cnt;
-    extern iec_8u  IEC101_STATE_FLAG_INIT;
-    /*
-    *********************************************************************************************************
-    *                                          FUNCTION PROTOTYPES
-    *********************************************************************************************************
-    */
-
-    void   Iex101_main(iec_8u *buf, iec_16u len);
-    iec_8u Iec101_StateMachine(void);
-
-    iec_8u IEC101_BuildSignal_Spont(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
-    iec_8u IEC101_BuildDetect_Spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
-    iec_8u IEC101_BuildDetectF_Spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
-
-#ifdef __cplusplus
-}
-#endif /*IEC101_STM32*/
-#endif
-#endif /*_IEC101_H*/

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 231 - 242
User/app/iec104/iec104.c


+ 52 - 52
User/app/iec104/iec104.h

@@ -3,9 +3,9 @@
 #ifndef _IEC104_H
 #define _IEC104_H
 
-#include "iec10x.h"
-#include "iec10x_conf.h"
-#include "iec10x_type.h"
+#include "iec104_conf.h"
+#include "iec104_queue.h"
+#include "iec104_types.h"
 
 #define IEC104_MAX_BUF_LEN 256
 
@@ -57,8 +57,8 @@
 /*
  * device type
  */
-//#define       ENDDEVICE_TYPE_ERR                  0
-//#define       ENDDEVICE_TYPE_HXPF                 2
+// #define       ENDDEVICE_TYPE_ERR                  0
+// #define       ENDDEVICE_TYPE_HXPF                 2
 #define ENDDEVICE_TYPE_HXTM 1
 #define ENDDEVICE_TYPE_HXGF 3
 
@@ -76,90 +76,90 @@
 typedef struct
 {
 
-    iec_32u Type    : 1;
-    iec_32u SendSn  : 15;
-    iec_32u Reserve : 1;
-    iec_32u RecvSn  : 15;
-} IEC104_CTRL_I_T, *PIEC104_CTRL_I_T;
+    iec_32u type    : 1;
+    iec_32u send_sn : 15;
+    iec_32u reserve : 1;
+    iec_32u recv_sn : 15;
+} iec104_ctrl_i_t, *p_iec104_ctrl_i_t;
 
 /* Control filed S type */
 typedef struct
 {
 
-    iec_32u Type1   : 1;
-    iec_32u Type2   : 1;
-    iec_32u Reserve : 15;
-    iec_32u RecvSn  : 15;
-} IEC104_CTRL_S_T, *PEC104_CTRL_S_TP;
+    iec_32u type_1  : 1;
+    iec_32u type_2  : 1;
+    iec_32u reserve : 15;
+    iec_32u recv_sn : 15;
+} iec104_ctrl_s_t, *p_iec104_ctrl_s_t;
 
 /* Control filed U type */
 typedef struct
 {
 
-    iec_32u Type1      : 1;
-    iec_32u Type2      : 1;
-    iec_32u Startdt    : 1;
-    iec_32u StartdtAck : 1;
-    iec_32u Stopdt     : 1;
-    iec_32u StopdtAck  : 1;
-    iec_32u Tester     : 1;
-    iec_32u TesterAck  : 1;
-    iec_32u Reserve    : 24;
-} IEC104_CTRL_U_T, *PIEC104_CTRL_U_T;
+    iec_32u type_1      : 1;
+    iec_32u type_2      : 1;
+    iec_32u startdt     : 1;
+    iec_32u startdt_ack : 1;
+    iec_32u stopdt      : 1;
+    iec_32u stopdt_ack  : 1;
+    iec_32u tester      : 1;
+    iec_32u tester_ack  : 1;
+    iec_32u reserve     : 24;
+} iec104_ctrl_u_t, *p_iec104_ctrl_u_t;
 
 /* Control filed type */
 typedef struct
 {
 
-    iec_32u Type1   : 1;
-    iec_32u Type2   : 1;
-    iec_32u Reserve : 30;
+    iec_32u type_1  : 1;
+    iec_32u type_2  : 1;
+    iec_32u reserve : 30;
 
-} IEC104_CTRLType_T, *PIEC104_CTRLType_T;
+} iec104_ctrl_type_t, *p_iec104_ctrl_type_t;
 
 /* Control filed type */
 typedef struct
 {
 
-    iec_32u Func    : 8;
-    iec_32u Reserve : 24;
+    iec_32u func    : 8;
+    iec_32u reserve : 24;
 
-} IEC104_CTRLFunc_T, *PIEC104_CTRLFunc_T;
+} iec104_ctrl_func_t, *p_iec104_ctrl_func_t;
 
 typedef union
 {
 
-    IEC104_CTRL_I_T   I;
-    IEC104_CTRL_S_T   S;
-    IEC104_CTRL_U_T   U;
-    IEC104_CTRLType_T Type;
-    IEC104_CTRLFunc_T Func;
-} IEC104_CTRL_T, *PIEC104_CTRL_T;
+    iec104_ctrl_i_t    i;
+    iec104_ctrl_s_t    s;
+    iec104_ctrl_u_t    u;
+    iec104_ctrl_type_t type;
+    iec104_ctrl_func_t func;
+} iec104_ctrl_t, *p_iec104_ctrl_t;
 
 typedef struct
 {
 
-    iec_8u        Head;
-    iec_8u        Len;
-    IEC104_CTRL_T Ctrl;
-    iec_8u        Asdu[1];
-} IEC104_DATA_T, *PIEC104_DATA_T;
+    iec_8u        head;
+    iec_8u        len;
+    iec104_ctrl_t ctrl;
+    iec_8u        asdu[1];
+} iec104_data_t, *p_iec104_data_t;
 
 typedef struct
 {
 
     float Current;
     float Temperature;
-} Iec10x_DevA_Info_T, *PIec10x_DevA_Info_T;
+} iec10x_dev_a_info_t, *p_iec10x_dev_a_info_t;
 
 #pragma pack()
 
 /*
  * length
  * */
-#define IEC104_HEAD_LEN (sizeof(IEC104_DATA_T) - 1)
-#define IEC104_ASDU_LEN (sizeof(IEC10X_ASDU_T) - 1)
-#define IEC104_INFO_LEN (sizeof(ASDU_INFO_T) - 1)
+#define IEC104_HEAD_LEN (sizeof(iec104_data_t) - 1)
+#define IEC104_ASDU_LEN (sizeof(iec10x_asdu_t) - 1)
+#define IEC104_INFO_LEN (sizeof(asdu_info_t) - 1)
 #define IEC104_DATA_LEN (IEC104_HEAD_LEN + IEC104_ASDU_LEN + IEC104_INFO_LEN)
 
 enum
@@ -203,10 +203,10 @@ extern iec_8u IEC104_STATE_FLAG_PULSE;
 *                          FUNCTION
 *********************************************************************************************************
 */
-iec_8u Iec104_StateMachine(void);
-iec_8u IEC104_BuildSignal_Spon(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
-iec_8u IEC104_BuildDetectF_Spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
-void   Iex104_Receive(iec_8u *buf, iec_16u len);
-iec_8u IEC104_BuildDetect_Spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
+iec_8u iec104_state_machine(void);
+iec_8u iec104_build_signal_spon(iec_8u TimeFlag, iec_8u signalV, iec_16u addrV);
+iec_8u iec104_build_detect_f_spont(iec_8u TimeFlag, float detectV, iec_16u addrV);
+void   iec104_receive(iec_8u *buf, iec_16u len);
+iec_8u iec104_build_detect_spont(iec_8u TimeFlag, PIEC10X_DETECT_T detectV, iec_16u addrV);
 
 #endif

+ 9 - 11
User/app/iec104/iec10x_conf.h → User/app/iec104/iec104_conf.h

@@ -2,20 +2,17 @@
 #ifndef __IEC10x_CONF_H
 #define __IEC10x_CONF_H
 
-#include "iec10x_type.h"
+#include "iec104_types.h"
+#include "project_var.h"
 
 #define WTP_SUPPORT_END_NUMBER 9
 
 #define RET_SUCESS 0
 #define RET_ERROR  1
 
-#define IEC104_SET
+// #define IEC104_DEBUG
 
-#define SIM900_MODE_CLIENT
-
-// #define SERIAL_DEBUG
-
-#ifdef SERIAL_DEBUG
+#ifdef IEC104_DEBUG
 #define log(...) printf(__VA_ARGS__)
 #define LOG(...) printf(__VA_ARGS__)
 #define LogInit()
@@ -23,12 +20,13 @@
 #else
 #define log(...)
 #define LOG(...)
-#define DumpHEX(buffer, len)
+#define dump_hex(buffer, len)
 #define PRINT_FUNLINE
 #endif
 
-#ifdef SERIAL_DEBUG
-void DumpHEX(iec_8u *buffer, iec_32u len);
+#ifdef IEC104_DEBUG
+// #define dump_hex(buffer, len)
+void dump_hex(iec_8u *buffer, iec_32u len);
 #endif
 
-#endif
+#endif

+ 59 - 26
User/app/iec104/iec10x_init.c → User/app/iec104/iec104_init.c

@@ -1,10 +1,9 @@
 
 #include "dwt.h"
 #include "fly_param.h"
-#include "iec10x.h"
-#include "iec10x_conf.h"
-#include "iec10x_prio_queue.h"
-#include "iec10x_type.h"
+#include "iec104_conf.h"
+#include "iec104_queue.h"
+#include "iec104_types.h"
 #include "main.h"
 #include "nor_flash.h"
 #include <string.h>
@@ -13,7 +12,7 @@
 
 #define TEST_SECTOR_NO 127 /* 测试扇区号,值域【0,128】 */
 
-uint8_t g_TestBuf[TEST_BUF_SIZE]; /* 数据测试用缓冲区 */
+uint8_t g_test_buf[TEST_BUF_SIZE]; /* 数据测试用缓冲区 */
 
 /*******************************************************************************
  * Function Name  : fly_init
@@ -51,15 +50,15 @@ static iec_32u fly_get_time(PCP56Time2a_T time)
     return RET_SUCESS;
 }
 
-static iec_8s fly_get_station_info(iec_16u *Addr, iec_8u n, iec_8u *MaxNum)
+static iec_8s fly_get_station_info(iec_16u *addr, iec_8u n, iec_8u *MaxNum)
 {
 
     *MaxNum = WTP_SUPPORT_END_NUMBER;
-    *Addr   = n;
+    *addr   = n;
     return RET_SUCESS;
 }
 
-static float fly_get_station_temp(iec_16u Addr)
+static float fly_get_station_temp(iec_16u addr)
 {
 
     return 30;
@@ -74,7 +73,7 @@ static iec_16u fly_get_link_addr(void)
 static void fly_close_link(void)
 {
 
-    // GPRSFlag = SYSTEM_FLAG_GPRS_CLOSE;
+    // GPRSFlag               = SYSTEM_FLAG_GPRS_CLOSE;
     // IEC104_STATE_FLAG_INIT = IEC104_FLAG_CLOSED;
 }
 
@@ -96,54 +95,88 @@ iec_8u fly_send(int socketfd, char *buf, int len)
     // for (i = 0; i < len; i++)
     // {
     // NOR_WriteByte(TEST_SECTOR_NO * NOR_SECTOR_SIZE, buf[i]);
-    if (NOR_WriteBuffer(buf, TEST_SECTOR_NO * NOR_SECTOR_SIZE + 1, len) == NOR_SUCCESS)
-    {
-        printf("send sram buffer ok!\r\n");
-    }
+    // if (NOR_WriteBuffer(buf, TEST_SECTOR_NO * NOR_SECTOR_SIZE + 1, len) == NOR_SUCCESS)
+    // {
+    //     printf("send sram buffer ok!\r\n");
+    // }
     // }
-    printf("Send Ok!\r\n");
+    LOG("Send Ok!\r\n");
 
     return RET_SUCESS;
 }
+
+iec_8s fly_get_info_num(iec_8u *info_num, iec_8u dev_type)
+{
+    return 0;
+}
+iec_8s fly_set_onfig(long value, iec_32u addr)
+{
+    return 0;
+}
+iec_8s fly_save_firmware(iec_8u firm_len, iec_8u *buf, iec_32u firmware_type, iec_32u iec104_update_seek_addr)
+{
+    return 0;
+}
+iec_8s fly_check_firmware(iec_32u firmware_type, iec_32u total_len)
+{
+    return 0;
+}
+iec_8s fly_update_firmware(iec_32u firmware_type)
+{
+    return 0;
+}
+iec_8s fly_back_off_firmware(iec_32u firmware_type)
+{
+    return 0;
+}
+
 void fly_lock(void)
 {
     INT8U err;
     OSMutexPend(net_mutex, 0, &err);
     // pthread_mutex_lock(&mutex);
+    LOG("Net_mutex lock!\r\n");
 }
 void fly_unlock()
 {
     OSMutexPost(net_mutex);
     // pthread_mutex_unlock(&mutex);
+    LOG("Net_mutex unlock!\r\n");
 }
 
-static IEC10X_T fly = {
-    "Linux",
+static iec104_t fly = {
+    "fly_iec104",
     fly_init,
     delay_ms,
     fly_close_link,
     fly_malloc,
     fly_free,
-    IEC10X_PrioEnQueue,
-    IEC10X_PrioDeQueue,
-    IEC10X_PrioFindQueueHead,
-    IEC10X_HighestPrio, /* Get the highest Prio Queue*/
-    IEC10X_PrioInitQueue,
-    IEC10X_Prio_ClearQueue,
+    iec104_prio_enqueue,
+    iec104_prio_dequeue,
+    iec104_prio_queue_find_head,
+    iec10x_prio_highest, /* Get the highest Prio Queue*/
+    iec104_prio_queue_init,
+    iec104_prio_queue_clear,
     fly_send,
     fly_set_time,
     fly_get_time,
     fly_get_station_info,
     fly_get_station_temp,
     fly_get_link_addr,
-
-#ifdef IEC10XLOCK
+    fly_get_info_num,
+    fly_set_onfig,
+    fly_save_firmware,
+    fly_check_firmware,
+    fly_update_firmware,
+    fly_back_off_firmware,
+
+#ifdef IEC104LOCK
     fly_lock,
     fly_unlock
 #endif
 };
 
-iec_32u RegisterIec10x(void)
+iec_32u iec10x_regist(void)
 {
-    return RegisterIEC10XMoudle(&fly);
+    return iec104_module_register(&fly);
 }

+ 334 - 0
User/app/iec104/iec104_queue.c

@@ -0,0 +1,334 @@
+/**
+************************************************************************************************
+* @文件    : Iec10x.c
+* @作者    : 樊春春
+* @版本    : V1.0
+* @时间    : 2022/07/09 16:18:42
+* @邮箱    : [email protected]
+* @说明    :
+************************************************************************************************
+**/
+
+#include "iec104_queue.h"
+
+p_iec104_t          iec104            = NULL;
+iec_16u             iec104_state_addr = 0;
+iec104_prio_queue_t iec10x_prio_queue_array[IEC10X_PRIO_MAX];
+
+iec_16u      IEC10X_Cp16time2a   = 0;
+iec_16u      IEC10X_Cp16time2a_V = 0;
+CP56Time2a_T IEC10X_Cp56time2a;
+
+void iec104_lock(void)
+{
+
+#ifdef IEC104LOCK
+    if (iec104->lock != NULL)
+        iec104->lock();
+#endif
+}
+
+void iec104_unlock(void)
+{
+
+#ifdef IEC104LOCK
+    if (iec104->unlock != NULL)
+        iec104->unlock();
+#endif
+}
+
+void iec104_queue_init(void)
+{
+    iec_8u i;
+    for (i = 0; i < IEC10X_PRIO_MAX; i++)
+    {
+        iec104->queue_init(&iec10x_prio_queue_array[i]);
+    }
+}
+
+void iec104_queue_clear(void)
+{
+    iec_8u i;
+    for (i = 0; i < IEC10X_PRIO_MAX; i++)
+    {
+        iec104->queue_clear(&iec10x_prio_queue_array[i]);
+    }
+}
+
+iec_8u iec104_prio_get(iec_8u State)
+{
+
+    /*Prio from 0~7*/
+    iec_8u Prio = 0;
+
+    return Prio;
+}
+
+void iec104_enqueue(iec_8u *enq_buf, iec_16u Length, iec_8u Prio,
+                    void (*IEC10XCallBack)(iec104_callback_arg_t *Arg), iec104_callback_arg_t *CallbackArg)
+{
+
+    iec104_prio_node_t *new_p;
+
+    iec104_lock();
+    if (Length < IEC10X_HEADER_LENGTH)
+    {
+        LOG("IEC10X_Enqueue,buffer too short \r\n");
+        goto END;
+    }
+
+    new_p = (iec104_prio_node_t *)iec104->malloc(sizeof(iec104_prio_node_t) + Length - 1);
+    if (new_p == NULL)
+    {
+        LOG("IEC10X_Enqueue,malloc error \r\n");
+        goto END;
+    }
+
+    memcpy(new_p->value, enq_buf, Length);
+    new_p->Length = Length;
+
+    /* Prio from 1~8, Array from 0~7*/
+    if (Prio >= IEC10X_PRIO_MAX)
+    {
+        LOG("IEC104_Enqueue, error Prio(%d) \r\n", Prio);
+        goto END;
+    }
+
+    /* Set callback Argument */
+    new_p->CallBack = IEC10XCallBack;
+    if (CallbackArg != NULL)
+        new_p->CallBackArg = *CallbackArg;
+
+    new_p->CallBackArg.value = new_p->value;
+    LOG("IEC104_Enqueue,Prio(%d) elementNum(%d)len(%d)(%d) \r\n", Prio, iec10x_prio_queue_array[Prio].element_num, Length, new_p->Length);
+    // DumpHEX(new_p->value, new_p->Length);
+    iec104->enqueue(&iec10x_prio_queue_array[Prio], new_p);
+END:
+    iec104_unlock();
+    return;
+}
+
+iec104_prio_node_t *iec104_dequeue(void)
+{
+    iec_8u              Prio;
+    iec104_prio_node_t *ret;
+    Prio = iec104->get_prio();
+    if (Prio >= 8)
+    {
+        LOG("IEC104_Dequeue, Error Prio(%d) \r\n", Prio);
+        return 0;
+    }
+    ret = iec104->dequeue(&iec10x_prio_queue_array[Prio]);
+    if (ret)
+    {
+        iec10x_prio_queue_array[Prio].element_num--;
+    }
+    LOG("IEC104_Dequeue(%d) \r\n", ret->Length);
+    return ret;
+}
+iec104_prio_node_t *IEC104_FindQHead(void)
+{
+
+    iec_8u              Prio;
+    iec104_prio_node_t *ret;
+    Prio = iec104->get_prio();
+    if (Prio >= 8)
+    {
+        return 0;
+    }
+    ret = iec104->find_qhead(&iec10x_prio_queue_array[Prio]);
+    return ret;
+}
+
+void iec104_scheduled(int socketfd)
+{
+
+    iec104_prio_node_t *de_q_node;
+
+    de_q_node = iec104_dequeue();
+
+    if (de_q_node)
+    {
+
+        LOG("<<-------------------IEC10X (%d)-------------------->> \r\n", DeQNode->Length);
+
+        /* call back funtion */
+        if (de_q_node->CallBack)
+            de_q_node->CallBack(&(de_q_node->CallBackArg));
+
+        dump_hex(DeQNode->value, DeQNode->Length);
+        iec104->send(socketfd, (char *)(de_q_node->value), de_q_node->Length);
+
+        iec104_lock();
+        iec104->free(de_q_node);
+        iec104_unlock();
+    }
+}
+
+iec_32s iec104_module_register(void *p_iec10x)
+{
+
+    int ret;
+    if (NULL == p_iec10x)
+    {
+        return -1;
+    }
+    else
+    {
+        iec104 = (p_iec104_t)p_iec10x;
+        if (NULL == iec104->init)
+        {
+            return -1;
+        }
+        else
+        {
+            iec104_queue_init();
+            // IEC10X_InitInfo();
+            ret = iec104->init();
+            if (0 == ret)
+            {
+                LOG("\r\nRegister \"%s\" IEC104 Success, < HuiXing 2014-2015 > ...\r\n", iec10x->name);
+            }
+            return ret;
+        }
+    }
+}
+
+#ifdef PRIO_QUEUE
+
+/*******************************************************************************
+* Function Name  : iec10x_prio_highest
+* Description    :
+* Input          : None
+* Output         : None
+* Return         : RET_ERROR failure
+                   len sucess
+*******************************************************************************/
+iec_8u iec10x_prio_highest(void)
+{
+
+    int    i, prio;
+    iec_8u flag = 0;
+    prio        = -1;
+    // LOG("%s \r\n",__FUNCTION__);
+    for (i = 0; i < IEC10X_PRIO_MAX; i++)
+    {
+        if (iec10x_prio_queue_array[i].element_num > 0 && !flag)
+        {
+            // return i;
+            prio = i;
+            flag = 1;
+            LOG("<%s>Prio[%d],Num%d. \n", __FUNCTION__, i, iec10x_prio_queue_array[i].element_num);
+        }
+        LOG("[%d]%d.", i, iec10x_prio_queue_array[i].element_num);
+    }
+    LOG("out(%d)\r\n", prio);
+    return prio;
+}
+
+void iec104_prio_queue_init(iec104_prio_queue_t *PrioQueue)
+{
+
+    PrioQueue->header      = NULL;
+    PrioQueue->tail        = NULL;
+    PrioQueue->element_num = 0;
+}
+iec_8u iec104_prio_enqueue(iec104_prio_queue_t *queue_hdr, iec104_prio_node_t *new_p)
+{
+
+    new_p->Next = NULL;
+
+    if (queue_hdr->header == NULL)
+    {
+        queue_hdr->header = new_p;
+        queue_hdr->tail   = new_p;
+    }
+    else
+    {
+        queue_hdr->tail->Next = new_p;
+        queue_hdr->tail       = new_p;
+    }
+
+    queue_hdr->element_num++;
+    LOG("%s ElementNum(%d) \r\n", __FUNCTION__, queue_hdr->element_num);
+    return RET_SUCESS;
+}
+
+iec104_prio_node_t *iec104_prio_dequeue(iec104_prio_queue_t *queue_hdr)
+{
+
+    iec104_prio_node_t *PrioNode_DeQ;
+    if (queue_hdr->header == NULL)
+    {
+        LOG("PrioDeQueue,error \r\n");
+        return NULL;
+    }
+    PrioNode_DeQ = queue_hdr->header;
+
+    queue_hdr->header = queue_hdr->header->Next;
+    if (queue_hdr->header == NULL)
+    {
+        queue_hdr->tail = NULL;
+    }
+
+    LOG("PrioDeQueue(%d) \r\n", PrioNode_DeQ->Length);
+
+    return PrioNode_DeQ;
+}
+
+iec104_prio_node_t *iec104_prio_queue_find_head(iec104_prio_queue_t *queue_hdr)
+{
+
+    iec104_prio_node_t *PrioNode_DeQ;
+    if (queue_hdr->header == NULL)
+    {
+        // LOG("PrioDeQueue,error \r\n");
+        return NULL;
+    }
+    PrioNode_DeQ = queue_hdr->header;
+
+    // LOG("PrioDeQueue(%d) \r\n",PrioNode_DeQ->Length);
+
+    return PrioNode_DeQ;
+}
+
+void *IEC10X_PeekQueue(iec104_prio_queue_t *queue_hdr)
+{
+
+    if (queue_hdr->header == NULL)
+    {
+        // LOG("   ");
+        return NULL;
+    }
+    return queue_hdr->header->value;
+}
+
+int IEC10X_Prio_IsEmptyQueue(iec104_prio_queue_t *queue_hdr)
+{
+
+    if (queue_hdr->header == NULL)
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+void iec104_prio_queue_clear(iec104_prio_queue_t *iec10x_prio_queue)
+{
+
+    iec104_prio_node_t *p = iec10x_prio_queue->header;
+    while (p != NULL)
+    {
+        iec10x_prio_queue->header = iec10x_prio_queue->header->Next;
+        iec104->free(p);
+        p = iec10x_prio_queue->header;
+    }
+    iec10x_prio_queue->tail        = NULL;
+    iec10x_prio_queue->element_num = 0;
+    return;
+}
+
+#endif

+ 88 - 129
User/app/iec104/iec10x.h → User/app/iec104/iec104_queue.h

@@ -1,33 +1,18 @@
-/**
-************************************************************************************************
-* @文件    : Iec10x.h
-* @作者    : 樊春春
-* @版本    : V1.0
-* @时间    : 2022/07/09 16:18:16
-* @邮箱    : [email protected]
-* @说明    :
-************************************************************************************************
-**/
-#ifndef _IEC10X_H
-#define _IEC10X_H
-
-#include "iec10x_conf.h"
-#include "iec10x_prio_queue.h"
-#include "iec10x_type.h"
+#ifndef _IEC104_QUEUE_H
+#define _IEC104_QUEUE_H
+
+#include "iec104_conf.h"
+#include "iec104_types.h"
 #include <stdio.h>
 #include <string.h>
 
 /*
- * CONFIGURE
+ * IEC104配置
  * */
-#define IEC10XLOCK
+#define IEC104LOCK
 #define PRIO_QUEUE
 
-#ifdef IEC101_SET
-#define IEC10X_PRIO_MAX 7
-#elif defined(IEC104_SET)
-#define IEC10X_PRIO_MAX 7
-#endif
+#define IEC10X_PRIO_MAX      7
 #define IEC10X_HEADER_LENGTH 1
 
 /*
@@ -44,28 +29,28 @@
 /*
  *  Transmission  Priority Queue.
  */
-typedef struct IEC10X_CallbackArg
+typedef struct iec104_callback_arg
 {
     iec_8u *value;
-    iec_32u PicSn;
+    iec_32u pic_sn;
     iec_32u FramSerialNum;
-} Iec10x_CallbackArg_T;
+} iec104_callback_arg_t;
 
-typedef struct IEC10X_NODE
+typedef struct iec104_node
 {
     iec_16u             Length;
-    struct IEC10X_NODE *Next;
-    void (*CallBack)(Iec10x_CallbackArg_T *Arg);
-    Iec10x_CallbackArg_T CallBackArg;
-    iec_8u               value[1];
-} Iec10x_PrioNode_T;
+    struct iec104_node *Next;
+    void (*CallBack)(iec104_callback_arg_t *Arg);
+    iec104_callback_arg_t CallBackArg;
+    iec_8u                value[1];
+} iec104_prio_node_t;
 
-typedef struct IEC10X_QUEUE
+typedef struct iec104_queue
 {
-    struct IEC10X_NODE *Header;
-    struct IEC10X_NODE *Tail;
-    unsigned char       ElementNum;
-} Iec10x_PrioQueue_T;
+    struct iec104_node *header;
+    struct iec104_node *tail;
+    unsigned char       element_num;
+} iec104_prio_queue_t;
 
 /*
 *********************************************************************************************************
@@ -119,9 +104,9 @@ typedef struct IEC10X_QUEUE
 #define IEC10X_ASDU_COT_UNKNOW     45
 
 /*
- * INFO ADDR
+ * INFO addr
  * */
-#define IEC10X_INFO_ADDR_NONE 0X00
+#define IEC10X_INFO_addr_NONE 0X00
 
 /*
 *********************************************************************************************************
@@ -182,8 +167,8 @@ typedef struct IEC10X_QUEUE
 /*
  * Asdu addr
  * */
-#define IEC10X_INFO_ADDR_DET             0X4001
-#define IEC10X_INFO_ADDR_DET_TEMP_HX_OFF 0x1000
+#define IEC10X_INFO_addr_DET             0X4001
+#define IEC10X_INFO_addr_DET_TEMP_HX_OFF 0x1000
 
 /*
 *********************************************************************************************************
@@ -199,7 +184,7 @@ typedef struct IEC10X_QUEUE
 
 /*
 *********************************************************************************************************
-*                           INFO ADDREST
+*                           INFO addrEST
 *               TD -- temprature device
 *               PD -- pullotion device
 *********************************************************************************************************
@@ -249,16 +234,9 @@ typedef struct
  * */
 typedef struct
 {
-#ifdef IEC101_SET
-    iec_8u _reason : 6;
-    iec_8u _pn     : 1;
-    iec_8u _test   : 1;
-#elif defined(IEC104_SET)
     iec_16u _reason : 14;
     iec_16u _pn     : 1;
     iec_16u _test   : 1;
-#endif
-
 } ASDU_REASON_T;
 /*
  *  asdu
@@ -271,20 +249,15 @@ typedef struct
     ASDU_REASON_T _reason;
     iec_16u       _addr;
     iec_8u        _info[1];
-} IEC10X_ASDU_T, *PIEC10X_ASDU_T;
+} iec10x_asdu_t, *p_iec10x_asdu_t;
 /*
  *  asdu info
  * */
 typedef struct
 {
-
-#ifdef IEC101_SET
-    iec_16u _addr;
-#elif defined(IEC104_SET)
-    iec_8u  _addr[3];
-#endif
+    iec_8u _addr[3];
     iec_8u _element[1];
-} ASDU_INFO_T, *PASDU_INFO_T;
+} asdu_info_t, *p_asdu_info_t;
 
 /*
  *  asdu info remote signal with time flag
@@ -319,12 +292,7 @@ typedef struct
 /*int  sq=0 */
 typedef struct
 {
-
-#ifdef IEC101_SET
-    iec_16u _addr;
-#elif defined(IEC104_SET)
     iec_8u  _addr[3];
-#endif
     iec_16s _detect;
     iec_8u  _qds;
 
@@ -333,11 +301,7 @@ typedef struct
 typedef struct
 {
 
-#ifdef IEC101_SET
-    iec_16u _addr;
-#elif defined(IEC104_SET)
-    iec_8u  _addr[3];
-#endif
+    iec_8u _addr[3];
     float  _detect;
     iec_8u _qds;
 
@@ -352,7 +316,7 @@ typedef struct
     iec_8u _minutes : 6;
     iec_8u _res     : 1;
     iec_8u _iv      : 1;
-} IEC10X_Time_Min_T, *PIEC10X_Time_Min_T;
+} iec10x_time_min_t, *p_iec10x_time_min_t;
 
 typedef struct
 {
@@ -360,7 +324,7 @@ typedef struct
     iec_8u _hours : 5;
     iec_8u _res   : 2;
     iec_8u _su    : 1;
-} IEC10X_Time_Hour_T, *PIEC10X_Time_Hour_T;
+} iec10x_time_hour_t, *p_iec10x_time_hour_t;
 typedef struct
 {
 
@@ -383,8 +347,8 @@ typedef struct
 {
 
     iec_16u             _milliseconds;
-    IEC10X_Time_Min_T   _min;
-    IEC10X_Time_Hour_T  _hour;
+    iec10x_time_min_t   _min;
+    iec10x_time_hour_t  _hour;
     IEC10X_Time_Day_T   _day;
     IEC10X_Time_Month_T _month;
     IEC10X_Time_Year_T  _year;
@@ -407,40 +371,40 @@ typedef struct
 /*
  * Iec10x init
  */
-typedef struct _iec10x
+typedef struct _iec104
 {
 
     char *name;
-    int (*Init)(void);
-    void (*Delay_ms)(iec_16u);
-    void (*CloseLink)(void);
-    void *(*Malloc)(iec_8u nbyte);
-    void (*Free)(void *buffer);
-    iec_8u (*enqueue)(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *newnode);
-    Iec10x_PrioNode_T *(*dequeue)(Iec10x_PrioQueue_T *QueueHdr);
-    Iec10x_PrioNode_T *(*FindQHead)(Iec10x_PrioQueue_T *QueueHdr);
-    iec_8u (*GetPrio)(void);
-    void (*InitQueue)(Iec10x_PrioQueue_T *PrioQueue);
-    void (*ClearQueue)(Iec10x_PrioQueue_T *QueueHdr);
-    iec_8u (*Send)(int socketfd, char *data, int len);
-    iec_32u (*SetTime)(PCP56Time2a_T time);
-    iec_32u (*GetTime)(PCP56Time2a_T time);
-    iec_8s (*GetStationState)(iec_16u Addr, iec_8u DevType);
-    float (*GetStaValue)(iec_16u Addr, iec_8u DevType);
-    iec_16u (*GetLinkAddr)(void);
-    iec_8s (*GetInfoNum)(iec_8u *InfoNum, iec_8u DevType);
-    iec_8s (*SetConfig)(long Value, iec_32u addr);
-    iec_8s (*SaveFirmware)(iec_8u FirmLen, iec_8u *buf, iec_32u FirmwareType, iec_32u Iec10x_Update_SeekAddr);
-    iec_8s (*CheckFirmware)(iec_32u FirmwareType, iec_32u TotalLen);
-    iec_8s (*UpdateFirmware)(iec_32u FirmwareType);
-    iec_8s (*BackoffFirmware)(iec_32u FirmwareType);
-
-#ifdef IEC10XLOCK
-    void (*LOCK)(void);
-    void (*UNLOCK)(void);
+    int (*init)(void);
+    void (*delay_ms)(iec_16u);
+    void (*close_link)(void);
+    void *(*malloc)(iec_8u nbyte);
+    void (*free)(void *buffer);
+    iec_8u (*enqueue)(iec104_prio_queue_t *queue_hdr, iec104_prio_node_t *newnode);
+    iec104_prio_node_t *(*dequeue)(iec104_prio_queue_t *queue_hdr);
+    iec104_prio_node_t *(*find_qhead)(iec104_prio_queue_t *queue_hdr);
+    iec_8u (*get_prio)(void);
+    void (*queue_init)(iec104_prio_queue_t *PrioQueue);
+    void (*queue_clear)(iec104_prio_queue_t *queue_hdr);
+    iec_8u (*send)(int socketfd, char *data, int len);
+    iec_32u (*set_time)(PCP56Time2a_T time);
+    iec_32u (*get_time)(PCP56Time2a_T time);
+    iec_8s (*get_station_state)(iec_16u addr, iec_8u dev_type);
+    float (*get_sta_value)(iec_16u addr, iec_8u dev_type);
+    iec_16u (*get_link_addr)(void);
+    iec_8s (*get_info_num)(iec_8u *info_num, iec_8u dev_type);
+    iec_8s (*set_config)(long value, iec_32u addr);
+    iec_8s (*save_firmware)(iec_8u firm_len, iec_8u *buf, iec_32u firmware_type, iec_32u iec104_update_seek_addr);
+    iec_8s (*check_firmware)(iec_32u firmware_type, iec_32u total_len);
+    iec_8s (*update_firmware)(iec_32u firmware_type);
+    iec_8s (*backoff_firmware)(iec_32u firmware_type);
+
+#ifdef IEC104LOCK
+    void (*lock)(void);
+    void (*unlock)(void);
 #endif
 
-} * PIEC10X_T, IEC10X_T;
+} *p_iec104_t, iec104_t;
 
 /*
  * BIG ENDIAN
@@ -467,43 +431,38 @@ typedef struct _iec10x
 *                                           EXTERN VARIABLE
 *********************************************************************************************************
 */
-extern PIEC10X_T IEC10X;
-extern iec_16u   Iec10x_Sta_Addr;
-extern iec_32s   Iec104_BuildSendSn;
-extern iec_32s   Iec104_BuildRecvSn;
+extern p_iec104_t iec104;
+extern iec_16u    iec104_state_addr;
+extern iec_32s    iec104_build_send_sn;
+extern iec_32s    iec104_build_recv_sn;
 
 extern iec_16u      IEC10X_Cp16time2a;
 extern iec_16u      IEC10X_Cp16time2a_V;
 extern CP56Time2a_T IEC10X_Cp56time2a;
 extern iec_8u       Iec10x_FirmwareUpdateFlag;
-/*
-*********************************************************************************************************
-*                                          QUEUE FUNCTION PROTOTYPES
-*********************************************************************************************************
-*/
+
 /*
  * Prio
  * */
-iec_8u             IEC10X_PrioEnQueue(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *new_p);
-Iec10x_PrioNode_T *IEC10X_PrioDeQueue(Iec10x_PrioQueue_T *QueueHdr);
-iec_8u             IEC10X_HighestPrio(void);
-void               IEC10X_PrioInitQueue(Iec10x_PrioQueue_T *PrioQueue);
-void               IEC10X_Prio_ClearQueue(Iec10x_PrioQueue_T *QueueHdr);
-Iec10x_PrioNode_T *IEC10X_PrioFindQueueHead(Iec10x_PrioQueue_T *QueueHdr);
-/*
- * Iec10x queue
+iec_8u              iec104_prio_enqueue(iec104_prio_queue_t *queue_hdr, iec104_prio_node_t *new_p);
+iec104_prio_node_t *iec104_prio_dequeue(iec104_prio_queue_t *queue_hdr);
+iec_8u              iec10x_prio_highest(void);
+void                iec104_prio_queue_init(iec104_prio_queue_t *PrioQueue);
+void                iec104_prio_queue_clear(iec104_prio_queue_t *queue_hdr);
+iec104_prio_node_t *iec104_prio_queue_find_head(iec104_prio_queue_t *queue_hdr);
+
+/*
+ * iec104 队列
  * */
-void               IEC10X_InitQ(void);
-void               IEC10X_ClearQ(void);
-iec_8u             IEC10X_GetPrio(iec_8u State);
-void               IEC10X_Enqueue(iec_8u *EnQBuf, iec_16u Length, iec_8u Prio,
-                                  void (*IEC10XCallBack)(Iec10x_CallbackArg_T *Arg), Iec10x_CallbackArg_T *CallbackArg);
-void               Iec10x_Scheduled(int socketfd);
-Iec10x_PrioNode_T *IEC10X_Dequeue(void);
-iec_32s            RegisterIEC10XMoudle(void *_IEC10X);
-void               IEC10X_ClearQ(void);
-
-void Iec10x_Lock(void);
-void Iec10x_UnLock(void);
+void                iec104_queue_init(void);
+void                iec104_queue_clear(void);
+iec_8u              iec104_prio_get(iec_8u State);
+void                iec104_enqueue(iec_8u *enq_buf, iec_16u Length, iec_8u Prio,
+                                   void (*IEC10XCallBack)(iec104_callback_arg_t *Arg), iec104_callback_arg_t *CallbackArg);
+void                iec104_scheduled(int socketfd);
+iec104_prio_node_t *iec104_dequeue(void);
+iec_32s             iec104_module_register(void *p_iec10x);
+void                iec104_lock(void);
+void                iec104_unlock(void);
 
 #endif /*_IEC10X_H*/

+ 0 - 2
User/app/iec104/iec10x_type.h → User/app/iec104/iec104_types.h

@@ -1,5 +1,3 @@
-// #ifndef __int8_t_defined
-// #define __int8_t_defined
 typedef signed char iec_8s;
 typedef short int   iec_16s;
 typedef int         iec_32s;

+ 0 - 213
User/app/iec104/iec10x.c

@@ -1,213 +0,0 @@
-/**
-************************************************************************************************
-* @文件    : Iec10x.c
-* @作者    : 樊春春
-* @版本    : V1.0
-* @时间    : 2022/07/09 16:18:42
-* @邮箱    : [email protected]
-* @说明    :
-************************************************************************************************
-**/
-
-#include "iec10x.h"
-#include "iec10x_conf.h"
-#include "iec10x_type.h"
-
-PIEC10X_T          IEC10X          = NULL;
-iec_16u            Iec10x_Sta_Addr = 0;
-Iec10x_PrioQueue_T Iec10x_PrioQueueArray[IEC10X_PRIO_MAX];
-
-iec_16u      IEC10X_Cp16time2a   = 0;
-iec_16u      IEC10X_Cp16time2a_V = 0;
-CP56Time2a_T IEC10X_Cp56time2a;
-
-void Iec10x_Lock(void)
-{
-
-#ifdef IEC10XLOCK
-    if (IEC10X->LOCK != NULL)
-        IEC10X->LOCK();
-#endif
-}
-void Iec10x_UnLock(void)
-{
-
-#ifdef IEC10XLOCK
-    if (IEC10X->UNLOCK != NULL)
-        IEC10X->UNLOCK();
-#endif
-}
-
-/****************************************************
- * @函数    : IEC10X_InitQ
- * @作者    : 樊春春
- * @功能    :
- * @入参    :
- * @说明    :
- *****************************************************/
-void IEC10X_InitQ(void)
-{
-    iec_8u i;
-    for (i = 0; i < IEC10X_PRIO_MAX; i++)
-    {
-        IEC10X->InitQueue(&Iec10x_PrioQueueArray[i]);
-    }
-}
-
-void IEC10X_ClearQ(void)
-{
-    iec_8u i;
-    for (i = 0; i < IEC10X_PRIO_MAX; i++)
-    {
-        IEC10X->ClearQueue(&Iec10x_PrioQueueArray[i]);
-    }
-}
-
-iec_8u IEC10X_GetPrio(iec_8u State)
-{
-
-    /*Prio from 0~7*/
-    iec_8u Prio = 0;
-
-    return Prio;
-}
-
-void IEC10X_Enqueue(iec_8u *EnQBuf, iec_16u Length, iec_8u Prio,
-                    void (*IEC10XCallBack)(Iec10x_CallbackArg_T *Arg), Iec10x_CallbackArg_T *CallbackArg)
-{
-
-    Iec10x_PrioNode_T *new_p;
-
-    Iec10x_Lock();
-    if (Length < IEC10X_HEADER_LENGTH)
-    {
-        LOG("IEC10X_Enqueue,buffer too short \r\n");
-        goto END;
-    }
-
-    new_p = (Iec10x_PrioNode_T *)IEC10X->Malloc(sizeof(Iec10x_PrioNode_T) + Length - 1);
-    if (new_p == NULL)
-    {
-        LOG("IEC10X_Enqueue,malloc error \r\n");
-        goto END;
-    }
-
-    memcpy(new_p->value, EnQBuf, Length);
-    new_p->Length = Length;
-
-    /* Prio from 1~8, Array from 0~7*/
-    if (Prio >= IEC10X_PRIO_MAX)
-    {
-        LOG("IEC10X_Enqueue, error Prio(%d) \r\n", Prio);
-        goto END;
-    }
-
-    /* Set callback Argument */
-    new_p->CallBack = IEC10XCallBack;
-    if (CallbackArg != NULL)
-        new_p->CallBackArg = *CallbackArg;
-
-    new_p->CallBackArg.value = new_p->value;
-    LOG("IEC10X_Enqueue,Prio(%d) elementNum(%d)len(%d)(%d) \r\n", Prio, Iec10x_PrioQueueArray[Prio].ElementNum, Length, new_p->Length);
-    // DumpHEX(new_p->value, new_p->Length);
-    IEC10X->enqueue(&Iec10x_PrioQueueArray[Prio], new_p);
-END:
-    Iec10x_UnLock();
-    return;
-}
-
-Iec10x_PrioNode_T *IEC10X_Dequeue(void)
-{
-    iec_8u             Prio;
-    Iec10x_PrioNode_T *ret;
-    Prio = IEC10X->GetPrio();
-    if (Prio >= 8)
-    {
-        LOG("IEC10X_Dequeue, Error Prio(%d) \r\n", Prio);
-        return 0;
-    }
-    ret = IEC10X->dequeue(&Iec10x_PrioQueueArray[Prio]);
-    if (ret)
-    {
-        Iec10x_PrioQueueArray[Prio].ElementNum--;
-    }
-    LOG("IEC10X_Dequeue(%d) \r\n", ret->Length);
-    return ret;
-}
-Iec10x_PrioNode_T *IEC10X_FindQHead(void)
-{
-
-    iec_8u             Prio;
-    Iec10x_PrioNode_T *ret;
-    Prio = IEC10X->GetPrio();
-    if (Prio >= 8)
-    {
-        return 0;
-    }
-    ret = IEC10X->FindQHead(&Iec10x_PrioQueueArray[Prio]);
-    return ret;
-}
-
-void Iec10x_Scheduled(int socketfd)
-{
-
-    Iec10x_PrioNode_T *DeQNode;
-
-    DeQNode = IEC10X_Dequeue();
-
-    if (DeQNode)
-    {
-
-        LOG("<<-------------------IEC10X (%d)-------------------->> \r\n", DeQNode->Length);
-
-        /* call back funtion */
-        if (DeQNode->CallBack)
-            DeQNode->CallBack(&(DeQNode->CallBackArg));
-
-        DumpHEX(DeQNode->value, DeQNode->Length);
-        IEC10X->Send(socketfd, (char *)(DeQNode->value), DeQNode->Length);
-
-        Iec10x_Lock();
-        IEC10X->Free(DeQNode);
-        Iec10x_UnLock();
-    }
-}
-/*******************************************************************************
- * Function Name  : RegisterSim900aMoudle
- * Description    : RegisterSim900aMoudle program
- * Input          : None
- * Output         : None
- * Return         : None
- *******************************************************************************/
-iec_32s RegisterIEC10XMoudle(void *_IEC10X)
-{
-
-    int ret;
-    if (NULL == _IEC10X)
-    {
-        return -1;
-    }
-    else
-    {
-        IEC10X = (PIEC10X_T)_IEC10X;
-        if (NULL == IEC10X->Init)
-        {
-            return -1;
-        }
-        else
-        {
-            IEC10X_InitQ();
-            // IEC10X_InitInfo();
-            ret = IEC10X->Init();
-            if (0 == ret)
-            {
-#ifdef IEC101_SET
-                LOG("\r\nRegister \"%s\" IEC101 Success, < HuiXing 2014-2015 > ...\r\n", IEC10X->name);
-#elif defined(IEC104_SET)
-                LOG("\r\nRegister \"%s\" IEC104 Success, < HuiXing 2014-2015 > ...\r\n", IEC10X->name);
-#endif
-            }
-            return ret;
-        }
-    }
-}

+ 0 - 148
User/app/iec104/iec10x_prio_queue.c

@@ -1,148 +0,0 @@
-#include "iec10x_prio_queue.h"
-#include "iec10x.h"
-#include "iec10x_conf.h"
-#include "iec10x_type.h"
-#include "includes.h"
-#include <stdio.h>
-
-extern PIEC10X_T          IEC10X;
-extern Iec10x_PrioQueue_T Iec10x_PrioQueueArray[IEC10X_PRIO_MAX];
-
-#ifdef PRIO_QUEUE
-
-/*******************************************************************************
-* Function Name  : HighestPrio
-* Description    :
-* Input          : None
-* Output         : None
-* Return         : RET_ERROR failure
-                   len sucess
-*******************************************************************************/
-iec_8u IEC10X_HighestPrio(void)
-{
-
-    int    i, prio;
-    iec_8u flag = 0;
-    prio        = -1;
-    // LOG("%s \r\n",__FUNCTION__);
-    for (i = 0; i < IEC10X_PRIO_MAX; i++)
-    {
-        if (Iec10x_PrioQueueArray[i].ElementNum > 0 && !flag)
-        {
-            // return i;
-            prio = i;
-            flag = 1;
-            LOG("<%s>Prio[%d],Num%d. \n", __FUNCTION__, i, Iec10x_PrioQueueArray[i].ElementNum);
-        }
-        LOG("[%d]%d.", i, Iec10x_PrioQueueArray[i].ElementNum);
-    }
-    LOG("out(%d)\r\n", prio);
-    return prio;
-}
-
-void IEC10X_PrioInitQueue(Iec10x_PrioQueue_T *PrioQueue)
-{
-
-    PrioQueue->Header     = NULL;
-    PrioQueue->Tail       = NULL;
-    PrioQueue->ElementNum = 0;
-}
-iec_8u IEC10X_PrioEnQueue(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *new_p)
-{
-
-    new_p->Next = NULL;
-
-    if (QueueHdr->Header == NULL)
-    {
-        QueueHdr->Header = new_p;
-        QueueHdr->Tail   = new_p;
-    }
-    else
-    {
-        QueueHdr->Tail->Next = new_p;
-        QueueHdr->Tail       = new_p;
-    }
-
-    QueueHdr->ElementNum++;
-    LOG("%s ElementNum(%d) \r\n", __FUNCTION__, QueueHdr->ElementNum);
-    return RET_SUCESS;
-}
-
-Iec10x_PrioNode_T *IEC10X_PrioDeQueue(Iec10x_PrioQueue_T *QueueHdr)
-{
-
-    Iec10x_PrioNode_T *PrioNode_DeQ;
-    if (QueueHdr->Header == NULL)
-    {
-        LOG("PrioDeQueue,error \r\n");
-        return NULL;
-    }
-    PrioNode_DeQ = QueueHdr->Header;
-
-    QueueHdr->Header = QueueHdr->Header->Next;
-    if (QueueHdr->Header == NULL)
-    {
-        QueueHdr->Tail = NULL;
-    }
-
-    // LOG("PrioDeQueue(%d) \r\n",PrioNode_DeQ->Length);
-
-    return PrioNode_DeQ;
-}
-
-Iec10x_PrioNode_T *IEC10X_PrioFindQueueHead(Iec10x_PrioQueue_T *QueueHdr)
-{
-
-    Iec10x_PrioNode_T *PrioNode_DeQ;
-    if (QueueHdr->Header == NULL)
-    {
-        // LOG("PrioDeQueue,error \r\n");
-        return NULL;
-    }
-    PrioNode_DeQ = QueueHdr->Header;
-
-    // LOG("PrioDeQueue(%d) \r\n",PrioNode_DeQ->Length);
-
-    return PrioNode_DeQ;
-}
-
-void *IEC10X_PeekQueue(Iec10x_PrioQueue_T *QueueHdr)
-{
-
-    if (QueueHdr->Header == NULL)
-    {
-        // LOG("   ");
-        return NULL;
-    }
-    return QueueHdr->Header->value;
-}
-
-int IEC10X_Prio_IsEmptyQueue(Iec10x_PrioQueue_T *QueueHdr)
-{
-
-    if (QueueHdr->Header == NULL)
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-void IEC10X_Prio_ClearQueue(Iec10x_PrioQueue_T *QueueHdr)
-{
-
-    Iec10x_PrioNode_T *p = QueueHdr->Header;
-    while (p != NULL)
-    {
-        QueueHdr->Header = QueueHdr->Header->Next;
-        IEC10X->Free(p);
-        p = QueueHdr->Header;
-    }
-    QueueHdr->Tail       = NULL;
-    QueueHdr->ElementNum = 0;
-    return;
-}
-
-#endif

+ 0 - 6
User/app/iec104/iec10x_prio_queue.h

@@ -1,6 +0,0 @@
-#ifndef __PRIO_QUEUE_IEC10X_H__
-#define __PRIO_QUEUE_IEC10X_H__
-
-#include "iec10x.h"
-
-#endif

+ 83 - 297
User/app/modbus/modbus.c

@@ -1,28 +1,15 @@
-/**
-************************************************************************************************
-* @文件    : fly_modbus.c
-* @作者    : 樊春春
-* @版本    : V1.0
-* @时间    : 2022/05/30 22:46:49
-* @邮箱    : [email protected]
-* @说明    :
-************************************************************************************************
-**/
-
 #include "modbus.h"
 
-INT16U misc_info_buf[BUF_LEN_128] = {0};
-INT16U cell_temp_buf[BUF_LEN_512] = {0};
-INT16U samkoon_txbuf[BUF_LEN_128] = {0};
+//  ModbusRtu 01帧、02帧、03帧、04帧、05帧、06帧发送函数
+void (*func_modbus_send_frame[7])(u16 register_addr, u16 count, void (*Func_Send)(const u8 *data, u16 count)) = {0, mosbus_send_frame01, mosbus_send_frame02, mosbus_send_frame03, mosbus_send_frame03, mosbus_send_frame05, mosbus_send_frame06}; // modbus 6种类型帧
 
 /****************************************************
- * @函数    : crc_count
- * @作者    : 樊春春
- * @功能    : 计算CRC数据
- * @入参    : addr: 数据指针   num: 数量
- * @说明    : 无
+ *  函 数 名:Count_CRC
+ *  函数功能:计算CRC数据
+ *  入口参数:addr: 数据指针   num: 数量
+ *  说    明:无
  *****************************************************/
-unsigned short crc_count(const INT8U *addr, int num)
+unsigned short count_crc(const u8 *addr, int num)
 {
     unsigned short crc = 0xFFFF;
     int            i;
@@ -38,304 +25,103 @@ unsigned short crc_count(const INT8U *addr, int num)
 }
 
 /****************************************************
- * @函数    : crc_write
- * @作者    : 樊春春
- * @功能    : CRC写入
- * @入参    : p: 数据指针   data: crc值   count: 写入位置
- * @说明    : 无
- *****************************************************/
-void crc_write(INT8U *p, INT16U data, INT8U count)
+ *  函 数 名:ModbusRtu_SendFrame01
+ *  函数功能:发送空调01帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame01(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send)
 {
-    p    = p + (2 * count + 3);
-    *p++ = (INT8U)data;
-    *p++ = (INT8U)(data >> 8);
-}
+    //  01    03    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 3, 0, 1}; // 空调03帧
 
-/****************************************************
- * @函数    : little2big
- * @作者    : 樊春春
- * @功能    : 小端转大端
- * @入参    : buf: 数据指针   count: 个数
- * @说明    : 无
- *****************************************************/
-void little2big(INT16U *buf, INT16U count)
-{
-    INT8U  i      = 0;
-    INT8U *p      = (INT8U *)buf;
-    INT8U *p_next = (INT8U *)buf + 1;
-    char   tmp;
-    for (i = 0; i < 2 * count; i++)
-    {
-        tmp     = *p;
-        *p      = *p_next;
-        *p_next = tmp;
-        p       = p + 2;
-        p_next  = p_next + 2;
-    }
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(count);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }
 
 /****************************************************
- * @函数    : modbus_head
- * @作者    : 樊春春
- * @功能    : Mosbus头拷贝
- * @入参    : des_data: 目标数据指针   src_data: 源数据指针
- * @说明    : 无
- *****************************************************/
-void modbus_head(INT8U *des_data, INT8U *src_data)
-{
-    INT8U i = 0;
-    for (i = 0; i < 2; i++)
-    {
-        *des_data++ = *src_data++;
-    }
-    src_data  = src_data + 3;
-    *des_data = (*src_data) * 2;
-}
-
-/*--------------------------------------------
-** func :ImportantData_TxGet
-** brief:copy send data;
-          soc 1th start from 0x4001;
-** para : samkoon_txbuf\misc_info_buf for use
---------------------------------------------*/
-void ImportantData_TxGet(INT16U pos, INT16U cnt, INT8U *des_data, INT8U *src_data)
-{
-    INT8U i  = 0;
-    pos      = pos - 0x4001; // addr offset 4300 hex
-    src_data = src_data + pos;
-    des_data = des_data + 6; // cell txbuf offset:6
-
-    for (i = pos; i < cnt; i++)
-    {
-        *des_data++ = *src_data++;
-    }
-}
-
-/*---------------------------------------
-** func :Cell_Info_ReadOut
-** brief:copy cell data
-          1th start from 0x4301
-** para :none
----------------------------------------*/
-void Cell_Info_ReadOut(INT16U *p)
+ *  函 数 名:ModbusRtu_SendFrame02
+ *  函数功能:发送空调02帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame02(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send)
 {
-    INT8U i, j;
-
-    for (i = 0; i < 6; i++)
-    {
-        for (j = 0; j < 6; j++)
-        {
-            *p++ = 3300;
-        }
-    }
+    //  01    03    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 3, 0, 1}; // 空调03帧
 
-    //	for(i = 0;i < config_get_slave_num(); i++)   // without offset
-    //  {
-    //		 for(j = 0;j < bmu_get_cell_num(i); j++)
-    //	   {
-    //			 *p++ = 3300; //bmu_get_cell_vol(i,j);
-    //		 }
-    //	}
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(count);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }
-/*---------------------------------------
-** func :Cell_Info_TxGet
-** brief: none
-** para :position \ cnt
----------------------------------------*/
 
-void Cell_Info_TxGet(INT16U pos, INT16U cnt, INT8U *des_data, INT8U *src_data)
+/****************************************************
+ *  函 数 名:ModbusRtu_SendFrame03
+ *  函数功能:发送空调03帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame03(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send)
 {
-    INT8U i  = 0;
-    pos      = pos - 0x4300; // addr offset 4300 hex
-    src_data = src_data + pos;
-    des_data = des_data + 6; // cell txbuf offset:6
+    //  01    03    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 3, 0, 1}; // 空调03帧
 
-    for (i = pos; i < cnt; i++)
-    {
-        *des_data++ = *src_data++;
-    }
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(count);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }
 
-/*---------------------------------------
-** func :Temperature_ReadOut
-** brief:copy temperature data,
-          1th start from 0x55C1
-          offset -40
-** para :none
----------------------------------------*/
-void Temperature_ReadOut(INT16U *p)
+/****************************************************
+ *  函 数 名:ModbusRtu_SendFrame04
+ *  函数功能:发送空调04帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame04(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send)
 {
-    INT8U i, j;
-    for (i = 0; i < 6; i++)
-    {
-        for (j = 0; j < 6; j++)
-        {
-            *p++ = 20;
-        }
-    }
+    //  01    03    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 3, 0, 1}; // 空调03帧
 
-    //	for(i = 0;i < config_get_slave_num(); i++)   // without offset     //PackNum = (total + (singleNum - 1))/singleNum
-    //  {
-    //		 for(j = 0;j < bmu_get_temp_num(i); j++)
-    //	   {
-    //		    *p++ = bmu_get_cell_temp(i,j);
-    //		 }
-    //	}
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(count);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }
 
-/*---------------------------------------
-** func :Cell_Info_TxGet
-** brief: none
-** para :position \ cnt
----------------------------------------*/
-void Temperature_TxGet(INT16U pos, INT16U cnt, INT8U *des_data, INT8U *src_data)
-{
-    INT8U i  = 0;
-    pos      = pos - 0x55c0; // addr offset 55c0 hex
-    src_data = src_data + pos;
-    des_data = des_data + 6; // tmp txbuf offset:6
-
-    for (i = pos; i < cnt; i++)
-    {
-        *des_data++ = *src_data++;
-    }
-}
-/*---------------------------------------
-** func :Rtu_TxData_Get()
-** brief: none
-** para :position \ cnt
----------------------------------------*/
-void Rtu_TxData_Get(INT16U pos,
-                    INT16U cnt,
-                    INT16U addr_start,
-                    INT8U  fotmat_offset, // fotmat_offset:3
-                    INT8U *des_data,
-                    INT8U *src_data)
+/****************************************************
+ *  函 数 名:ModbusRtu_SendFrame05
+ *  函数功能:发送空调05帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame05(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send)
 {
-    INT8U i = 0;
-    if (pos < addr_start)
-        return;
+    //  01    03    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 3, 0, 1}; // 空调03帧
 
-    pos      = pos - addr_start; // addr offset 55c0 hex
-    src_data = src_data + pos * 2;
-    //	des_data = des_data + fotmat_offset;
-    des_data = (INT8U *)des_data + fotmat_offset;
-    for (i = 2 * pos; i < 2 * cnt; i++)
-    {
-        *des_data++ = *src_data++;
-    }
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(count);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }
 
-/*----------------------------------------------
-** @func  : samkoon_com_work
-** @brief : BMS with samkoon communication
-** format :  xx     xx   xx xx   xx xx    xx xx
-             addr  func  -reg-  -count-   -crc-
-      ans:   xx     xx   xx xx   xx....xx    xx xx
-             addr  func  count-  --data--    -crc-
-
-crc:small  other:big
------------------------------------------------*/
-void samkoon_com_work(INT8U *rec_data, void (*tx_p)(const INT8U *buf, INT16U len))
+/****************************************************
+ *  函 数 名:ModbusRtu_SendFrame06
+ *  函数功能:发送空调06帧
+ *  入口参数:register_addr 寄存器地址   count 数量
+ *  说    明:无
+ ****************************************************/
+void mosbus_send_frame06(u16 register_addr, u16 data, FuncSend_TypeDef Func_Send)
 {
-    INT16U          register_addr_hmi;
-    INT16U          tmp_crc;
-    volatile INT16U register_count;
-    volatile INT8U  illegal_flag  = 0;
-    INT8U           function_code = 0;
-
-    register_addr_hmi = (rec_data[REGISTER_ADDR_H] << 8) + rec_data[REGISTER_ADDR_L];
-    register_count    = (rec_data[COUNT_INDEX_H] << 8) + rec_data[COUNT_INDEX_L];
-    function_code     = rec_data[FUNCTION_CODE_INDEX];
-
-    switch (function_code)
-    {
-    case FUNC_03:
-        if ((register_addr_hmi >= MODBUS_ADDR_RACK_REMOTE) && (register_addr_hmi < MODBUS_ADDR_RACK_REMOTE_END))
-        {
-            modbus_head((INT8U *)samkoon_txbuf, rec_data);
-            // Important_Bin_ReadOut(misc_info_buf);
-            little2big(misc_info_buf, register_count);
-            Rtu_TxData_Get(register_addr_hmi, register_count, 0xc9, 3, (INT8U *)samkoon_txbuf, (INT8U *)misc_info_buf);
-            tmp_crc = crc_count((INT8U *)samkoon_txbuf, 2 * register_count + 3);
-            crc_write((INT8U *)samkoon_txbuf, tmp_crc, register_count);
-            //				samkoon_txbuf[register_count + 2] = tmp_crc;
-            tx_p((INT8U *)samkoon_txbuf, (2 * register_count + 5));
-        }
-        else if ((register_addr_hmi >= MODBUS_ADDR_SOC) && (register_addr_hmi < MODBUS_RACK_END))
-        {
-            modbus_head((INT8U *)samkoon_txbuf, rec_data);
-            // ImportantData_Readout(misc_info_buf);
-            little2big(misc_info_buf, register_count);
-            Rtu_TxData_Get(register_addr_hmi, register_count, 0x4101, 3, (INT8U *)samkoon_txbuf, (INT8U *)misc_info_buf);
-            tmp_crc = crc_count((INT8U *)samkoon_txbuf, 2 * register_count + 3);
-            crc_write((INT8U *)samkoon_txbuf, tmp_crc, register_count);
-            //			   	samkoon_txbuf[register_count + 2] = tmp_crc;
-            tx_p((INT8U *)samkoon_txbuf, (2 * register_count + 5));
-        }
-        else if ((register_addr_hmi >= MODBUS_ADDR_CELL) && (register_addr_hmi < MODBUS_CELL_END))
-        {
-            modbus_head((INT8U *)samkoon_txbuf, rec_data);
-            Cell_Info_ReadOut(cell_temp_buf); // read all cell data
-            little2big(cell_temp_buf, register_count);
-            Rtu_TxData_Get(register_addr_hmi, register_count, 0x4301, 3, (INT8U *)samkoon_txbuf, (INT8U *)cell_temp_buf);
-            tmp_crc = crc_count((INT8U *)samkoon_txbuf, 2 * register_count + 3);
-            crc_write((INT8U *)samkoon_txbuf, tmp_crc, register_count);
-            //			     samkoon_txbuf[register_count + 2] = tmp_crc;
-            tx_p((INT8U *)samkoon_txbuf, (2 * register_count + 5));
-        }
-        else if ((register_addr_hmi >= MODBUS_ADDR_TEMP) && (register_addr_hmi < MODBUS_TEMP_END))
-        {
-            modbus_head((INT8U *)samkoon_txbuf, rec_data);
-            Temperature_ReadOut(cell_temp_buf); // read all temp data
-            little2big(cell_temp_buf, register_count);
-            Rtu_TxData_Get(register_addr_hmi, register_count, 0x55c1, 3, (INT8U *)samkoon_txbuf, (INT8U *)cell_temp_buf);
-            tmp_crc = crc_count((INT8U *)samkoon_txbuf, 2 * register_count + 3);
-            crc_write((INT8U *)samkoon_txbuf, tmp_crc, register_count);
-            //			     samkoon_txbuf[register_count + 2] = tmp_crc;
-            tx_p((INT8U *)samkoon_txbuf, (2 * register_count + 5));
-        }
-        else if ((register_addr_hmi >= MODBUS_ADDR_READ_KA) && (register_addr_hmi < MODBUS_KA_END))
-        {
-            modbus_head((INT8U *)samkoon_txbuf, rec_data);
-            // Relay_Bin_Readout(misc_info_buf);
-            little2big(misc_info_buf, register_count);
-            Rtu_TxData_Get(register_addr_hmi, register_count, 0x1001, 3, (INT8U *)samkoon_txbuf, (INT8U *)misc_info_buf);
-            tmp_crc = crc_count((INT8U *)samkoon_txbuf, 2 * register_count + 3);
-            crc_write((INT8U *)samkoon_txbuf, tmp_crc, register_count);
-            //			   	 samkoon_txbuf[register_count + 2] = tmp_crc;
-            tx_p((INT8U *)samkoon_txbuf, (2 * register_count + 5));
-        }
-        break;
-    /* do other work... */
-    case FUNC_05:
-        break;
+    //  01    06    地址H    地址L   数量H   数量L    CRC-L  CRC-H
+    union ModbusRtu_03Frame_Tx_Union_TypeDef ModbusRtu_03Frame_Tx_Union = {1, 6, 0, 0}; // 06帧
 
-    default:
-        illegal_flag = 1;
-        break;
-    }
-}
-
-void modbus_slave_task(void)
-{
-    INT8U              err          = 0;
-    INT8U              test_buf[20] = {0};
-    UartFrame_TypeDef *msg;
-    while (1)
-    {
-        OSTimeDly(200);
-        iwdg_feed(UART3_DOG);
-        msg = (UartFrame_TypeDef *)OSMboxPend(uart3_mbox, 50, &err);
-        if ((err == OS_ERR_NONE) && (msg->len >= 2))
-        {
-            if ((msg->buf[0] == 0x00) && (msg->buf[1] == 0xAA) && (msg->buf[2] == 0xBB))
-            {
-                test_buf[0] = 0x00;
-                test_buf[1] = 0xBB;
-                test_buf[2] = 0xAA;
-                uart3_dma_send(test_buf, 3);
-            }
-        }
-    }
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_addr  = __REV16(register_addr);
+    ModbusRtu_03Frame_Tx_Union.Frame03.register_count = __REV16(data);
+    ModbusRtu_03Frame_Tx_Union.Frame03.crc            = count_crc(ModbusRtu_03Frame_Tx_Union.send_buff, 6);
+    Func_Send((const u8 *)ModbusRtu_03Frame_Tx_Union.send_buff, 8); // DMA发送报文
 }

+ 48 - 68
User/app/modbus/modbus.h

@@ -1,70 +1,50 @@
-#ifndef __MODBUS_H
-#define __MODBUS_H
-
-// #include "bms_config.h"
-#include "fly_param.h"
-// #include "bmu_param.h"
-#include "includes.h"
-#include "iwdg.h"
-#include "uart1.h"
-#include "uart3.h"
-
-typedef unsigned char  MODBUS_INT8U;
-typedef signed char    MODBUS_INT8S;
-typedef unsigned short MODBUS_INT16U;
-typedef signed short   MODBUS_INT16S;
-typedef unsigned int   MODBUS_INT32U;
-typedef signed int     MODBUS_INT32S;
-
-typedef void (*txfun_p)(const INT8U *buf, INT16U len);
-
-#define MODBUS_GAIN(VALUE1, VALUE2)        ((MODBUS_INT32U)(VALUE1) * (VALUE2))
-#define MODBUS_SUBTRACT(VALUE1, VALUE2)    ((MODBUS_INT32U)(VALUE1) - (VALUE2))
-#define MODBUS_DIVISION(DIVISOR, DIVIDEND) (((MODBUS_INT32U)(DIVISOR) + (DIVIDEND) / 2) / (DIVIDEND))
-#define MODBUS_ABS(VALUE1)                 (((VALUE1) < 0) ? (-(VALUE1)) : (VALUE1))
-
-#define BUF_LEN_128      128
-#define BUF_LEN_256      256
-#define BUF_LEN_512      512
-#define RACK_NUM         1u
-#define BUF_LEN_768      768
-#define GROUP_NUMBER_MAX 15
-#define VOL_TMP_PAGE_NUM 32
-
-#define BUF_LEN_256      256
-#define BUF_LEN_512      512
-#define RACK_NUM         1u
-#define BUF_LEN_768      768
-#define GROUP_NUMBER_MAX 15
-#define VOL_TMP_PAGE_NUM 32
-
-#define FUNC_03 3
-#define FUNC_05 5
-#define FUNC_06 6
-#define FUNC_10 16
-
-// samkoon COM def
-#define COUNT_INDEX_H       4
-#define COUNT_INDEX_L       5
-#define REGISTER_ADDR_H     2
-#define REGISTER_ADDR_L     3
-#define FUNCTION_CODE_INDEX 1
-
-// samkoon address def
-
-#define MODBUS_ADDR_SOC         0x4101 // 电池簇SOC寄存器地址
-#define MODBUS_ADDR_CELL        0x4301 // 单体电压寄存器地址
-#define MODBUS_ADDR_TEMP        0x55c1 // 单体温度寄存器地址
-#define MODBUS_ADDR_READ_KA     0x1001 // 继电器状态读地址
-#define MODBUS_ADDR_RACK_REMOTE 0xC9   //
-
-#define MODBUS_RACK_END             0x4120 // 电池簇SOC寄存器地址
-#define MODBUS_CELL_END             0x4490
-#define MODBUS_TEMP_END             0x5750
-#define MODBUS_KA_END               0x1009
-#define MODBUS_ADDR_RACK_REMOTE_END 0xE7
-
-void modbus_master_task(void);
-void modbus_slave_task(void);
+#ifndef __MODBUSRTU_H
+#define __MODBUSRTU_H
+
+#include "project_var.h"
+
+#define ADDR_CONV_COUNT 7
+#define AIR_FRAME_COUNT 8
+
+typedef void (*FuncSend_TypeDef)(const u8 *data, u16 count);
+typedef void (*FuncCommand_TypeDef)(void);
+
+#pragma pack(1)
+// ModbusRtu 03请求帧
+typedef struct
+{
+    u8  addr;
+    u8  function; //
+    u16 register_addr;
+    u16 register_count;
+    u16 crc;
+} ModbusRtu_03Frame_Tx_TypeDef;
+
+union ModbusRtu_03Frame_Tx_Union_TypeDef
+{
+    ModbusRtu_03Frame_Tx_TypeDef Frame03; //
+    u8                           send_buff[16];
+};
+
+#pragma pack() // 取消自定义字节对齐方式
+
+//
+typedef struct
+{
+    u16 register_addr;  //
+    u16 register_count; //
+    u16 frame_style;
+} Modbus_Frame_TypeDef;
+
+extern void (*func_modbus_send_frame[7])(u16 register_addr, u16 count, void (*Func_Send)(const u8 *data, u16 count));
+
+void mosbus_send_frame01(u16 register_addr, u16 count, FuncSend_TypeDef FuncSend);
+void mosbus_send_frame02(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
+void mosbus_send_frame03(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
+void mosbus_send_frame04(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
+void mosbus_send_frame05(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
+void mosbus_send_frame06(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
+
+unsigned short count_crc(const u8 *addr, int num);
 
 #endif

+ 187 - 40
User/app/net/net.c

@@ -1,84 +1,231 @@
 #include "net.h"
+#include "fly_param.h"
 #include "iec104.h"
-#include "iec10x.h"
+#include "iec104_queue.h"
+#include "os_cpu.h"
+#include "stm32f4xx_gpio.h"
+#include "ucos_ii.h"
+#include <stdio.h>
 
-static err_t bms_test_process(int fd, void *data, int len)
+INT32S g_iec104_socket                = -1; /* 创建与104交互的socket */
+INT32S g_modbus_tcp_socket            = -1; /* 创建与104交互的socket */
+INT32S g_modbus_tcp_socket_link_state = 0;  /* 与4G模块Socket信息初始化标志:1初始化完成 0:未初始化 */
+INT32S g_iec104_socket_link_state     = 0;  /* 与4G模块Socket信息初始化标志:1初始化完成 0:未初始化 */
+u8     g_data_req_flag                = 0;
+
+void fly_mosbus_init_flag(void)
 {
-    INT8U response[2] = {0xBB, 0xAA};
-    if ((len == 2) && (((INT8U *)data)[0] == 0xAA) && (((INT8U *)data)[1] == 0xBB))
+    g_data_req_flag = 0;
+    return;
+}
+
+int modbus_tcp_rec_module(INT8U *rec_buf)
+{
+    INT32S buf_len = 0;
+
+    buf_len = recv(g_modbus_tcp_socket, rec_buf, MAX_RECV_SIZE, 0);
+
+    if (buf_len <= 0)
     {
-        send(fd, (void *)response, sizeof(response), 0);
+        fly_mosbus_init_flag();
+        closesocket(g_modbus_tcp_socket);
+        g_modbus_tcp_socket = -1;
+        return -1;
     }
-    return 1;
+    return buf_len;
 }
 
-static err_t bms_net_process(int fd)
+err_t fly_test_process(INT8U *rec_buf, INT32S buf_len)
 {
-
-    Iec10x_Scheduled(fd);
-    Iec104_StateMachine();
+    INT8U response[2] = {0xBB, 0xAA};
+    if (((buf_len == 2) && ((INT8U *)rec_buf)[0] == 0xAA) && (((INT8U *)rec_buf)[1] == 0xBB))
+    {
+        send(g_modbus_tcp_socket, (void *)response, sizeof(response), 0);
+    }
     return 1;
 }
 
-void net_task(void)
+void iec104_task(void)
 {
-    INT8U              buf[500];
-    INT32S             ret    = 0;
-    INT32S             sockfd = -1, newfd = -1;
-    INT32U             len = 0;
-    struct sockaddr_in svr_addr, clt_addr;
+    /* socket 创建 */
+    INT8U                     buf[500];
+    INT32S                    ret = 0;
+    static INT32S             iec104_sockfd;
+    static struct sockaddr_in svr_addr = {0};
+    struct sockaddr_in        clt_addr;
+    INT32U                    non_block = 1;
 
-    INT16U Iec104_RecvLen;
+    //     if (g_iec104_socket_link_state == 1)
+    //     {
+    //         goto SOCKET_LINK;
+    //     }
+    //     iec104_sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    //     if (iec104_sockfd < 0)
+    //     {
+    //         return -1;
+    //     }
+    //     memset(&svr_addr, 0, sizeof(struct sockaddr_in));
+
+    //     /* 端口号设置为2404 */
+    //     svr_addr.sin_family      = AF_INET;
+    //     svr_addr.sin_port        = htons(IEC_PORT);
+    //     svr_addr.sin_addr.s_addr = htons(INADDR_ANY);
+
+    //     /* 绑定 */
+    //     ret = bind(iec104_sockfd, (struct sockaddr *)&svr_addr, sizeof(svr_addr));
+    //     if (ret < 0)
+    //     {
+    //         lwip_close(iec104_sockfd);
+    //         return -1;
+    //     }
+    //     /* 监听1个连接 */
+    //     ret = listen(iec104_sockfd, 1);
+    //     if (ret < 0)
+    //     {
+    //         lwip_close(iec104_sockfd);
+    //         return -1;
+    //     }
+    //     g_iec104_socket_link_state = 1; /* 初始化完成后, socket信息标志置位 */
+
+    // SOCKET_LINK:
+    //     /* 建链 */
+    //     len             = sizeof(clt_addr);
+    //     g_iec104_socket = accept(iec104_sockfd, (struct sockaddr *)&clt_addr, len);
+    //     if (g_iec104_socket < 0)
+    //     {
+    //         return g_iec104_socket;
+    //     }
+    //     ret = ioctlsocket(g_iec104_socket, FIONBIO, (u_long *)&non_block);
+
+    //     if (ret <= 0)
+    //     {
+    //         // DEBUG("the other side has been closed (%d).\n", sizeof(buf) - 1);
+    //         lwip_close(g_iec104_socket);
+    //         g_iec104_socket = -1;
+    //     }
+    //     return g_iec104_socket;
 
     svr_addr.sin_family      = AF_INET;
-    svr_addr.sin_port        = htons(TCP_PORT);
+    svr_addr.sin_port        = htons(IEC_PORT);
     svr_addr.sin_addr.s_addr = htons(INADDR_ANY);
 
     while (1)
     {
-        sockfd = socket(AF_INET, SOCK_STREAM, 0);
-        if (sockfd < 0)
+        iec104_sockfd = socket(AF_INET, SOCK_STREAM, 0);
+        if (iec104_sockfd < 0)
         {
             continue;
         }
 
-        ret = bind(sockfd, (struct sockaddr *)&svr_addr, sizeof(svr_addr));
+        ret = bind(iec104_sockfd, (struct sockaddr *)&svr_addr, sizeof(svr_addr));
         if (ret < 0)
         {
-            lwip_close(sockfd);
-            sockfd = -1;
+            lwip_close(iec104_sockfd);
+            iec104_sockfd = -1;
             continue;
         }
 
-        ret = listen(sockfd, 1);
+        ret = listen(iec104_sockfd, 1);
         if (ret < 0)
         {
-            lwip_close(sockfd);
+            lwip_close(iec104_sockfd);
             continue;
         }
 
-        len = sizeof(clt_addr);
-
-        newfd = accept(sockfd, NULL, NULL);
+        g_iec104_socket = accept(iec104_sockfd, NULL, NULL);
 
-        while (-1 != newfd)
+        while (-1 != g_iec104_socket)
         {
-            ret = recv(newfd, buf, sizeof(buf) - 1, 0);
+            ret = recv(g_iec104_socket, buf, sizeof(buf) - 1, 0);
             if (ret <= 0)
             {
-                printf("the other side has been closed (%d).\n", sizeof(buf) - 1);
-                lwip_close(newfd);
-                newfd = -1;
+                lwip_close(g_iec104_socket);
+                g_iec104_socket = -1;
                 break;
             }
-            bms_net_process(newfd);
-            LOG("#####################received \n");
-            DumpHEX(buf, read(newfd, buf, 1500));
-            Iex104_Receive(buf, read(newfd, buf, 1500));
+
+            dump_hex(buf, ret);
+            iec104_receive(buf, ret);
         }
 
-        lwip_close(sockfd);
-        sockfd = -1;
-        // OSTimeDly(10);
+        lwip_close(iec104_sockfd);
+        iec104_sockfd = -1;
+    }
+}
+
+INT32S iec104_rec_master(char *rec_buf)
+{
+    INT32S buf_len = 0;
+
+    buf_len = recv(g_iec104_socket, rec_buf, MAX_RECV_SIZE, 0);
+
+    if (buf_len <= 0)
+    {
+        // g_data_req_flag = 0;
+        closesocket(g_iec104_socket);
+        g_iec104_socket = -1;
+        return -1;
     }
+    iec104_receive(rec_buf, buf_len);
+    return buf_len;
 }
+
+int modbus_tcp_connect_module(void)
+{
+    /* socket 创建 */
+    INT8U                     buf[500];
+    INT32S                    ret = 0;
+    static INT32S             modbus_tcp_sockfd;
+    static struct sockaddr_in svr_addr = {0};
+    struct sockaddr_in        clt_addr;
+    INT32U                    len       = 0;
+    INT32U                    non_block = 1;
+
+    if (g_modbus_tcp_socket_link_state == 1)
+    {
+        goto SOCKET_LINK;
+    }
+    modbus_tcp_sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    if (modbus_tcp_sockfd < 0)
+    {
+        return -1;
+    }
+    memset(&svr_addr, 0, sizeof(struct sockaddr_in));
+
+    /* 端口号设置为8080 */
+    svr_addr.sin_family      = AF_INET;
+    svr_addr.sin_port        = htons(TCP_PORT);
+    svr_addr.sin_addr.s_addr = htons(INADDR_ANY);
+
+    /* 绑定 */
+    ret = bind(modbus_tcp_sockfd, (struct sockaddr *)&svr_addr, sizeof(svr_addr));
+    if (ret < 0)
+    {
+        lwip_close(modbus_tcp_sockfd);
+        return -1;
+    }
+    /* 监听1个连接 */
+    ret = listen(modbus_tcp_sockfd, 1);
+    if (ret < 0)
+    {
+        lwip_close(modbus_tcp_sockfd);
+        return -1;
+    }
+    g_modbus_tcp_socket_link_state = 1; /* 初始化完成后, socket信息标志置位 */
+
+SOCKET_LINK:
+    /* 建链 */
+    g_modbus_tcp_socket = accept(modbus_tcp_sockfd, NULL, NULL);
+    if (g_modbus_tcp_socket < 0)
+    {
+        return g_modbus_tcp_socket;
+    }
+    ret = ioctlsocket(g_modbus_tcp_socket, FIONBIO, (u_long *)&non_block);
+
+    if (ret < 0)
+    {
+        lwip_close(g_modbus_tcp_socket);
+        g_modbus_tcp_socket = -1;
+    }
+    return g_modbus_tcp_socket;
+}

+ 15 - 1
User/app/net/net.h

@@ -3,7 +3,21 @@
 #include "includes.h"
 #include "lwip/sockets.h"
 
+extern INT32S g_iec104_socket;
+extern INT32S g_iec104_socket_link_state;
+extern INT32S g_modbus_tcp_socket;
+extern INT32S g_modbus_tcp_socket_link_state;
+extern u8     g_data_req_flag;
+#define MAX_RECV_SIZE 500 /* 最大接收Buf长度 */
+
 #define TCP_PORT 8080
+#define IEC_PORT 2404
+
+void   iec104_task(void);
+INT32S iec104_rec_master(char *rec_buf);
 
-void net_task(void);
+void  fly_mosbus_init_flag(void);
+int   modbus_tcp_rec_module(INT8U *rec_buf);
+err_t fly_test_process(INT8U *rec_buf, INT32S buf_len);
+int   modbus_tcp_connect_module(void);
 #endif

+ 228 - 0
User/app/pcs/pcs.c

@@ -0,0 +1,228 @@
+// /**
+// ************************************************************************************************
+// * @file   		pcs_nr.c
+// * @author  		国轩储能
+// * @version 		V1.0
+// * @date    		2018-11-20
+// * @brief   		南瑞pcs通讯
+// * @attention
+// ************************************************************************************************
+// **/
+
+// #include "ModbusTcp_Client.h"
+// #include "os_my_var.h"
+// #include "pcs_nr.h"
+// #include "socket.h"
+// #include "w5500.h"
+
+// u16 pcs_run_data1[48]; // pcs1 运行数据
+// u32 time_pcs;
+
+// void __bsp_Pcs_FrameSend_W5500(const u8 *pMsg, u8 count);
+// void Pcs_RecFrame_1st(const u8 *p);
+// void Pcs_RecFrame_2nd(const u8 *p);
+// void (*Func_PcsHandleFrame[2])(const u8 *p) = {Pcs_RecFrame_1st, Pcs_RecFrame_2nd}; // 定义PCS接收帧
+
+// // 定义PCS发送帧
+// FrameSend_TypeDef PCSFrameArray[PCS_FRAME_COUNT] =
+//     {
+//         {0, 1, 0x0000, 10, ModbusTcpCli_SendFrame04, Pcs_RecFrame_1st},
+//         {1, 0, 0x000a, 36, ModbusTcpCli_SendFrame04, Pcs_RecFrame_2nd},
+//         {2, 3, 0x0000, 10, ModbusTcpCli_SendFrame04, Pcs_RecFrame_1st},
+//         {3, 4, 0x0000, 10, ModbusTcpCli_SendFrame04, Pcs_RecFrame_1st},
+//         {4, 0, 0x0000, 10, ModbusTcpCli_SendFrame04, Pcs_RecFrame_1st},
+
+// };
+
+// ModbusTcpCli_TypeDef ModbusTcpCli_Pcs = {1, __bsp_Pcs_FrameSend_W5500}; //  1: 从机地址,  __bsp_Pcs_FrameSend_W5500:发送函数
+
+// /****************************************************
+//  *  函 数 名:CopyPCS1_DataRun
+//  *  函数功能:读取PCS1运行数据
+//  *  入口参数:register_addr 寄存器地址   count 数量  p 缓冲区指针
+//  *  说    明:无
+//  *****************************************************/
+// void CopyPCS1_DataRun(u16 register_addr, u16 count, u16 *p)
+// {
+//     u16 offset, i;
+//     offset = register_addr - MODBUS_ADDR_PCS1_RUN;
+
+//     for (i = 0; i < count; i++)
+//         *p++ = pcs_run_data1[offset + i];
+// }
+
+// /****************************************************
+//  *  函 数 名:PCS1_ParSet_YK
+//  *  函数功能:PCS遥控参数设置
+//  *  入口参数:register_addr: 寄存器地址,  data:  0 断开   1 闭合
+//  *  说    明:无
+//  *****************************************************/
+// void PCS1_ParSet_YK(u16 register_addr, u16 data)
+// {
+//     u16       register_pcs, value;
+//     OS_RESULT result;
+//     u8       *pMsg;
+//     register_pcs = register_addr - MODBUS_ADDR_YK_PCS1 + MODBUS_ADDRRESS_PCS_YK;
+
+//     if (getSn_SR(SOCK_PCS1) == SOCK_ESTABLISHED)
+//     {
+//         value = data ? 0xFF00 : 0; //   0   断开    1  吸合
+//         ModbusTcpCli_SendFrame05(register_pcs, value, &ModbusTcpCli_Pcs);
+
+//         /* 等待收到数据,不阻塞任务 */
+//         result = os_mbx_wait(&pcs_set_mailbox, (void *)&pMsg, TIME_200MS);
+//         //  OS_R_OK,表示消息邮箱中有消息,立即从消息邮箱中获得消息,无需等待
+//         //  OS_R_MBX,表示在设置的超时时间范围内收到消息
+//         if ((result == OS_R_OK || result == OS_R_MBX) && (pMsg[7] == 0x05)) // 成功获得消息
+//         {
+//             value = value; // 调试用
+//         }
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:PCS_ParSet_YK
+//  *  函数功能:PCS遥控直流断路器
+//  *  入口参数:data: 数量,  stack_id  电池堆编号(1开始)
+//  *  说    明:无
+//  *****************************************************/
+// void PCS_DCBreaker_YK(u8 data)
+// {
+//     PCS1_ParSet_YK(MODBUS_ADDR_PCS1_DC_BREAKER_HMI, data); //  PCS1
+// }
+
+// /****************************************************
+//  *  函 数 名:PCS1_ParSet_YT
+//  *  函数功能:PCS遥调参数设置
+//  *  入口参数:register_addr 寄存器地址   count 数量  p 缓冲区指针
+//  *  说    明:无
+//  *****************************************************/
+// void PCS1_ParSet_YT(u16 register_addr, int16_t data)
+// {
+//     OS_RESULT result;
+//     u8       *pMsg;
+//     u16       register_pcs, temp;
+
+//     //	  if(data < 0)  // 设置功率-10,pcs显示-11
+//     //			  data++;
+//     register_pcs = register_addr - MODBUS_ADDR_YT_PCS1 + MODBUS_ADDRRESS_PCS_YT;
+
+//     ModbusTcpCli_SendFrame06(register_pcs, data, &ModbusTcpCli_Pcs);
+//     /* 等待PCS数据,不阻塞任务 */
+//     result = os_mbx_wait(&pcs_set_mailbox, (void *)&pMsg, TIME_200MS);
+//     //  OS_R_OK,表示消息邮箱中有消息,立即从消息邮箱中获得消息,无需等待
+//     //  OS_R_MBX,表示在设置的超时时间范围内收到消息。
+//     if ((result == OS_R_OK || result == OS_R_MBX) && (pMsg[7] == 0x06)) // 成功获得消息
+//     {
+//         temp = temp;
+//     }
+// }
+
+// /****************************************************
+//  *  函 数 名:PCS1_NetHandle
+//  *  函数功能:处理PCS发过来数据帧
+//  *  入口参数:p 缓冲区指针
+//  *  说    明:无
+//  *****************************************************/
+// // void PCS1_NetHandle(const u8 *p, u16 register_addr)
+// //{
+// //	// 00 00 00 00 00 05     01    04    字节数    dataH   dataL
+// //     u8  offset, i, temp1, temp2, count;
+// //
+// //	  count = p[8]/2;
+// //	  offset = register_addr - MODBUS_ADDR_PCS1_RUN;
+// //	  if(p[7] == MODBUS_FUNCTION_CODE_04)  // 读取PCS运行数据
+// //		{
+// //			  for(i = 0; i < count; i++)
+// //			  {
+// //				    temp1 = p[9 + 2*i];
+// //					  temp2 = p[9 + 2*i +1];
+// //				    pcs_run_data1[offset + i] = (temp1 << 8) + temp2;
+// //				}
+// //		}
+// // }
+
+// /****************************************************
+//  *  函 数 名:SendFrame_ReadPcsData
+//  *  函数功能:发送获取PCS1数据报文
+//  *  入口参数:register_addr 寄存器地址   count 数量
+//  *  说    明:无
+//  ****************************************************/
+// void ReadPcsData(void)
+// {
+//     u32       time1, time2;
+//     static u8 cur_index = 0; // 1#pcs帧序号
+//     OS_RESULT result;
+//     u8       *pMsg;
+
+//     FrameSend_TypeDef PCSFrame = PCSFrameArray[cur_index]; // 指向当前帧
+//     if (getSn_SR(SOCK_PCS1) == SOCK_ESTABLISHED)
+//     {
+//         // 从发送数据帧到消息邮箱收到数据,办公室实测最短时间20ms,最长40ms
+//         PCSFrame.Send(PCSFrame.start_addr, PCSFrame.reg_count, &ModbusTcpCli_Pcs); // 发送
+//         time1 = DWT_CYCCOUNT;
+//         /* 等待PCS数据,不阻塞任务 */
+//         result = os_mbx_wait(&pcs_yc_mailbox, (void *)&pMsg, TIME_200MS);
+//         //  OS_R_OK,表示消息邮箱中有消息,立即从消息邮箱中获得消息,无需等待
+//         //  OS_R_MBX,表示在设置的超时时间范围内收到消息。
+//         if (result == OS_R_OK || result == OS_R_MBX) // 成功获得消息
+//         {
+//             time2    = DWT_CYCCOUNT;
+//             time_pcs = (time2 - time1) / 168;
+// #if defined(__HUAIBEI)
+//             PCSFrame.Receive(pMsg);
+// #elif defined(__PRODUCT_TEST)
+//             SG_PCS1_NetHandle(rec_buf_pcs1); //  处理PCS发过来数据帧
+// #else
+// #error no such macro!;
+// #endif
+//         }
+//         cur_index = PCSFrame.next_index;
+
+//         Battery_ImportantData[INDEX_STATE_PCS1].com_state = STATE_OK;
+//     }
+//     else
+//         Battery_ImportantData[INDEX_STATE_PCS1].com_state = STATE_FAULT;
+// }
+
+// void Pcs_RecFrame_1st(const u8 *p)
+// {
+//     //                              字节数
+//     // 00 00 00 00 00 04   01   03    2    dataH    dataL
+//     u8 offset, i, temp1, temp2, count;
+
+//     count  = p[8] / 2;
+//     offset = 0;                          // register_addr - MODBUS_ADDR_PCS1_RUN;
+//     if (p[7] == MODBUS_FUNCTION_CODE_04) // 读取PCS运行数据
+//     {
+//         for (i = 0; i < count; i++)
+//         {
+//             temp1                     = p[9 + 2 * i];
+//             temp2                     = p[9 + 2 * i + 1];
+//             pcs_run_data1[offset + i] = (temp1 << 8) + temp2;
+//         }
+//     }
+// }
+
+// void Pcs_RecFrame_2nd(const u8 *p)
+// {
+//     u8 offset, i, temp1, temp2, count;
+
+//     count  = p[8] / 2;
+//     offset = 10;                         // register_addr - MODBUS_ADDR_PCS1_RUN;
+//     if (p[7] == MODBUS_FUNCTION_CODE_04) // 读取PCS运行数据
+//     {
+//         for (i = 0; i < count; i++)
+//         {
+//             temp1                     = p[9 + 2 * i];
+//             temp2                     = p[9 + 2 * i + 1];
+//             pcs_run_data1[offset + i] = (temp1 << 8) + temp2;
+//         }
+//     }
+// }
+
+// void __bsp_Pcs_FrameSend_W5500(const u8 *pMsg, u8 count)
+// {
+//     w5500_send(SOCK_PCS1, pMsg, count);
+//     //   ModbusTcpCli_Pcs1  ModbusTcpCli_TypeDef
+// }

+ 111 - 0
User/app/pcs/pcs.h

@@ -0,0 +1,111 @@
+// #ifndef __PCS_NR_H
+// #define __PCS_NR_H
+
+// #include "project_var2.h"
+// #include "tcp_demo.h"
+
+// // #define ADDR_CONV_COUNT  7
+
+// #define MODBUS_ADDRRESS_PCS_YT 0xF000 // PCS遥调首地址
+
+// #define MODBUS_ADDRRESS_PCS_YK 0x0000 // PCS遥控首地址
+
+// #define PCS_FRAME_COUNT 2 // 请求PCS数据帧数量
+
+// // extern union PCS_10Frame_Tx_Union_TypeDef  PCS_10Frame_Tx_Union;
+// // extern union PCS_04Frame_Tx_Union_TypeDef  PCS_04Frame_Tx_Union;
+
+// #pragma pack(1)
+
+// // pcs 04请求帧
+// typedef struct
+// {
+//     u8  check1;   // 检验信息
+//     u8  check2;   // 检验信息
+//     u16 fix;      //
+//     u8  pud_len1; //
+//     u8  pud_len2; //
+
+//     u8  addr;     //
+//     u8  function; //
+//     u16 register_addr;
+//     u16 register_count;
+
+// } PCS_04Frame_Tx_TypeDef;
+
+// union PCS_04Frame_Tx_Union_TypeDef
+// {
+//     PCS_04Frame_Tx_TypeDef PCS04Frame; // 注意顺序,  PCS04Frame在前,  pcs_send_buff在后。 初始化赋值决定
+//     u8                     pcs_send_buff[16];
+// };
+
+// // pcs 03结果帧
+// typedef struct
+// {
+//     u8 reserve1; // 浮点数组对齐用,否则编译通过,运行进入HardFault_Handler
+//     u8 reserve2;
+//     u8 reserve3;
+//     u8 check1; // 检验信息
+
+//     u8  check2;   // 检验信息
+//     u16 fix;      //
+//     u8  pud_len1; //
+
+//     u8 pud_len2;       //
+//     u8 addr;           //
+//     u8 function;       //
+//     u8 pcs_data_count; //
+
+//     u16 data[128];
+
+// } PCS_03Frame_Result_TypeDef;
+
+// union PCS_03Frame_Rx_Union_TypeDef
+// {
+//     u8                         pcs_rec_buff[256];
+//     PCS_03Frame_Result_TypeDef PCS03Frame; //
+// };
+
+// //////////////////////////******************************************//////////////////////////////
+
+// // pcs 10请求帧
+// typedef struct
+// {
+//     u8  check1;   // 检验信息
+//     u8  check2;   // 检验信息
+//     u16 fix;      //
+//     u8  pud_len1; //
+//     u8  pud_len2; //
+
+//     u8  addr;     //
+//     u8  function; //
+//     u16 register_addr;
+
+//     u16 data; //
+
+// } PCS_10Frame_TypeDef;
+
+// union PCS_10Frame_Tx_Union_TypeDef
+// {
+//     PCS_10Frame_TypeDef PCS10Frame; //
+//     u8                  pcs_send_buff[32];
+// };
+
+// #pragma pack() // 取消自定义字节对齐方式
+
+// void CopyPCS1_DataRun(u16 register_addr, u16 count, u16 *p);
+// // void CopyPCS2_DataRun(u16 register_addr, u16 count, u16 *p);
+
+// void PCS1_ParSet_YK(u16 register_addr, u16 data);
+// // void PCS2_ParSet_YK(u16 register_addr,  u16 data);
+// // void PCS_ParSet_YK(u16 register_addr, u16 data, u8 stack_id);
+// void PCS_DCBreaker_YK(u8 data);
+
+// void PCS1_ParSet_YT(u16 register_addr, int16_t data);
+// // void PCS2_ParSet_YT(u16 register_addr, int16_t data);
+
+// // void PCS1_NetHandle(const u8 *p, u16 register_addr);
+
+// void ReadPcsData(void);
+
+// #endif

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است