xref: /openbmc/phosphor-pid-control/conf.hpp (revision f8b6e55147148c3cfb42327ff267197a460b411c)
1 #pragma once
2 
3 #include "pid/ec/pid.hpp"
4 #include "pid/ec/stepwise.hpp"
5 
6 #include <cstdint>
7 #include <limits>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 namespace pid_control
13 {
14 
15 namespace conf
16 {
17 
18 /*
19  * General sensor structure used for configuration.
20  */
21 struct SensorConfig
22 {
23     /* Used for listen if readPath is passive. */
24     std::string type;
25     /* Can be a sensor path or a dbus path. */
26     std::string readPath;
27     std::string writePath;
28     /* min/max values for writing a percentage or error checking. */
29     int64_t min;
30     int64_t max;
31     int64_t timeout;
32     bool ignoreDbusMinMax;
33     bool unavailableAsFailed;
34 };
35 
36 /*
37  * Structure for decorating an input sensor's name with additional
38  * information, such as TempToMargin and MissingIsAcceptable.
39  * This information comes from the PID loop configuration,
40  * not from SensorConfig, in order for it to be able to work
41  * with dynamic sensors from entity-manager.
42  */
43 struct SensorInput
44 {
45     std::string name;
46     double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
47     bool convertTempToMargin = false;
48     bool missingIsAcceptable = false;
49 };
50 
51 /*
52  * Structure for holding the configuration of a PID.
53  */
54 struct ControllerInfo
55 {
56     std::string type;                // fan or margin or temp?
57     std::vector<SensorInput> inputs; // one or more sensors.
58     double setpoint;                 // initial setpoint for thermal.
59     ec::pidinfo pidInfo;             // pid details
60     ec::StepwiseInfo stepwiseInfo;
61     double failSafePercent;
62 };
63 
64 struct CycleTime
65 {
66     /* The time interval every cycle. 0.1 seconds by default */
67     uint64_t cycleIntervalTimeMS = 100; // milliseconds
68 
69     /* The interval of updating thermals. 1 second by default */
70     uint64_t updateThermalsTimeMS = 1000; // milliseconds
71 };
72 
73 /*
74  * General zone structure used for configuration.  A zone is a list of PIDs
75  * and a set of configuration settings.  This structure gets filled out with
76  * the zone configuration settings and not the PID details.
77  */
78 struct ZoneConfig
79 {
80     /* The minimum set-point value we would ever want (typically in RPM) */
81     double minThermalOutput;
82 
83     /* If the sensors are in fail-safe mode, this is the percentage to use. */
84     double failsafePercent;
85 
86     /* Customize time settings for every cycle */
87     CycleTime cycleTime;
88 
89     /* Enable accumulation of the output PWM of different controllers with same
90      * sensor */
91     bool accumulateSetPoint;
92 };
93 
94 using PIDConf = std::map<std::string, ControllerInfo>;
95 
96 constexpr bool DEBUG = false; // enable to print found configuration
97 
98 } // namespace conf
99 
100 } // namespace pid_control
101