diff --git a/TODO b/TODO index 89bbd6f4..41ee54ac 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,13 @@ Version 1.5.0: * Distributed clocks: - Delay calculation. - - Output reference clock and application time in 'ethercat master'. - User same application time offset when setting start times. + - Replace timeval by uint64 EtherCAT time. +* Fix arguments of reg_read. +* Sign/Abs type for reg_ commands? +* Number layout for reg_read. +* Show Record / Array / List type of SDOs. +* Limit bandwidth of state machine datagram. * Read alias from register 0x0012 instead of SII. * Finish library implementation. * Re-work EoE code. diff --git a/master/cdev.c b/master/cdev.c index 9608aeb9..8fbd265c 100644 --- a/master/cdev.c +++ b/master/cdev.c @@ -173,6 +173,7 @@ int ec_cdev_ioctl_master( if (down_interruptible(&master->device_sem)) return -EINTR; + if (master->main_device.dev) { memcpy(data.devices[0].address, master->main_device.dev->dev_addr, ETH_ALEN); @@ -194,8 +195,16 @@ int ec_cdev_ioctl_master( data.devices[1].link_state = master->backup_device.link_state ? 1 : 0; data.devices[1].tx_count = master->backup_device.tx_count; data.devices[1].rx_count = master->backup_device.rx_count; + up(&master->device_sem); + data.app_time = master->app_time; + data.ref_clock = EC_READ_U16(master->sync_datagram.address); + if (data.ref_clock < 0xffff) { + // ref_clock address is station_address, output ring position + data.ref_clock--; + } + if (copy_to_user((void __user *) arg, &data, sizeof(data))) return -EFAULT; diff --git a/master/ioctl.h b/master/ioctl.h index 19abfd29..fb3d3171 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -136,6 +136,8 @@ typedef struct { uint32_t tx_count; uint32_t rx_count; } devices[2]; + uint64_t app_time; + uint16_t ref_clock; } ec_ioctl_master_t; /*****************************************************************************/ diff --git a/master/master.c b/master/master.c index 297d8e7f..e0a8384f 100644 --- a/master/master.c +++ b/master/master.c @@ -622,6 +622,8 @@ void ec_master_leave_operation_phase(ec_master_t *master } #endif + master->app_time = 0ULL; + if (ec_master_thread_start(master, ec_master_idle_thread, "EtherCAT-IDLE")) EC_WARN("Failed to restart master thread!\n"); diff --git a/tool/CommandMaster.cpp b/tool/CommandMaster.cpp index f02c6bc8..636b4ae5 100644 --- a/tool/CommandMaster.cpp +++ b/tool/CommandMaster.cpp @@ -33,6 +33,8 @@ using namespace std; #include "CommandMaster.h" +#define MAX_TIME_STR_SIZE 50 + /*****************************************************************************/ CommandMaster::CommandMaster(): @@ -65,6 +67,9 @@ void CommandMaster::execute(MasterDevice &m, const StringVector &args) ec_ioctl_master_t data; stringstream err; unsigned int i; + time_t epoch; + char time_str[MAX_TIME_STR_SIZE + 1]; + size_t time_str_size; if (args.size()) { err << "'" << getName() << "' takes no arguments!"; @@ -86,10 +91,11 @@ void CommandMaster::execute(MasterDevice &m, const StringVector &args) } cout << endl - << " Slaves: " << data.slave_count << endl; + << " Slaves: " << data.slave_count << endl + << " Ethernet devices:" << endl; for (i = 0; i < 2; i++) { - cout << " Device" << i << ": "; + cout << " " << (i == 0 ? "Main" : "Backup") << ": "; if (data.devices[i].address[0] == 0x00 && data.devices[i].address[1] == 0x00 && data.devices[i].address[2] == 0x00 @@ -107,12 +113,29 @@ void CommandMaster::execute(MasterDevice &m, const StringVector &args) << setw(2) << (unsigned int) data.devices[i].address[5] << " (" << (data.devices[i].attached ? "attached" : "waiting...") << ")" << endl << dec - << " Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl - << " Tx count: " << data.devices[i].tx_count << endl - << " Rx count: " << data.devices[i].rx_count; + << " Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl + << " Tx count: " << data.devices[i].tx_count << endl + << " Rx count: " << data.devices[i].rx_count; } cout << endl; } + + cout << " Distributed clocks:" << endl + << " Reference clock: "; + if (data.ref_clock != 0xffff) { + cout << "Slave " << dec << data.ref_clock; + } else { + cout << "None"; + } + cout << endl + << " Application time: " << data.app_time << endl + << " "; + + epoch = data.app_time / 1000000000 + 946684800ULL; + time_str_size = strftime(time_str, MAX_TIME_STR_SIZE, + "%Y-%m-%d %H:%M:%S", gmtime(&epoch)); + cout << string(time_str, time_str_size) << "." + << setfill('0') << setw(9) << data.app_time % 1000000000 << endl; } /*****************************************************************************/