phc2sys: add option to set slave-master time offset.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This commit is contained in:
		
							parent
							
								
									a373805b6d
								
							
						
					
					
						commit
						1a83619b17
					
				@ -24,6 +24,8 @@ phc2sys \- synchronize two clocks
 | 
				
			|||||||
.BI \-R " update-rate"
 | 
					.BI \-R " update-rate"
 | 
				
			||||||
] [
 | 
					] [
 | 
				
			||||||
.BI \-N " clock-readings"
 | 
					.BI \-N " clock-readings"
 | 
				
			||||||
 | 
					] [
 | 
				
			||||||
 | 
					.BI \-O " offset"
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.SH DESCRIPTION
 | 
					.SH DESCRIPTION
 | 
				
			||||||
@ -84,6 +86,10 @@ the fastest reading is used to update the slave clock, this is useful to
 | 
				
			|||||||
minimize the error caused by random delays in scheduling and bus utilization.
 | 
					minimize the error caused by random delays in scheduling and bus utilization.
 | 
				
			||||||
The default is 5.
 | 
					The default is 5.
 | 
				
			||||||
.TP
 | 
					.TP
 | 
				
			||||||
 | 
					.BI \-O " offset"
 | 
				
			||||||
 | 
					Specify the offset between the slave and master times in seconds.
 | 
				
			||||||
 | 
					The default is 0 seconds.
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
.BI \-h
 | 
					.BI \-h
 | 
				
			||||||
Display a help message.
 | 
					Display a help message.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								phc2sys.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								phc2sys.c
									
									
									
									
									
								
							@ -241,6 +241,7 @@ static void usage(char *progname)
 | 
				
			|||||||
		" -I [ki]        integration constant (0.3)\n"
 | 
							" -I [ki]        integration constant (0.3)\n"
 | 
				
			||||||
		" -R [rate]      slave clock update rate in HZ (1)\n"
 | 
							" -R [rate]      slave clock update rate in HZ (1)\n"
 | 
				
			||||||
		" -N [num]       number of master clock readings per update (5)\n"
 | 
							" -N [num]       number of master clock readings per update (5)\n"
 | 
				
			||||||
 | 
							" -O [offset]    slave-master time offset (0)\n"
 | 
				
			||||||
		" -h             prints this message and exits\n"
 | 
							" -h             prints this message and exits\n"
 | 
				
			||||||
		"\n",
 | 
							"\n",
 | 
				
			||||||
		progname);
 | 
							progname);
 | 
				
			||||||
@ -253,12 +254,12 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
	clockid_t src = CLOCK_INVALID, dst = CLOCK_REALTIME;
 | 
						clockid_t src = CLOCK_INVALID, dst = CLOCK_REALTIME;
 | 
				
			||||||
	uint64_t phc_ts;
 | 
						uint64_t phc_ts;
 | 
				
			||||||
	int64_t phc_offset;
 | 
						int64_t phc_offset;
 | 
				
			||||||
	int c, phc_readings = 5, phc_rate = 1;
 | 
						int c, phc_readings = 5, phc_rate = 1, sync_offset = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Process the command line arguments. */
 | 
						/* Process the command line arguments. */
 | 
				
			||||||
	progname = strrchr(argv[0], '/');
 | 
						progname = strrchr(argv[0], '/');
 | 
				
			||||||
	progname = progname ? 1+progname : argv[0];
 | 
						progname = progname ? 1+progname : argv[0];
 | 
				
			||||||
	while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:i:"))) {
 | 
						while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:O:i:"))) {
 | 
				
			||||||
		switch (c) {
 | 
							switch (c) {
 | 
				
			||||||
		case 'c':
 | 
							case 'c':
 | 
				
			||||||
			dst = clock_open(optarg);
 | 
								dst = clock_open(optarg);
 | 
				
			||||||
@ -281,6 +282,9 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		case 'N':
 | 
							case 'N':
 | 
				
			||||||
			phc_readings = atoi(optarg);
 | 
								phc_readings = atoi(optarg);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case 'O':
 | 
				
			||||||
 | 
								sync_offset = atoi(optarg);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		case 'i':
 | 
							case 'i':
 | 
				
			||||||
			ethdev = optarg;
 | 
								ethdev = optarg;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@ -311,6 +315,7 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		struct timespec now;
 | 
							struct timespec now;
 | 
				
			||||||
		if (clock_gettime(src, &now))
 | 
							if (clock_gettime(src, &now))
 | 
				
			||||||
			perror("clock_gettime");
 | 
								perror("clock_gettime");
 | 
				
			||||||
 | 
							now.tv_sec += sync_offset;
 | 
				
			||||||
		if (clock_settime(dst, &now))
 | 
							if (clock_settime(dst, &now))
 | 
				
			||||||
			perror("clock_settime");
 | 
								perror("clock_settime");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -323,6 +328,7 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		if (!read_phc(src, dst, phc_readings, &phc_offset, &phc_ts)) {
 | 
							if (!read_phc(src, dst, phc_readings, &phc_offset, &phc_ts)) {
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							phc_offset -= sync_offset * NS_PER_SEC;
 | 
				
			||||||
		do_servo(&servo, dst, phc_offset, phc_ts, kp, ki);
 | 
							do_servo(&servo, dst, phc_offset, phc_ts, kp, ki);
 | 
				
			||||||
		show_servo(stdout, "phc", phc_offset, phc_ts);
 | 
							show_servo(stdout, "phc", phc_offset, phc_ts);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user