Skip to content
Snippets Groups Projects
Commit 1db810c8 authored by Harvey Leicester's avatar Harvey Leicester Committed by Adam Wujek
Browse files

[FEATURE: #333] userspace/tools/spll_conf: add tool for runtime config of spll pi gain terms

parent 38bcc0fd
Branches
Tags
No related merge requests found
......@@ -127,6 +127,9 @@ int rts_debug_command(int param, int value);
/* Set offset between PPS-in and PPS-out when in GM mode */
int rts_gm_pps_in_out_offset_command(int offset_ps);
/* Set spll pi gain terms */
int rts_set_pi_gain(int loop, int kp, int ki);
#ifdef RTIPC_EXPORT_STRUCTURES
static struct minipc_pd rtipc_rts_get_state_struct = {
......@@ -205,6 +208,17 @@ static struct minipc_pd rtipc_rts_set_pps_in_out_offset_struct = {
},
};
static struct minipc_pd rtipc_rts_set_pi_gain_struct = {
.name = "iiii",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END
},
};
#endif
#endif
......@@ -62,6 +62,8 @@
#define SPLL_STATS_VER 5
#define SPLL_STATS_MAGIC 0x5b1157a7
#define SPLL_LOOP_HELPER -1
#define SPLL_LOOP_MAIN 0
struct spll_build_id {
char commit_id[32];
......
......@@ -155,6 +155,19 @@ int rts_gm_pps_in_out_offset_command(int offset_ps)
return rval;
}
int rts_set_pi_gain(int loop, int kp, int ki)
{
int rval;
int ret = minipc_call(client, RTS_TIMEOUT,
&rtipc_rts_set_pi_gain_struct, &rval,
loop, kp, ki);
if (ret < 0)
return ret;
return rval;
}
int rts_connect(char *logfilename)
{
static FILE *f;
......
......@@ -31,3 +31,4 @@ radiusvlan
ioctl
asix_ioctl
wrsw_hal_conf
spll_conf
......@@ -18,6 +18,7 @@ TOOLS += asix_ioctl
TOOLS += utc_leap_test
TOOLS += radiusvlan
TOOLS += wrsw_hal_conf
TOOLS += spll_conf
PPSI_CONFIG = ../ppsi/include/generated/autoconf.h
WR_INSTALL_ROOT ?= /usr/lib/white-rabbit
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2024 CERN (www.cern.ch)
* Author: Harvey Leicester <harvey.leicester@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libwr/wrs-msg.h>
#include <libwr/softpll_export.h>
#include <rt_ipc.h>
static int loop = SPLL_LOOP_MAIN;
static int loop_setting[2] = {0};
static char *prgName;
static void show_help(void)
{
printf("Tool to set spll pi loop parameters.\n"
"Usage: spll_conf <main/helper> <kp> <ki>\n"
"where:\n"
"\t<main/helper> pll to update\n"
"\t<kp> proportional gain\n"
"\t<ki> integral gain\n"
"\n"
"Version: " __GIT_VER__ " compiled by " __GIT_USR__ " on " __DATE__ ", " __TIME__ "\n"
);
}
static void spll_pi_parse_cmdline(int argc, char *argv[])
{
int i = 0;
if (argc > 1) {
if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) {
show_help();
exit(0);
}
}
if (argc != 4) {
fprintf(stderr, "Invalid number of arguments. Try %s -h\n", prgName);
exit(-1);
}
if (!strcmp(argv[1], "main")) {
loop = SPLL_LOOP_MAIN;
} else if (!strcmp(argv[1], "helper")) {
loop = SPLL_LOOP_HELPER;
} else {
fprintf(stderr,"Unrecognized loop option %s. Try %s -h\n",
argv[1], prgName);
exit(-1);
}
for(i = 2; i < argc; i++) {
loop_setting[i - 2] = atoi(argv[i]);
}
}
int set_spll_pi_gain(int loop, int kp, int ki)
{
static int connected = 0;
struct rts_pll_state pstate;
if (!connected) {
if (rts_connect(NULL) < 0)
return -1;
connected = 1;
}
if (rts_get_state(&pstate)<0 )
return -1;
pr_info("setting %s pll, parameters: kp=%i ki=%i\n",
(loop == SPLL_LOOP_MAIN) ? "main" : "helper", kp, ki);
if (rts_set_pi_gain(loop, kp, ki) < 0) {
return -1;
}
return 0;
}
int main(int argc, char *argv[])
{
int ret;
wrs_msg_init(argc, argv, LOG_DAEMON);
prgName = argv[0];
spll_pi_parse_cmdline(argc, argv);
ret = set_spll_pi_gain(loop, loop_setting[0], loop_setting[1]);
return ret;
}
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