From b9da13e102b532f55366b1ee0da76a84c251fe44 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 27 May 2021 08:33:58 +0100 Subject: [PATCH] Add time of accession to bus mastership to the shm. Useful for deciding how long to let the clock settle before using it. --- nqptp-shm-structures.h | 3 ++- nqptp.c | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h index 3e3f0ca..9704644 100644 --- a/nqptp-shm-structures.h +++ b/nqptp-shm-structures.h @@ -22,7 +22,7 @@ #define STORAGE_ID "/nqptp" #define MAX_CLOCKS 32 -#define NQPTP_SHM_STRUCTURES_VERSION 4 +#define NQPTP_SHM_STRUCTURES_VERSION 5 #define NQPTP_CONTROL_PORT 9000 // the control port will accept a UDP packet with the first letter being: @@ -43,6 +43,7 @@ struct shm_structure { char master_clock_ip[64]; // where it's coming from uint64_t local_time; // the time when the offset was calculated uint64_t local_to_master_time_offset; // add this to the local time to get master clock time + uint64_t master_clock_start_time; // this is when the master clock became master }; #endif diff --git a/nqptp.c b/nqptp.c index 457514e..a2e0960 100644 --- a/nqptp.c +++ b/nqptp.c @@ -86,7 +86,10 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t int rc = pthread_mutex_lock(&shared_memory->shm_mutex); if (rc != 0) warn("Can't acquire mutex to update master clock!"); - shared_memory->master_clock_id = master_clock_id; + if (shared_memory->master_clock_id != master_clock_id) { + shared_memory->master_clock_id = master_clock_id; + shared_memory->master_clock_start_time = get_time_now(); + } if (ip != NULL) strncpy((char *)&shared_memory->master_clock_ip, ip, FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1); @@ -136,7 +139,7 @@ int main(int argc, char **argv) { if (argv[i][0] == '-') { if (strcmp(argv[i] + 1, "V") == 0) { #ifdef CONFIG_USE_GIT_VERSION_STRING - if (git_version_string[0] != '\0') + if (git_version_string[0] != '\0') fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string, NQPTP_SHM_STRUCTURES_VERSION); else -- 2.47.2