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