Răsfoiți Sursa

update: move ec_start/ec_stop cmd into ec_cmd.c

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 5 zile în urmă
părinte
comite
b47bb1926b
3 a modificat fișierele cu 52 adăugiri și 164 ștergeri
  1. 0 163
      demo/hpmicro/main.c
  2. 51 0
      src/ec_cmd.c
  3. 1 1
      src/ec_slave.c

+ 0 - 163
demo/hpmicro/main.c

@@ -26,12 +26,6 @@ SDK_DECLARE_EXT_ISR_M(BOARD_CONSOLE_UART_IRQ, shell_uart_isr)
 
 #define task_start_PRIORITY (configMAX_PRIORITIES - 2U)
 
-#define MOTOR_MODE_CSV_CSP 0
-#define MOTOR_MODE_CSP     1
-#define MOTOR_MODE_CSV     2
-
-volatile uint8_t motor_mode = MOTOR_MODE_CSV;
-
 ATTR_PLACE_AT_FAST_RAM_BSS ec_master_t g_ec_master;
 
 #ifdef CONFIG_EC_EOE
@@ -116,167 +110,10 @@ CSH_CMD_EXPORT(ethercat, );
 
 unsigned char cherryecat_eepromdata[2048]; // EEPROM data buffer, please generate by esi_parse.py
 
-static ec_pdo_entry_info_t dio_1600[] = {
-    { 0x6000, 0x00, 0x20 },
-};
-
-static ec_pdo_entry_info_t dio_1a00[] = {
-    { 0x7010, 0x00, 0x20 },
-};
-
-static ec_pdo_info_t dio_rxpdos[] = {
-    { 0x1600, 1, &dio_1600[0] },
-};
-
-static ec_pdo_info_t dio_txpdos[] = {
-    { 0x1a00, 1, &dio_1a00[0] },
-};
-
-static ec_sync_info_t dio_syncs[] = {
-    { 2, EC_DIR_OUTPUT, 1, dio_rxpdos },
-    { 3, EC_DIR_INPUT, 1, dio_txpdos },
-};
-
-static ec_pdo_entry_info_t coe402_1602[] = {
-    { 0x6040, 0x00, 0x10 },
-    { 0x60ff, 0x00, 0x20 },
-    { 0x0000, 0x00, 0x10 },
-};
-
-static ec_pdo_entry_info_t coe402_1a02[] = {
-    { 0x6041, 0x00, 0x10 },
-    { 0x6064, 0x00, 0x20 },
-    { 0x0000, 0x00, 0x10 },
-};
-
-static ec_pdo_info_t cia402_csv_rxpdos[] = {
-    { 0x1602, 3, &coe402_1602[0] },
-};
-
-static ec_pdo_info_t cia402_csv_txpdos[] = {
-    { 0x1a02, 3, &coe402_1a02[0] },
-};
-
-static ec_sync_info_t cia402_csv_syncs[] = {
-    { 2, EC_DIR_OUTPUT, 1, cia402_csv_rxpdos },
-    { 3, EC_DIR_INPUT, 1, cia402_csv_txpdos },
-};
-
-static ec_pdo_entry_info_t coe402_1601[] = {
-    { 0x6040, 0x00, 0x10 },
-    { 0x607a, 0x00, 0x20 },
-    { 0x0000, 0x00, 0x10 },
-};
-
-static ec_pdo_entry_info_t coe402_1a01[] = {
-    { 0x6041, 0x00, 0x10 },
-    { 0x6064, 0x00, 0x20 },
-    { 0x0000, 0x00, 0x10 },
-};
-
-static ec_pdo_info_t cia402_csp_rxpdos[] = {
-    { 0x1601, 3, &coe402_1601[0] },
-};
-
-static ec_pdo_info_t cia402_csp_txpdos[] = {
-    { 0x1a01, 3, &coe402_1a01[0] },
-};
-
-static ec_sync_info_t cia402_csp_syncs[] = {
-    { 2, EC_DIR_OUTPUT, 1, cia402_csp_rxpdos },
-    { 3, EC_DIR_INPUT, 1, cia402_csp_txpdos },
-};
-
 void ec_pdo_callback(ec_slave_t *slave, uint8_t *output, uint8_t *input)
 {
 }
 
