diff --git a/include/villas/nodes/smu.hpp b/include/villas/nodes/smu.hpp index d8b0959ed..6b6e792c0 100644 --- a/include/villas/nodes/smu.hpp +++ b/include/villas/nodes/smu.hpp @@ -152,7 +152,10 @@ typedef struct { float k[SMU_NCH]; } __attribute__((__packed__)) smu_mcsk_t; - +typedef struct { + int64_t tv_sec; + long tv_nsec; +} __attribute__((__packed__)) timespec64_t; /** * @brief IOCTL definitions * @@ -165,8 +168,10 @@ typedef struct { #define SMU_IOC_RESET _IO (SMU_IOC_MAGIC, 1) #define SMU_IOC_START _IO (SMU_IOC_MAGIC, 2) #define SMU_IOC_STOP _IO (SMU_IOC_MAGIC, 3) -#define SMU_IOC_SET_CONF _IOW(SMU_IOC_MAGIC, 4, smu_conf_t*) -#define SMU_IOC_GET_CONF _IOR(SMU_IOC_MAGIC, 5, smu_conf_t*) +#define SMU_IOC_GET_TIME _IOR(SMU_IOC_MAGIC, 4, timespec64_t*) +#define SMU_IOC_SET_CONF _IOW(SMU_IOC_MAGIC, 5, smu_conf_t*) +#define SMU_IOC_GET_CONF _IOR(SMU_IOC_MAGIC, 6, smu_conf_t*) + /** * @brief Signal definitions @@ -190,7 +195,7 @@ private: daq_sync_t sync; smu_daq_t daq_cfg; Dumper dumpers[SMU_NCH]; - int fd; + static inline int fd; uint8_t* shared_mem; uint32_t shared_mem_pos; uint32_t shared_mem_inc; @@ -202,6 +207,9 @@ private: static inline std::atomic mem_pos = 0; static inline pthread_mutex_t mutex; static inline pthread_cond_t cv; + static inline timespec64_t sync_signal_mem_pos = {0}; + static inline timespec sample_time ={0}; + static inline int sec_cnt = 0; protected: virtual diff --git a/lib/nodes/smu.cpp b/lib/nodes/smu.cpp index af3f1a23d..1aa9ad30c 100644 --- a/lib/nodes/smu.cpp +++ b/lib/nodes/smu.cpp @@ -241,9 +241,15 @@ int SMUNode::stop() void SMUNode::sync_signal(int, siginfo_t *info, void*) { - //mem_pos = (info->si_value.sival_int); - /* Signal uldaq_read() about new data */ - //pthread_cond_signal(&u->in.cv); + + ioctl(fd, SMU_IOC_GET_TIME,&sync_signal_mem_pos); + sample_time.tv_nsec = sync_signal_mem_pos.tv_nsec; + sample_time.tv_sec = sync_signal_mem_pos.tv_sec; + + if (sample_time.tv_nsec > 500000000) + sample_time.tv_sec += 1; + sec_cnt = 0; + //std::cout << "pps event"; } void SMUNode::data_available_signal(int, siginfo_t *info, void*) @@ -258,8 +264,8 @@ void SMUNode::data_available_signal(int, siginfo_t *info, void*) int SMUNode::_read(struct Sample *smps[], unsigned cnt) { struct timespec ts; - ts.tv_sec = time(nullptr); - ts.tv_nsec = 0; + ts.tv_sec = sample_time.tv_sec; + ts.tv_nsec = sec_cnt * 1e9 / fps; pthread_mutex_lock(&mutex); @@ -271,6 +277,7 @@ int SMUNode::_read(struct Sample *smps[], unsigned cnt) for (unsigned j = 0; j < cnt; j++) { struct Sample *t = smps[j]; + ts.tv_nsec += 1000 * 1000 * sample_rate; for (unsigned i = 0; i < 8; i++) { int16_t data = p[mem_pos_local].ch[i]; @@ -280,6 +287,7 @@ int SMUNode::_read(struct Sample *smps[], unsigned cnt) } mem_pos_local++; + ts.tv_nsec = 0; t->flags = (int) SampleFlags::HAS_TS_ORIGIN | (int) SampleFlags::HAS_DATA | (int) SampleFlags::HAS_SEQUENCE; t->ts.origin = ts;