Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 config.c  |  7 +------
 config.h  |  1 -
 phc2sys.c |  7 ++++---
 pi.c      | 11 +++++++----
 pi.h      |  8 +-------
 ptp4l.c   |  1 -
 servo.c   |  2 +-
 7 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/config.c b/config.c
index b649cf0..3bd98da 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
        GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, 
PRINT_LEVEL_MAX),
        GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+       GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
        GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
        GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
        PORT_ITEM_INT("udp_ttl", 1, 1, 255),
@@ -541,12 +542,6 @@ static enum parser_result parse_global_setting(const char 
*option,
                cfg->dds.freq_est_interval = val;
                pod->freq_est_interval = val;
 
-       } else if (!strcmp(option, "pi_proportional_const")) {
-               r = get_ranged_double(value, &df, 0.0, DBL_MAX);
-               if (r != PARSED_OK)
-                       return r;
-               *cfg->pi_proportional_const = df;
-
        } else if (!strcmp(option, "pi_integral_const")) {
                r = get_ranged_double(value, &df, 0.0, DBL_MAX);
                if (r != PARSED_OK)
diff --git a/config.h b/config.h
index db7963f..4f24f51 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
        struct port_defaults pod;
        enum servo_type clock_servo;
 
-       double *pi_proportional_const;
        double *pi_integral_const;
        double *pi_proportional_scale;
        double *pi_proportional_exponent;
diff --git a/phc2sys.c b/phc2sys.c
index 44ba1fc..76f161a 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1243,7 +1243,7 @@ int main(int argc, char *argv[])
        }
        cfg = &phc2sys_config;
 
-       configured_pi_kp = KP;
+       config_set_double(cfg, "pi_proportional_const", KP);
        configured_pi_ki = KI;
 
        /* Process the command line arguments. */
@@ -1289,8 +1289,9 @@ int main(int argc, char *argv[])
                        }
                        break;
                case 'P':
-                       if (get_arg_val_d(c, optarg, &configured_pi_kp,
-                                         0.0, DBL_MAX))
+                       if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
+                               return -1;
+                       if (config_set_double(cfg, "pi_proportional_const", 
tmp))
                                return -1;
                        break;
                case 'I':
diff --git a/pi.c b/pi.c
index e0116fe..7549dd6 100644
--- a/pi.c
+++ b/pi.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <math.h>
 
+#include "config.h"
 #include "pi.h"
 #include "print.h"
 #include "servo_private.h"
@@ -35,7 +36,6 @@
 #define FREQ_EST_MARGIN 0.001
 
 /* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_kp = 0.0;
 double configured_pi_ki = 0.0;
 double configured_pi_kp_scale = 0.0;
 double configured_pi_kp_exponent = -0.3;
@@ -53,6 +53,8 @@ struct pi_servo {
        double ki;
        double last_freq;
        int count;
+       /* configuration: */
+       double configured_pi_kp;
 };
 
 static void pi_destroy(struct servo *servo)
@@ -177,7 +179,7 @@ static void pi_reset(struct servo *servo)
        s->count = 0;
 }
 
-struct servo *pi_servo_create(int fadj, int sw_ts)
+struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
 {
        struct pi_servo *s;
 
@@ -193,12 +195,13 @@ struct servo *pi_servo_create(int fadj, int sw_ts)
        s->last_freq     = fadj;
        s->kp            = 0.0;
        s->ki            = 0.0;
+       s->configured_pi_kp = config_get_double(cfg, NULL, 
"pi_proportional_const");
 
-       if (configured_pi_kp && configured_pi_ki) {
+       if (s->configured_pi_kp && configured_pi_ki) {
                /* Use the constants as configured by the user without
                   adjusting for sync interval unless they make the servo
                   unstable. */
-               configured_pi_kp_scale = configured_pi_kp;
+               configured_pi_kp_scale = s->configured_pi_kp;
                configured_pi_ki_scale = configured_pi_ki;
                configured_pi_kp_exponent = 0.0;
                configured_pi_ki_exponent = 0.0;
diff --git a/pi.h b/pi.h
index 7b092a0..cd3c74f 100644
--- a/pi.h
+++ b/pi.h
@@ -23,12 +23,6 @@
 
 /**
  * When set to a non-zero value, this variable determines the
- * proportional constant for the PI controller.
- */
-extern double configured_pi_kp;
-
-/**
- * When set to a non-zero value, this variable determines the
  * integral constant for the PI controller.
  */
 extern double configured_pi_ki;
@@ -77,6 +71,6 @@ extern double configured_pi_ki_exponent;
  */
 extern double configured_pi_ki_norm_max;
 
-struct servo *pi_servo_create(int fadj, int sw_ts);
+struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts);
 
 #endif
diff --git a/ptp4l.c b/ptp4l.c
index 78261a9..5c23ddf 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
        .transport = TRANS_UDP_IPV4,
        .clock_servo = CLOCK_SERVO_PI,
 
-       .pi_proportional_const = &configured_pi_kp,
        .pi_integral_const = &configured_pi_ki,
        .pi_proportional_scale = &configured_pi_kp_scale,
        .pi_proportional_exponent = &configured_pi_kp_exponent,
diff --git a/servo.c b/servo.c
index 2e82ebe..0449223 100644
--- a/servo.c
+++ b/servo.c
@@ -37,7 +37,7 @@ struct servo *servo_create(struct config *cfg, enum 
servo_type type,
 
        switch (type) {
        case CLOCK_SERVO_PI:
-               servo = pi_servo_create(fadj, sw_ts);
+               servo = pi_servo_create(cfg, fadj, sw_ts);
                break;
        case CLOCK_SERVO_LINREG:
                servo = linreg_servo_create(fadj);
-- 
2.1.4


------------------------------------------------------------------------------
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to