Commit 122caf5f authored by Adam Wujek's avatar Adam Wujek

shell: add cmd_leapsec

Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent fa5f9f09
......@@ -372,6 +372,14 @@ config CMD_PPS
This enables pps command, which can be used to force PPS output
all the time for all clock classes.
config CMD_LEAPSEC
depends on WR_NODE
boolean "Include command to control leapsecond value"
default n
help
This enables leapsec command, which can be used to adjust leap seconds
value.
#
# This is a set of configuration options that should not be changed by
# normal users. If the "developer" menu is used, the binary is tainted.
......
......@@ -1801,6 +1801,12 @@ tools used to build and run it, you can write to our mailing list
\code{ip set <ip>} & reports or sets the IPv4 address of the WRPC (only
available if \texttt{CONFIG\_IP} is set at build time \\
\code{leapsec} & \\
\code{leapsec get} & get number of leap seconds from PTP and from the system \\
\code{leapsec set <num>} & get number of leap seconds for PTP. This settings
make sense only for GM mode \\
\code{ltest} & \\
\code{ltest fake <nsecs>} & fakes delay to trigger latency failures (for
testing). \\
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2021 CERN (www.cern.ch)
* Author: Adam Wujek
*
* Released according to the GNU GPL, version 2 or any later version.
*/
/* Command: leapsec
Arguments:
set SEC - sets leap seconds value
<none> - dumps leap seconds value
Description: set/read leap seconds value used by PTP */
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <wrc.h>
#include <wrpc.h>
#include "shell.h"
#include "util.h"
#include "wrc_ptp.h"
/* Setting leap second makes sense only for GM. For other modes leap seconds
* counter is received from a master (slave) or is hardcoded in PPSI (master).
* In master it is hardcoded to PP_DEFAULT_UTC_OFFSET, since master mode does
* not have timescale set. */
static int cmd_leapsec(const char *args[])
{
int ptp_offset, system_offset;
if (args[1] && !strcasecmp(args[0], "set")) {
wrc_ptp_set_leapsec(atoi(args[1]));
} else if (args[0] && strcasecmp(args[0], "get")) {
/* other param given, but not "get" */
return -EINVAL;
}
wrc_ptp_get_leapsec(&ptp_offset, &system_offset);
pp_printf("leap seconds: ptp %d, system %d\n", ptp_offset, system_offset);
return 0;
}
DEFINE_WRC_COMMAND(leapsec) = {
.name = "leapsec",
.exec = cmd_leapsec,
};
......@@ -47,6 +47,13 @@
#define HAS_CMD_PPS 0
#endif
#ifdef CONFIG_CMD_LEAPSEC
#define HAS_CMD_LEAPSEC 1
#else
#define HAS_CMD_LEAPSEC 0
#endif
static char cmd_buf[SH_MAX_LINE_LEN + 1];
static int cmd_pos = 0, cmd_len = 0;
static int state = SH_PROMPT;
......@@ -380,4 +387,6 @@ void shell_register_commands(void)
REGISTER_WRC_COMMAND(vlan);
if (HAS_CMD_PPS)
REGISTER_WRC_COMMAND(pps);
if (HAS_CMD_LEAPSEC)
REGISTER_WRC_COMMAND(leapsec);
}
......@@ -26,5 +26,6 @@ obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o
obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o
obj-$(CONFIG_CMD_LL) += shell/cmd_ll.o
obj-$(CONFIG_CMD_PPS) += shell/cmd_pps.o
obj-$(CONFIG_CMD_LEAPSEC) += shell/cmd_leapsec.o
obj-$(CONFIG_FLASH_INIT) += shell/cmd_init.o
obj-$(CONFIG_VLAN) += shell/cmd_vlan.o
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment