xref: /openbmc/phosphor-pid-control/conf.hpp (revision 31058fd3)
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, to help out with TempToMargin conversion.
38  */
39 struct SensorInput
40 {
41     std::string name;
42     double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
43     bool convertTempToMargin = false;
44 };
45 
46 /*
47  * Structure for holding the configuration of a PID.
48  */
49 struct ControllerInfo
50 {
51     std::string type;                // fan or margin or temp?
52     std::vector<SensorInput> inputs; // one or more sensors.
53     double setpoint;                 // initial setpoint for thermal.
54     ec::pidinfo pidInfo;             // pid details
55     ec::StepwiseInfo stepwiseInfo;
56     double failSafePercent;
57 };
58 
59 struct CycleTime
60 {
61     /* The time interval every cycle. 0.1 seconds by default */
62     uint64_t cycleIntervalTimeMS = 100; // milliseconds
63 
64     /* The interval of updating thermals. 1 second by default */
65     uint64_t updateThermalsTimeMS = 1000; // milliseconds
66 };
67 
68 /*
69  * General zone structure used for configuration.  A zone is a list of PIDs
70  * and a set of configuration settings.  This structure gets filled out with
71  * the zone configuration settings and not the PID details.
72  */
73 struct ZoneConfig
74 {
75     /* The minimum set-point value we would ever want (typically in RPM) */
76     double minThermalOutput;
77 
78     /* If the sensors are in fail-safe mode, this is the percentage to use. */
79     double failsafePercent;
80 
81     /* Customize time settings for every cycle */
82     CycleTime cycleTime;
83 };
84 
85 using PIDConf = std::map<std::string, ControllerInfo>;
86 
87 constexpr bool DEBUG = false; // enable to print found configuration
88 
89 } // namespace conf
90 
91 } // namespace pid_control
92