-int ec_start(int argc, const char **argv)
-{
-    static ec_slave_config_t slave_cia402_config;
-    static ec_slave_config_t slave_dio_config;
-
-    if (g_ec_master.slave_count == 0) {
-        printf("No slave found, please check the connection\r\n");
-        return -1;
-    }
-
-    if (argc < 2) {
-        printf("Please input: ec_start <cyclic time in us> mode\r\n");
-        return -1;
-    }
-
-    slave_cia402_config.dc_assign_activate = 0x300;
-
-    slave_cia402_config.dc_sync[0].cycle_time = atoi(argv[1]) * 1000;
-    slave_cia402_config.dc_sync[0].shift_time = 1000000;
-    slave_cia402_config.dc_sync[1].cycle_time = 0;
-    slave_cia402_config.dc_sync[1].shift_time = 0;
-
-    if (argc >= 3) {
-        if (strncmp(argv[2], "csp", 3) == 0) {
-            motor_mode = MOTOR_MODE_CSP;
-            slave_cia402_config.sync = cia402_csp_syncs;
-            slave_cia402_config.sync_count = sizeof(cia402_csp_syncs) / sizeof(ec_sync_info_t);
-        } else if (strncmp(argv[2], "csv", 3) == 0) {
-            motor_mode = MOTOR_MODE_CSV;
-            slave_cia402_config.sync = cia402_csv_syncs;
-            slave_cia402_config.sync_count = sizeof(cia402_csv_syncs) / sizeof(ec_sync_info_t);
-        } else {
-            printf("Unsupported motor mode, use csv as default\r\n");
-            motor_mode = MOTOR_MODE_CSV;
-            slave_cia402_config.sync = cia402_csv_syncs;
-            slave_cia402_config.sync_count = sizeof(cia402_csv_syncs) / sizeof(ec_sync_info_t);
-        }
-        slave_cia402_config.pdo_callback = ec_pdo_callback;
-    }
-
-    slave_dio_config.dc_assign_activate = 0x300;
-
-    slave_dio_config.dc_sync[0].cycle_time = atoi(argv[1]) * 1000;
-    slave_dio_config.dc_sync[0].shift_time = 1000000;
-    slave_dio_config.dc_sync[1].cycle_time = 0;
-    slave_dio_config.dc_sync[1].shift_time = 0;
-    slave_dio_config.sync = dio_syncs;
-    slave_dio_config.sync_count = sizeof(dio_syncs) / sizeof(ec_sync_info_t);
-    slave_dio_config.pdo_callback = ec_pdo_callback;
-
-    for (uint32_t i = 0; i < g_ec_master.slave_count; i++) {
-        if (g_ec_master.slaves[i].sii.vendor_id != 0x0048504D) { // HPMicro
-            EC_LOG_ERR("Unsupported slave found: vendor_id=0x%08x\n", g_ec_master.slaves[i].sii.vendor_id);
-            return -1;
-        }
-
-        switch (g_ec_master.slaves[i].sii.product_code) {
-            case 0x00000001: // DIO
-                g_ec_master.slaves[i].config = &slave_dio_config;
-                break;
-            case 0x00000003: // CIA402
-            case 0x00000004: // CIA402 + FOE
-                g_ec_master.slaves[i].config = &slave_cia402_config;
-                break;
-
-            default:
-                g_ec_master.slaves[i].config = &slave_dio_config;
-                break;
-        }
-    }
-
-    g_ec_master.cycle_time = atoi(argv[1]) * 1000;       // cycle time in ns
-    g_ec_master.shift_time = atoi(argv[1]) * 1000 * 0.2; // 20% shift time in ns
-    g_ec_master.dc_sync_with_dc_ref_enable = true;       // enable DC sync with dc reference clock
-    ec_master_start(&g_ec_master);
-    return 0;
-}
-CSH_CMD_EXPORT(ec_start, );
-
-int ec_stop(int argc, const char **argv)
-{
-    ec_master_stop(&g_ec_master);
-    return 0;
-}
-CSH_CMD_EXPORT(ec_stop, );
-
 #ifdef CONFIG_EC_EOE
 #include "tcp_client.h"
 int tcp_client(int argc, const char **argv)

