|
30 | 30 | #include "sfptpd_phc.h"
|
31 | 31 | #include "sfptpd_crny_module.h"
|
32 | 32 | #include "sfptpd_config_helpers.h"
|
| 33 | +#include "sfptpd_filter.h" |
33 | 34 |
|
34 | 35 |
|
35 | 36 | /****************************************************************************
|
@@ -100,6 +101,8 @@ static int parse_pid_filter_kp(struct sfptpd_config_section *section, const char
|
100 | 101 | unsigned int num_params, const char * const params[]);
|
101 | 102 | static int parse_pid_filter_ki(struct sfptpd_config_section *section, const char *option,
|
102 | 103 | 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[]); |
103 | 106 | static int parse_trace_level(struct sfptpd_config_section *section, const char *option,
|
104 | 107 | unsigned int num_params, const char * const params[]);
|
105 | 108 | 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[] =
|
355 | 358 | 1, SFPTPD_CONFIG_SCOPE_INSTANCE,
|
356 | 359 | parse_pid_filter_ki,
|
357 | 360 | .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}, |
358 | 370 | {"trace_level", "[<general | threading | bic | netlink | ntp | servo | clocks | most | all>] NUMBER",
|
359 | 371 | "Specifies a module (of 'general' if omitted) trace level from 0 (none) to 6 (excessive)",
|
360 | 372 | ~1, SFPTPD_CONFIG_SCOPE_GLOBAL,
|
@@ -1578,6 +1590,28 @@ static int parse_pid_filter_ki(struct sfptpd_config_section *section, const char
|
1578 | 1590 | return 0;
|
1579 | 1591 | }
|
1580 | 1592 |
|
| 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 | +} |
1581 | 1615 |
|
1582 | 1616 | static int parse_trace_level(struct sfptpd_config_section *section, const char *option,
|
1583 | 1617 | unsigned int num_params, const char * const params[])
|
@@ -2118,6 +2152,7 @@ static struct sfptpd_config_section *general_config_create(const char *name,
|
2118 | 2152 |
|
2119 | 2153 | new->pid_filter.kp = SFPTPD_DEFAULT_SERVO_K_PROPORTIONAL;
|
2120 | 2154 | new->pid_filter.ki = SFPTPD_DEFAULT_SERVO_K_INTEGRAL;
|
| 2155 | + new->fir_filter_size = 0; /* 0 indicates to use default computed size */ |
2121 | 2156 |
|
2122 | 2157 | new->selection_policy = sfptpd_default_selection_policy;
|
2123 | 2158 | memcpy(new->phc_diff_methods, sfptpd_default_phc_diff_methods, sizeof(sfptpd_default_phc_diff_methods));
|
|
0 commit comments