Commit cc101d87 authored by Adam Wujek's avatar Adam Wujek

tools: introduce ppsi_conf command for realtime reconfiguration

So far support:
--priority1
--priority2
--enable/disable phase tracking
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 26993418
...@@ -63,7 +63,7 @@ static inline wrs_arch_data_t *WRS_ARCH_G(struct pp_globals *ppg) ...@@ -63,7 +63,7 @@ static inline wrs_arch_data_t *WRS_ARCH_G(struct pp_globals *ppg)
extern void wrs_main_loop(struct pp_globals *ppg); extern void wrs_main_loop(struct pp_globals *ppg);
extern void wrs_init_ipcserver(struct minipc_ch *ppsi_ch); extern void wrs_init_ipcserver(struct pp_globals *ppg, struct minipc_ch *ppsi_ch);
/* wrs-calibration.c */ /* wrs-calibration.c */
int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, TimeInterval *scaledBitSlide, int wrs_read_calibration_data(struct pp_instance *ppi,int32_t *clock_period, TimeInterval *scaledBitSlide,
......
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
#define PPSIEXP_COMMAND_WR_TRACKING 1 #define PPSIEXP_COMMAND_WR_TRACKING 1
#define PPSIEXP_COMMAND_L1SYNC_TRACKING 2 #define PPSIEXP_COMMAND_L1SYNC_TRACKING 2
#define PPSIEXP_RET_OK 0
#define PPSIEXP_RET_ERROR_CMD 1
#define PPSIEXP_RET_ERROR_VAL 2
/* Commands for ppsiexp_update_param_cmd */
#define PPSIEXP_PARAM_PRIORITY1_CMD 1
#define PPSIEXP_PARAM_PRIORITY2_CMD 2
/* Export structures, shared by server and client for argument matching */ /* Export structures, shared by server and client for argument matching */
#ifdef PPSI_EXPORT_STRUCTURES #ifdef PPSI_EXPORT_STRUCTURES
...@@ -20,6 +28,16 @@ struct minipc_pd __rpcdef_cmd = { ...@@ -20,6 +28,16 @@ struct minipc_pd __rpcdef_cmd = {
}, },
}; };
#endif /* PTP_EXPORT_STRUCTURES */ struct minipc_pd ppsiexp_update_param_cmd = {
.name = "params",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* Command/parameter */
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), /* New value */
MINIPC_ARG_END,
},
};
#endif /* PPSI_EXPORT_STRUCTURES */
#endif /* __PPSI_EXPORTS_H */ #endif /* __PPSI_EXPORTS_H */
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#define PPSI_EXPORT_STRUCTURES #define PPSI_EXPORT_STRUCTURES
#include <ppsi_exports.h> #include <ppsi_exports.h>
static struct pp_globals *ppg_local;
/* Execute command coming ipc */ /* Execute command coming ipc */
static int wrsipc_cmd(int cmd, int value) static int wrsipc_cmd(int cmd, int value)
{ {
...@@ -39,10 +43,60 @@ static int export_cmd(const struct minipc_pd *pd, ...@@ -39,10 +43,60 @@ static int export_cmd(const struct minipc_pd *pd,
return 0; return 0;
} }
static int in_range(int val, int min, int max)
{
if (val < min || val > max)
return 0;
return 1;
}
static int update_param_cmd(const struct minipc_pd *pd, uint32_t *args,
void *ret)
{
int rval = PPSIEXP_RET_OK;
int param_type = args[0];
int param_val = args[1];
switch (param_type) {
case PPSIEXP_PARAM_PRIORITY1_CMD:
printf("%s: cmd %d (PPSIEXP_PARAM_PRIORITY1_CMD) value %d\n",
__func__, param_type, param_val);
if (!in_range(param_val, PP_MIN_PRIORITY1, PP_MAX_PRIORITY1)) {
rval = PPSIEXP_RET_ERROR_VAL;
break;
}
ppg_local->rt_opts->priority1 = param_val;
bmc_apply_configured_device_attributes(ppg_local);
break;
case PPSIEXP_PARAM_PRIORITY2_CMD:
printf("%s: cmd %d (PPSIEXP_PARAM_PRIORITY2_CMD) value %d\n",
__func__, param_type, param_val);
if (!in_range(param_val, PP_MIN_PRIORITY2, PP_MAX_PRIORITY2)) {
rval = PPSIEXP_RET_ERROR_VAL;
break;
}
ppg_local->rt_opts->priority2 = param_val;
bmc_apply_configured_device_attributes(ppg_local);
break;
default:
printf("%s: not found cmd %d value %d\n", __func__, param_type,
param_val);
rval = PPSIEXP_RET_ERROR_CMD;
break;
}
*(int *)ret = rval;
return 0;
}
/* To be called at startup, right after the creation of server channel */ /* To be called at startup, right after the creation of server channel */
void wrs_init_ipcserver(struct minipc_ch *ppsi_ch) void wrs_init_ipcserver(struct pp_globals *ppg, struct minipc_ch *ppsi_ch)
{ {
ppg_local = ppg;
__rpcdef_cmd.f = export_cmd; __rpcdef_cmd.f = export_cmd;
ppsiexp_update_param_cmd.f = update_param_cmd;
minipc_export(ppsi_ch, &__rpcdef_cmd); minipc_export(ppsi_ch, &__rpcdef_cmd);
minipc_export(ppsi_ch, &ppsiexp_update_param_cmd);
} }
...@@ -206,7 +206,6 @@ int main(int argc, char **argv) ...@@ -206,7 +206,6 @@ int main(int argc, char **argv)
pp_printf("ppsi: could not create minipc server"); pp_printf("ppsi: could not create minipc server");
exit(1); exit(1);
} }
wrs_init_ipcserver(ppsi_ch);
ppsi_head = wrs_shm_get(wrs_shm_ptp, "ppsi", ppsi_head = wrs_shm_get(wrs_shm_ptp, "ppsi",
WRS_SHM_WRITE | WRS_SHM_LOCKED); WRS_SHM_WRITE | WRS_SHM_LOCKED);
...@@ -448,6 +447,8 @@ int main(int argc, char **argv) ...@@ -448,6 +447,8 @@ int main(int argc, char **argv)
seed = (unsigned long) atoi(getenv("PPSI_DROP_SEED")); seed = (unsigned long) atoi(getenv("PPSI_DROP_SEED"));
ppsi_drop_init(ppg, seed); ppsi_drop_init(ppg, seed);
wrs_init_ipcserver(ppg, ppsi_ch);
/* release lock from wrs_shm_get */ /* release lock from wrs_shm_get */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END); wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END);
......
ptpdump adjrate
adjtime adjtime
jmptime
chktime chktime
adjrate jmptime
pps-out
monotonicClock monotonicClock
ppsi_conf
pps-out
ptpdump
...@@ -12,7 +12,14 @@ OBJDUMP = $(CROSS_COMPILE)objdump ...@@ -12,7 +12,14 @@ OBJDUMP = $(CROSS_COMPILE)objdump
include ../.config include ../.config
CFLAGS = -Wall -ggdb -I../include -I../arch-$(CONFIG_ARCH)/include CFLAGS = -Wall -ggdb -I../include -I../arch-$(CONFIG_ARCH)/include
PROGS = ptpdump adjtime jmptime chktime adjrate monotonicClock PROGS = \
adjrate \
adjtime \
chktime \
monotonicClock \
ppsi_conf \
ptpdump \
LDFLAGS += -lrt LDFLAGS += -lrt
all: $(PROGS) all: $(PROGS)
...@@ -28,6 +35,9 @@ $(PROGS): $(wildcard *.h) $(wildcard ../include/ppsi/*.h) ...@@ -28,6 +35,9 @@ $(PROGS): $(wildcard *.h) $(wildcard ../include/ppsi/*.h)
ptpdump: dump-main.o dump-funcs.o ptpdump: dump-main.o dump-funcs.o
$(CC) $(LDFLAGS) dump-main.o dump-funcs.o -o $@ $(CC) $(LDFLAGS) dump-main.o dump-funcs.o -o $@
ppsi_conf: CFLAGS+=-I../arch-wrs/mini-rpc -L../arch-wrs/mini-rpc
ppsi_conf: LDFLAGS+=-lminipc
clean: clean:
rm -f $(PROGS) *.o *~ rm -f $(PROGS) *.o *~
/*
* Copyright (C) 2023 CERN (www.cern.ch)
* Author: Adam Wujek
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <ppsi/ppsi.h>
#include <minipc.h>
#define PPSI_EXPORT_STRUCTURES
#include "ppsi_exports.h"
#define MINIPC_TIMEOUT 5000
static int verbose = 0;
static struct minipc_ch *ptp_ch;
enum input_arg {
arg_help = 'Z' + 1, /* avoid conflicts with short options */
arg_prio1,
arg_prio2,
arg_tracking,
arg_verbose,
};
static struct option long_opts[] = {
{"help", no_argument, NULL, arg_help},
{"prio1", required_argument, NULL, arg_prio1},
{"priority1", required_argument, NULL, arg_prio1},
{"prio2", required_argument, NULL, arg_prio2},
{"priority2", required_argument, NULL, arg_prio2},
{"tracking", required_argument, NULL, arg_tracking},
{"verbose", optional_argument, NULL, arg_verbose},
{NULL, 0, NULL, 0}
};
void help(char *prgname)
{
fprintf(stderr, "%s: Use: \"%s [-v] [-h] [option]\n",
prgname, prgname);
fprintf(stderr,
"The program has the following options:\n"
" -h|--help - print help\n"
" -v|--verbose - verbose output\n"
"Global parameters:\n"
" --prio1=<num>\n"
" --priority1=<num> - set priority 1 to <num>\n"
" --prio2=<num>\n"
" --priority2=<num> - set priority 2 to <num>\n"
" --tracking=<on|off|enable|disable|1|0>\n"
" - enable/disable tracking in servo\n"
);
exit(1);
}
void ppsi_connect_minipc(void)
{
if (ptp_ch) {
/* close minipc, if connected before */
minipc_close(ptp_ch);
}
ptp_ch = minipc_client_create("ptpd", 0);
if (!ptp_ch) {
fprintf(stderr, "Can't establish WRIPC connection to the PTP "
"daemon!\n");
exit(1);
}
}
void init_shm(void)
{
ppsi_connect_minipc();
}
static void enable_disable_tracking(int onoff) {
int rval;
printf("%s: onoff %d\n", __func__, onoff);
minipc_call(ptp_ch, MINIPC_TIMEOUT, &__rpcdef_cmd, &rval, 1, onoff);
}
static int ppsi_set_param(int param, int val) {
int rval = 0;
printf("%s: set param %d val %d\n", __func__, param, val);
minipc_call(ptp_ch, MINIPC_TIMEOUT, &ppsiexp_update_param_cmd, &rval,
param, val);
return rval;
}
int main(int argc, char *argv[])
{
int opt;
int tmp;
int ret;
/* If no params print help */
if (argc == 1)
help(argv[0]);
while ((opt = getopt_long(argc, argv, "vh", long_opts, NULL)) != -1) {
if (opt == 'h' || opt == arg_help )
help(argv[0]);
if (opt == '?') {
/* Unrecognized option, exit */
exit(1);
}
if (opt == 'v') {
verbose = 1;
printf("Enable verbose mode\n");
}
if (opt == arg_verbose) {
if (!strcmp(optarg, "off") || !strcmp(optarg, "0")) {
verbose = 0;
printf("Enable verbose mode\n");
} else {
verbose = 1;
printf("Disable verbose mode\n");
}
}
}
init_shm();
/* Reset position of argument for getopt_long */
optind = 0;
while ((opt = getopt_long(argc, argv, "vh", long_opts, NULL)) != -1) {
switch (opt) {
case arg_prio1:
tmp = atoi(optarg);
if (verbose)
printf("Setting priority1 to %d\n", tmp);
ret = ppsi_set_param(PPSIEXP_PARAM_PRIORITY1_CMD, tmp);
if (ret) {
fprintf(stderr, "Error setting priority1 to "
"%d\n", tmp);
exit (1);
}
break;
case arg_prio2:
tmp = atoi(optarg);
if (verbose)
printf("Setting priority2 to %d\n", tmp);
ret = ppsi_set_param(PPSIEXP_PARAM_PRIORITY2_CMD, tmp);
if (ret) {
fprintf(stderr, "Error setting priority2 to "
"%d\n", tmp);
exit (1);
}
break;
case arg_tracking:
{
int tracking;
if (!strcmp(optarg, "on")
|| !strcmp(optarg, "enable")
|| !strcmp(optarg, "1")
) {
tracking = 1;
} else if (!strcmp(optarg, "off")
|| !strcmp(optarg, "disable")
|| !strcmp(optarg, "0")
) {
tracking = 0;
} else {
fprintf(stderr, "Unknown value (%s) for"
" tracking\n", optarg);
exit (1);
}
if (verbose)
printf("%s tracking\n",
tracking ? "Enable" : "Disable");
enable_disable_tracking(tracking);
break;
}
default:
break;
}
}
return 0;
}
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