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