Просмотр исходного кода

update: reduce sm info memory, change static to dynamic

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 2 месяцев назад
Родитель
Сommit
b73fbd78b2
6 измененных файлов с 17 добавлено и 6 удалено
  1. 1 1
      README.md
  2. 1 1
      README_zh.md
  3. 1 1
      cherryec_config_template.h
  4. 1 1
      demo/hpmicro/inc/ec_config.h
  5. 1 1
      include/ec_slave.h
  6. 12 1
      src/ec_slave.c

+ 1 - 1
README.md

@@ -11,7 +11,7 @@ CherryECAT is a tiny and beautiful, high real-time and low-jitter EtherCAT maste
 
 ## Feature
 
-- ~ 4K ram, ~32K flash(24K + 8K shell cmd + debug log)
+- ~ 4K ram, ~40K flash(24K + 16K shell cmd, including log)
 - Asynchronous queue-based transfer (one transfer can carry multiple datagrams)
 - Zero-copy technology: directly use enet tx/rx buffer to fill and parse ethercat data
 - Support hot-plugging

+ 1 - 1
README_zh.md

@@ -11,7 +11,7 @@ CherryECAT 是一个小而美的、高实时性、低抖动的 EtherCAT 主机
 
 ## 特性
 
-- ~ 4K ram,~32K flash(24K + 8K shell cmd + debug log)
+- ~ 4K ram,~40K flash(24K + 16K shell cmd, including log)
 - 异步队列式传输(一次传输可以携带多个 datagram)
 - 零拷贝技术:直接使用 enet tx/rx buffer 填充和解析 ethercat 数据
 - 支持热插拔

+ 1 - 1
cherryec_config_template.h

@@ -54,7 +54,7 @@
 #endif
 
 #ifndef CONFIG_EC_PER_SM_MAX_PDOS
-#define CONFIG_EC_PER_SM_MAX_PDOS 8
+#define CONFIG_EC_PER_SM_MAX_PDOS 3
 #endif
 
 #ifndef CONFIG_EC_PER_PDO_MAX_PDO_ENTRIES

+ 1 - 1
demo/hpmicro/inc/ec_config.h

@@ -54,7 +54,7 @@
 #endif
 
 #ifndef CONFIG_EC_PER_SM_MAX_PDOS
-#define CONFIG_EC_PER_SM_MAX_PDOS 8
+#define CONFIG_EC_PER_SM_MAX_PDOS 3
 #endif
 
 #ifndef CONFIG_EC_PER_PDO_MAX_PDO_ENTRIES

+ 1 - 1
include/ec_slave.h

@@ -102,7 +102,7 @@ typedef struct ec_slave {
 
     ec_sii_t sii; /**< Extracted SII data. */
 
-    ec_sm_info_t sm_info[EC_MAX_SYNC_MANAGERS];
+    ec_sm_info_t *sm_info;
     uint8_t sm_count; /**< Number of sync managers. */
 
     ec_slave_config_t *config; /**< Slave custom configuration. */

+ 12 - 1
src/ec_slave.c

@@ -52,6 +52,11 @@ static void ec_slave_clear(ec_slave_t *slave)
         ec_osal_free(slave->sii.strings);
         slave->sii.strings = NULL;
     }
+
+    if (slave->sm_info) {
+        ec_osal_free(slave->sm_info);
+        slave->sm_info = NULL;
+    }
 }
 
 static int ec_slave_fetch_sii_strings(ec_slave_t *slave, const uint8_t *data, size_t data_size)
@@ -1060,7 +1065,6 @@ void ec_slaves_scanning(ec_master_t *master)
                 autoinc_address++;
             }
         }
-        ec_osal_mutex_give(master->scan_lock);
 
         for (uint8_t netdev_idx = EC_NETDEV_MAIN; netdev_idx < CONFIG_EC_MAX_NETDEVS; netdev_idx++) {
             if (master->slaves_responding[netdev_idx] == 0) {
@@ -1305,6 +1309,13 @@ void ec_slaves_scanning(ec_master_t *master)
 
                         EC_ASSERT_MSG(slave->sm_count >= 4, "Slave %u has less than 4 sync managers\n", slave->index);
 
+                        slave->sm_info = ec_osal_malloc(slave->sm_count * sizeof(ec_sm_info_t));
+                        if (!slave->sm_info) {
+                            EC_SLAVE_LOG_ERR("Failed to allocate memory for SM info on slave %u\n", slave->index);
+                            goto mutex_unlock;
+                        }
+                        memset(slave->sm_info, 0, slave->sm_count * sizeof(ec_sm_info_t));
+
                         for (uint8_t i = 0; i < slave->sm_count; i++) {
                             ec_sii_sm_t *sm = (ec_sii_sm_t *)((uint8_t *)cat_data + i * sizeof(ec_sii_sm_t));