+ 51 - 0
src/ec_cmd.c

@@ -25,11 +25,19 @@ void ec_master_cmd_eoe_init(ec_eoe_t *master)
 }
 #endif
 
+__WEAK unsigned char cherryecat_eepromdata[2048]; // EEPROM data buffer, please generate by esi_parse.py
+
+__WEAK void ec_pdo_callback(ec_slave_t *slave, uint8_t *output, uint8_t *input)
+{
+}
+
 static void ec_master_cmd_show_help(void)
 {
     EC_LOG_RAW("CherryECAT " CHERRYECAT_VERSION_STR " Command Line Tool\n\n");
     EC_LOG_RAW("Usage: ethercat <command> [options]\n");
     EC_LOG_RAW("Commands:\n");
+    EC_LOG_RAW("  start <cyclic_time_us> <cia402_mode>           Start master pdo timer\n");
+    EC_LOG_RAW("  stop                                           Stop master pdo timer\n");
     EC_LOG_RAW("  master                                         Show master information\n");
     EC_LOG_RAW("  rescan                                         Request a slaves rescan\n");
     EC_LOG_RAW("  slaves                                         Show slaves overview\n");
@@ -450,6 +458,49 @@ int ethercat(int argc, const char **argv)
     if (strcmp(argv[1], "help") == 0) {
         ec_master_cmd_show_help();
         return 0;
+    } else if (strcmp(argv[1], "start") == 0) {
+        static ec_slave_config_t slave_config[32];
+        uint8_t motor_mode;
+
+        if (argc == 4) {
+            motor_mode = atoi(argv[3]);
+        } else {
+            motor_mode = 0;
+        }
+
+        for (uint32_t i = 0; i < global_cmd_master->slave_count; i++) {
+            ret = ec_master_find_slave_sync_info(global_cmd_master->slaves[i].sii.vendor_id,
+                                                 global_cmd_master->slaves[i].sii.product_code,
+                                                 global_cmd_master->slaves[i].sii.revision_number,
+                                                 motor_mode,
+                                                 &slave_config[i].sync,
+                                                 &slave_config[i].sync_count);
+            if (ret != 0) {
+                EC_LOG_ERR("Failed to find slave sync info: vendor_id=0x%08x, product_code=0x%08x\n",
+                           global_cmd_master->slaves[i].sii.vendor_id,
+                           global_cmd_master->slaves[i].sii.product_code);
+                return -1;
+            }
+
+            slave_config[i].dc_assign_activate = 0x300;
+
+            slave_config[i].dc_sync[0].cycle_time = atoi(argv[1]) * 1000;
+            slave_config[i].dc_sync[0].shift_time = 1000000;
+            slave_config[i].dc_sync[1].cycle_time = 0;
+            slave_config[i].dc_sync[1].shift_time = 0;
+            slave_config[i].pdo_callback = ec_pdo_callback;
+
+            global_cmd_master->slaves[i].config = &slave_config[i];
+        }
+
+        global_cmd_master->cycle_time = atoi(argv[2]) * 1000;       // cycle time in ns
+        global_cmd_master->shift_time = atoi(argv[2]) * 1000 * 0.2; // 20% shift time in ns
+        global_cmd_master->dc_sync_with_dc_ref_enable = true;       // enable DC sync with dc reference clock
+        ec_master_start(global_cmd_master);
+        return 0;
+    } else if (strcmp(argv[1], "stop") == 0) {
+        ec_master_stop(global_cmd_master);
+        return 0;
     } else if (strcmp(argv[1], "master") == 0) {
         ec_master_cmd_master(global_cmd_master);
         return 0;

+ 1 - 1
src/ec_slave.c

@@ -949,7 +949,7 @@ void ec_slaves_scanning(ec_master_t *master)
     ec_slave_t *slave;
     uint8_t netdev_idx;
     bool rescan_required = false;
-    unsigned int scan_jiffies;
+    uint64_t scan_jiffies;
     uint64_t ref_time[CONFIG_EC_MAX_NETDEVS] = { 0 };
     int ret;