cmd_time.c 831 Bytes
Newer Older
1
/*  Command: time
2
    Arguments:
3 4 5
    	set UTC NSEC - sets time
    	raw - dumps raw time
    	<none> - dumps pretty time
6

7 8 9 10 11 12
    Description: (re)starts/stops the PTP session. */

#include <errno.h>
#include <string.h>

#include "shell.h"
13
#include "util.h"
14 15 16 17 18
#include "wrc_ptp.h"
#include "pps_gen.h"

int cmd_time(const char *args[])
{
19 20
	uint64_t sec;
	uint32_t nsec;
21

22
	pps_gen_get_time(&sec, &nsec);
23

24 25 26 27
	if (args[2] && !strcasecmp(args[0], "set")) {
		if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) {
			pps_gen_set_time((uint64_t) atoi(args[1]),
					 atoi(args[2]));
28 29 30
			return 0;
		} else
			return -EBUSY;
31 32 33
	} else if (args[0] && !strcasecmp(args[0], "raw")) {
		mprintf("%d %d\n", (uint32_t) sec, nsec);
		return 0;
34 35
	}

36
	mprintf("%s +%d nanoseconds.\n", format_time(sec), nsec);	/* fixme: clock freq is not always 125 MHz */
37 38

	return 0;
39
}