xref: /openbmc/phosphor-pid-control/conf.hpp (revision e1fa85942c66533699a3b785990d95e9c89b6050)
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     bool ignoreFailIfHostOff;
35 };
36 
37 /*
38  * Structure for decorating an input sensor's name with additional
39  * information, such as TempToMargin and MissingIsAcceptable.
40  * This information comes from the PID loop configuration,
41  * not from SensorConfig, in order for it to be able to work
42  * with dynamic sensors from entity-manager.
43  */
44 struct SensorInput
45 {
46     std::string name;
47     double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
48     bool convertTempToMargin = false;
49     bool missingIsAcceptable = false;
50 };
51 
52 /*
53  * Structure for holding the configuration of a PID.
54  */
55 struct ControllerInfo
56 {
57     std::string type;                // fan or margin or temp?
58     std::vector<SensorInput> inputs; // one or more sensors.
59     double setpoint;                 // initial setpoint for thermal.
60     ec::pidinfo pidInfo;             // pid details
61     ec::StepwiseInfo stepwiseInfo;
62     double failSafePercent;
63 };
64 
65 struct CycleTime
66 {
67     /* The time interval every cycle. 0.1 seconds by default */
68     uint64_t cycleIntervalTimeMS = 100; // milliseconds
69 
70     /* The interval of updating thermals. 1 second by default */
71     uint64_t updateThermalsTimeMS = 1000; // milliseconds
72 };
73 
74 /*
75  * General zone structure used for configuration.  A zone is a list of PIDs
76  * and a set of configuration settings.  This structure gets filled out with
77  * the zone configuration settings and not the PID details.
78  */
79 struct ZoneConfig
80 {
81     /* The minimum set-point value we would ever want (typically in RPM) */
82     double minThermalOutput;
83 
84     /* If the sensors are in fail-safe mode, this is the percentage to use. */
85     double failsafePercent;
86 
87     /* Customize time settings for every cycle */
88     CycleTime cycleTime;
89 
90     /* Enable accumulation of the output PWM of different controllers with same
91      * sensor */
92     bool accumulateSetPoint;
93 };
94 
95 using PIDConf = std::map<std::string, ControllerInfo>;
96 
97 constexpr bool DEBUG = false; // enable to print found configuration
98 
99 } // namespace conf
100 
101 } // namespace pid_control
102