cmd_time.c 817 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*  Command: time
    Arguments: 
    	set UTC NSEC - sets time
    	raw - dumps raw time
    	<none> - dumps pretty time
    
    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 19
#include "wrc_ptp.h"
#include "pps_gen.h"


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

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

38
	mprintf("%s +%d nanoseconds.\n", format_time(sec), nsec); /* fixme: clock freq is not always 125 MHz */
39 40 41
	
	return 0;	
}