Skip to content

Commit 4202fdf

Browse files
committed
SWPTP-1584: add fir_filter_size option for secondary servos
1 parent 7262d5c commit 4202fdf

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
3333
- Add `observe_readonly_clocks` option to create passive servos. (SWPTP-1579)
3434
- A PPS sync instance may be created for each external pin associated with an
3535
interface clock, configured for `pps-in` or `pps-out` functions. (SWPTP-1576)
36+
- Add `fir_filter_size` option for secondary servos. (SWPTP-1584)
3637
- Add hardware clock control and diagnostic utility `tstool`.
3738

3839
### Changed

src/include/sfptpd_general_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ typedef struct sfptpd_config_general {
276276
long double kp;
277277
long double ki;
278278
} pid_filter;
279+
unsigned int fir_filter_size;
279280
struct sfptpd_selection_policy selection_policy;
280281
sfptpd_phc_pps_method_t phc_pps_method[SFPTPD_PPS_METHOD_MAX + 1];
281282
char json_stats_filename[PATH_MAX];

src/sfptpd_general_config.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "sfptpd_phc.h"
3131
#include "sfptpd_crny_module.h"
3232
#include "sfptpd_config_helpers.h"
33+
#include "sfptpd_filter.h"
3334

3435

3536
/****************************************************************************
@@ -100,6 +101,8 @@ static int parse_pid_filter_kp(struct sfptpd_config_section *section, const char
100101
unsigned int num_params, const char * const params[]);
101102
static int parse_pid_filter_ki(struct sfptpd_config_section *section, const char *option,
102103
unsigned int num_params, const char * const params[]);
104+
static int parse_fir_filter_size(struct sfptpd_config_section *section, const char *option,
105+
unsigned int num_params, const char * const params[]);
103106
static int parse_trace_level(struct sfptpd_config_section *section, const char *option,
104107
unsigned int num_params, const char * const params[]);
105108
static int parse_test_mode(struct sfptpd_config_section *section, const char *option,
@@ -355,6 +358,15 @@ static const sfptpd_config_option_t config_general_options[] =
355358
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
356359
parse_pid_filter_ki,
357360
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_SERVO_K_INTEGRAL)},
361+
{"fir_filter_size", "NUMBER",
362+
"Number of data samples stored in the FIR filter. The "
363+
"valid range is [" STRINGIFY(SFPTPD_FIR_FILTER_STIFFNESS_MIN)
364+
"," STRINGIFY(SFPTPD_FIR_FILTER_STIFFNESS_MAX) "]. A value of "
365+
"1 means that the filter is off while higher values will "
366+
"reduce adaptability but increase stability. "
367+
"Default is one second's worth of samples.",
368+
1, SFPTPD_CONFIG_SCOPE_INSTANCE,
369+
parse_fir_filter_size},
358370
{"trace_level", "[<general | threading | bic | netlink | ntp | servo | clocks | most | all>] NUMBER",
359371
"Specifies a module (of 'general' if omitted) trace level from 0 (none) to 6 (excessive)",
360372
~1, SFPTPD_CONFIG_SCOPE_GLOBAL,
@@ -1578,6 +1590,28 @@ static int parse_pid_filter_ki(struct sfptpd_config_section *section, const char
15781590
return 0;
15791591
}
15801592

1593+
static int parse_fir_filter_size(struct sfptpd_config_section *section, const char *option,
1594+
unsigned int num_params, const char * const params[])
1595+
{
1596+
int tokens, size;
1597+
sfptpd_config_general_t *general = (sfptpd_config_general_t *)section;
1598+
assert(num_params == 1);
1599+
1600+
tokens = sscanf(params[0], "%u", &size);
1601+
if (tokens != 1)
1602+
return EINVAL;
1603+
1604+
if ((size < SFPTPD_FIR_FILTER_STIFFNESS_MIN) ||
1605+
(size > SFPTPD_FIR_FILTER_STIFFNESS_MAX)) {
1606+
CFG_ERROR(section, "fir_filter_size %s invalid. Expect range [%d,%d]\n",
1607+
params[0], SFPTPD_FIR_FILTER_STIFFNESS_MIN,
1608+
SFPTPD_FIR_FILTER_STIFFNESS_MAX);
1609+
return ERANGE;
1610+
}
1611+
1612+
general->fir_filter_size = (unsigned int)size;
1613+
return 0;
1614+
}
15811615

15821616
static int parse_trace_level(struct sfptpd_config_section *section, const char *option,
15831617
unsigned int num_params, const char * const params[])
@@ -2118,6 +2152,7 @@ static struct sfptpd_config_section *general_config_create(const char *name,
21182152

21192153
new->pid_filter.kp = SFPTPD_DEFAULT_SERVO_K_PROPORTIONAL;
21202154
new->pid_filter.ki = SFPTPD_DEFAULT_SERVO_K_INTEGRAL;
2155+
new->fir_filter_size = 0; /* 0 indicates to use default computed size */
21212156

21222157
new->selection_policy = sfptpd_default_selection_policy;
21232158
memcpy(new->phc_diff_methods, sfptpd_default_phc_diff_methods, sizeof(sfptpd_default_phc_diff_methods));

src/sfptpd_servo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ struct sfptpd_servo *sfptpd_servo_create(struct sfptpd_clockfeed *clockfeed,
183183
else if (stiffness > SFPTPD_SERVO_FILTER_STIFFNESS_MAX)
184184
stiffness = SFPTPD_SERVO_FILTER_STIFFNESS_MAX;
185185

186+
/* Override computed FIR filter size if specified in config. */
187+
if (general_config->fir_filter_size != 0)
188+
stiffness = general_config->fir_filter_size;
189+
186190
/* Initialise the PID and FIR filters */
187191
sfptpd_fir_filter_init(&servo->fir_filter, stiffness);
188192
sfptpd_pid_filter_init(&servo->pid_filter,

0 commit comments

Comments
 (0)