xref: /openbmc/phosphor-pid-control/pid/util.cpp (revision f77d5a57)
1d8012181SPatrick Venture /**
2d8012181SPatrick Venture  * Copyright 2017 Google Inc.
3d8012181SPatrick Venture  *
4d8012181SPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5d8012181SPatrick Venture  * you may not use this file except in compliance with the License.
6d8012181SPatrick Venture  * You may obtain a copy of the License at
7d8012181SPatrick Venture  *
8d8012181SPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9d8012181SPatrick Venture  *
10d8012181SPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11d8012181SPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12d8012181SPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d8012181SPatrick Venture  * See the License for the specific language governing permissions and
14d8012181SPatrick Venture  * limitations under the License.
15d8012181SPatrick Venture  */
16d8012181SPatrick Venture 
17da4a5dd1SPatrick Venture #include "ec/pid.hpp"
18da4a5dd1SPatrick Venture 
19d8012181SPatrick Venture #include <cstring>
20d8012181SPatrick Venture #include <iostream>
21d8012181SPatrick Venture 
22*f77d5a57SPatrick Venture void InitializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
23d8012181SPatrick Venture {
24d8012181SPatrick Venture     std::memset(info, 0x00, sizeof(ec::pid_info_t));
25d8012181SPatrick Venture 
26*f77d5a57SPatrick Venture     info->ts = initial.ts;
27*f77d5a57SPatrick Venture     info->p_c = initial.p_c;
28*f77d5a57SPatrick Venture     info->i_c = initial.i_c;
29*f77d5a57SPatrick Venture     info->ff_off = initial.ff_off;
30*f77d5a57SPatrick Venture     info->ff_gain = initial.ff_gain;
31*f77d5a57SPatrick Venture     info->i_lim.min = initial.i_lim.min;
32*f77d5a57SPatrick Venture     info->i_lim.max = initial.i_lim.max;
33*f77d5a57SPatrick Venture     info->out_lim.min = initial.out_lim.min;
34*f77d5a57SPatrick Venture     info->out_lim.max = initial.out_lim.max;
35*f77d5a57SPatrick Venture     info->slew_neg = initial.slew_neg;
36*f77d5a57SPatrick Venture     info->slew_pos = initial.slew_pos;
37d8012181SPatrick Venture }
38d8012181SPatrick Venture 
39d8012181SPatrick Venture void DumpPIDStruct(ec::pid_info_t* info)
40d8012181SPatrick Venture {
41da4a5dd1SPatrick Venture     std::cerr << " ts: " << info->ts << " p_c: " << info->p_c
42da4a5dd1SPatrick Venture               << " i_c: " << info->i_c << " ff_off: " << info->ff_off
43d8012181SPatrick Venture               << " ff_gain: " << info->ff_gain
44d8012181SPatrick Venture               << " i_lim.min: " << info->i_lim.min
45d8012181SPatrick Venture               << " i_lim.max: " << info->i_lim.max
46d8012181SPatrick Venture               << " out_lim.min: " << info->out_lim.min
47d8012181SPatrick Venture               << " out_lim.max: " << info->out_lim.max
48d8012181SPatrick Venture               << " slew_neg: " << info->slew_neg
49d8012181SPatrick Venture               << " slew_pos: " << info->slew_pos
50d8012181SPatrick Venture               << " last_output: " << info->last_output
51da4a5dd1SPatrick Venture               << " integral: " << info->integral << std::endl;
52d8012181SPatrick Venture 
53d8012181SPatrick Venture     return;
54d8012181SPatrick Venture }
55