xref: /openbmc/phosphor-pid-control/pid/thermalcontroller.cpp (revision da4a5dd133b88ebfeb69e89d05b381f81ba70e50)
1 /**
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "thermalcontroller.hpp"
18 
19 #include "util.hpp"
20 #include "zone.hpp"
21 
22 std::unique_ptr<PIDController> ThermalController::CreateThermalPid(
23     ZoneInterface* owner, const std::string& id,
24     std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial)
25 {
26     // ThermalController currently only supports precisely one input.
27     if (inputs.size() != 1)
28     {
29         return nullptr;
30     }
31 
32     auto thermal = std::make_unique<ThermalController>(id, inputs, owner);
33 
34     ec::pid_info_t* info = thermal->get_pid_info();
35     thermal->set_setpoint(setpoint);
36 
37     InitializePIDStruct(info, &initial);
38 
39     return thermal;
40 }
41 
42 // bmc_host_sensor_value_float
43 float ThermalController::input_proc(void)
44 {
45     /*
46      * This only supports one thermal input because it doesn't yet know how to
47      * handle merging them, probably max?
48      */
49     double value = _owner->getCachedValue(_inputs.at(0));
50     return static_cast<float>(value);
51 }
52 
53 // bmc_get_setpt
54 float ThermalController::setpt_proc(void)
55 {
56     float setpoint = get_setpoint();
57 
58     /* TODO(venture): Thermal setpoint invalid? */
59 #if 0
60     if (-1 == setpoint)
61     {
62         return 0.0f;
63     }
64     else
65     {
66         return setpoint;
67     }
68 #endif
69     return setpoint;
70 }
71 
72 // bmc_set_pid_output
73 void ThermalController::output_proc(float value)
74 {
75     _owner->addRPMSetPoint(value);
76 
77     return;
78 }
79