Commit 0e094a73 authored by José López Jiménez's avatar José López Jiménez

wrs_spll_tune: new tool to modify the kp/ki constants in runtime from userspace

parent 10bef13d
No preview for this file type
......@@ -120,6 +120,10 @@ int rts_enable_ptracker(int channel, int enable);
/* Enabled/disables phase tracking on a particular port */
int rts_debug_command(int param, int value);
int rts_spll_get_constants(int loop, int param, int value);
int rts_spll_set_constants(int loop, int param, int value);
#ifdef RTIPC_EXPORT_STRUCTURES
static struct minipc_pd rtipc_rts_get_state_struct = {
......@@ -179,6 +183,30 @@ static struct minipc_pd rtipc_rts_debug_command_struct = {
},
};
static struct minipc_pd rtipc_rts_spll_set_constants_struct = {
.name = "gggg",
.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
},
};
static struct minipc_pd rtipc_rts_spll_get_constants_struct = {
.name = "hhhh",
.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
......@@ -125,6 +125,30 @@ int rts_debug_command(int command, int value)
return rval;
}
int rts_spll_set_constants(int loop, int param, int value)
{
int rval;
int ret = minipc_call(client, RTS_TIMEOUT,
&rtipc_rts_spll_set_constants_struct, &rval,
loop, param, value);
if (ret < 0)
return ret;
return rval;
}
int rts_spll_get_constants(int loop, int param, int value)
{
int rval;
int ret = minipc_call(client, RTS_TIMEOUT,
&rtipc_rts_spll_get_constants_struct, &rval,
loop, param, value);
if (ret < 0)
return ret;
return rval;
}
int rts_connect(char *logfilename)
{
static FILE *f;
......
......@@ -10,6 +10,7 @@ TOOLS += wrs_status_led
TOOLS += mkpasswd
TOOLS += wrs_sfp_dump
TOOLS += wrs_throttling
TOOLS += wrs_spll_tune
PPSI_CONFIG = ../ppsi/include/generated/autoconf.h
WR_INSTALL_ROOT ?= /usr/lib/white-rabbit
......
#include <sys/time.h>
#include <signal.h>
#include <rt_ipc.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#define SPLL_MAIN_LOOP 0
#define SPLL_HELPER_LOOP 1
#define SPLL_KP 0
#define SPLL_KI 1
void error(char *msg)
{
perror(msg);
exit(0);
}
void printHelp(char *name)
{
printf("WRS SoftPLL tune\n\n");
printf("This tool enables the user to change the proportional and integral constants\n");
printf("of the SoftPLL helper and main loops.\n\n");
printf("Usage: %s -s/-g main/helper -c kp/ki -v value\n",name);
exit(0);
}
void sigintHandler(int sig_num)
{
exit(0);
}
int main(int argc, char *argv[])
{
int c = 0;
char s_loop[7];
char s_constant[3];
int set = -1, get = -1;
int loop=-1, constant=-1;
int value = -1;
int check_kp=-1, check_ki=-1;
while ((c = getopt(argc, argv, "hs:g:c:v:")) != -1)
switch (c)
{
case 'h':
printHelp(argv[0]);
break;
case 's':
set = 1;
strcpy(s_loop, optarg);
break;
case 'g':
get = 1;
strcpy(s_loop, optarg);
break;
case 'c':
strcpy(s_constant, optarg);
break;
case 'v':
value = atoi(optarg);
break;
case '?':
if (optopt == 's' || optopt == 'g')
fprintf(stderr, "Option -%c requires \"main\" or \"helper\" loop to be defined.\n", optopt);
else if (optopt == 'c')
fprintf(stderr, "Option -%c requires \"kp\" or \"ki\" to be defined.\n", optopt);
else if (optopt == 'v')
fprintf(stderr, "Option -%c requires the value of the constant to be provided.", optopt);
else if (isprint(optopt))
{
fprintf(stderr, "Unknown option '-%c'.\n", optopt);
printHelp(argv[0]);
}
else
{
fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
printHelp(argv[0]);
}
return 1;
default:
abort();
}
if (!strcmp(s_loop, "helper"))
{
loop = SPLL_HELPER_LOOP;
}
else if (!strcmp(s_loop, "main"))
{
loop = SPLL_MAIN_LOOP;
}
else
{
fprintf(stderr, "'main' or 'helper' option must be provided.\n");
printHelp(argv[0]);
}
if (get != 1)
{
if (!strcmp(s_constant, "kp"))
{
constant = SPLL_KP;
}
else if (!strcmp(s_constant, "ki"))
{
constant = SPLL_KI;
}
else
{
fprintf(stderr, "'kp' or 'ki' option must be provided.\n");
printHelp(argv[0]);
}
}
if( rts_connect(NULL) < 0 ){
printf("Can't connect to the RT subsys\n");
}
if (set == 1)
{
rts_spll_set_constants(loop,constant,value);
do{
check_kp = rts_spll_get_constants(loop,SPLL_KP,0);
check_ki = rts_spll_get_constants(loop,SPLL_KI,0);
}while(check_ki == -1 || check_kp == -1);
usleep(100);
printf("%s constants: kp=%d ki=%d\n",s_loop,check_kp,check_ki);
return 0;
}else if (get == 1)
{
do{
check_kp = rts_spll_get_constants(loop,SPLL_KP,0);
check_ki = rts_spll_get_constants(loop,SPLL_KI,0);
}while(check_ki == -1 || check_kp == -1);
usleep(100);
printf("%s constants: kp=%d ki=%d\n",s_loop,check_kp,check_ki);
return 0;
}
return -1;
}
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