10a450197SShawn McCarney /**
20a450197SShawn McCarney * Copyright © 2021 IBM Corporation
30a450197SShawn McCarney *
40a450197SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License");
50a450197SShawn McCarney * you may not use this file except in compliance with the License.
60a450197SShawn McCarney * You may obtain a copy of the License at
70a450197SShawn McCarney *
80a450197SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0
90a450197SShawn McCarney *
100a450197SShawn McCarney * Unless required by applicable law or agreed to in writing, software
110a450197SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS,
120a450197SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130a450197SShawn McCarney * See the License for the specific language governing permissions and
140a450197SShawn McCarney * limitations under the License.
150a450197SShawn McCarney */
160a450197SShawn McCarney #pragma once
170a450197SShawn McCarney
180a450197SShawn McCarney #include <string>
190a450197SShawn McCarney
200a450197SShawn McCarney namespace phosphor::power::regulators
210a450197SShawn McCarney {
220a450197SShawn McCarney
230a450197SShawn McCarney /**
240a450197SShawn McCarney * Voltage regulator sensor type.
250a450197SShawn McCarney */
26837ece7cSShawn McCarney enum class SensorType : unsigned char
270a450197SShawn McCarney {
280a450197SShawn McCarney /**
290a450197SShawn McCarney * Output current.
300a450197SShawn McCarney */
310a450197SShawn McCarney iout,
320a450197SShawn McCarney
330a450197SShawn McCarney /**
340a450197SShawn McCarney * Highest output current.
350a450197SShawn McCarney */
360a450197SShawn McCarney iout_peak,
370a450197SShawn McCarney
380a450197SShawn McCarney /**
390a450197SShawn McCarney * Lowest output current.
400a450197SShawn McCarney */
410a450197SShawn McCarney iout_valley,
420a450197SShawn McCarney
430a450197SShawn McCarney /**
440a450197SShawn McCarney * Output power.
450a450197SShawn McCarney */
460a450197SShawn McCarney pout,
470a450197SShawn McCarney
480a450197SShawn McCarney /**
490a450197SShawn McCarney * Temperature.
500a450197SShawn McCarney */
510a450197SShawn McCarney temperature,
520a450197SShawn McCarney
530a450197SShawn McCarney /**
540a450197SShawn McCarney * Highest temperature.
550a450197SShawn McCarney */
560a450197SShawn McCarney temperature_peak,
570a450197SShawn McCarney
580a450197SShawn McCarney /**
590a450197SShawn McCarney * Output voltage.
600a450197SShawn McCarney */
610a450197SShawn McCarney vout,
620a450197SShawn McCarney
630a450197SShawn McCarney /**
640a450197SShawn McCarney * Highest output voltage.
650a450197SShawn McCarney */
660a450197SShawn McCarney vout_peak,
670a450197SShawn McCarney
680a450197SShawn McCarney /**
690a450197SShawn McCarney * Lowest output voltage.
700a450197SShawn McCarney */
710a450197SShawn McCarney vout_valley
720a450197SShawn McCarney };
730a450197SShawn McCarney
740a450197SShawn McCarney /**
750a450197SShawn McCarney * @namespace sensors
760a450197SShawn McCarney *
770a450197SShawn McCarney * Contains utility functions related to voltage regulator sensors.
780a450197SShawn McCarney */
790a450197SShawn McCarney namespace sensors
800a450197SShawn McCarney {
810a450197SShawn McCarney
820a450197SShawn McCarney /**
830a450197SShawn McCarney * Returns the name of the specified SensorType.
840a450197SShawn McCarney *
850a450197SShawn McCarney * The returned string will exactly match the enumerator name, such as
860a450197SShawn McCarney * "temperature_peak".
870a450197SShawn McCarney *
880a450197SShawn McCarney * @param type sensor type
890a450197SShawn McCarney * @return sensor type name
900a450197SShawn McCarney */
toString(SensorType type)91837ece7cSShawn McCarney inline std::string toString(SensorType type)
920a450197SShawn McCarney {
930a450197SShawn McCarney std::string name{};
940a450197SShawn McCarney switch (type)
950a450197SShawn McCarney {
960a450197SShawn McCarney case SensorType::iout:
970a450197SShawn McCarney name = "iout";
980a450197SShawn McCarney break;
990a450197SShawn McCarney case SensorType::iout_peak:
1000a450197SShawn McCarney name = "iout_peak";
1010a450197SShawn McCarney break;
1020a450197SShawn McCarney case SensorType::iout_valley:
1030a450197SShawn McCarney name = "iout_valley";
1040a450197SShawn McCarney break;
1050a450197SShawn McCarney case SensorType::pout:
1060a450197SShawn McCarney name = "pout";
1070a450197SShawn McCarney break;
1080a450197SShawn McCarney case SensorType::temperature:
1090a450197SShawn McCarney name = "temperature";
1100a450197SShawn McCarney break;
1110a450197SShawn McCarney case SensorType::temperature_peak:
1120a450197SShawn McCarney name = "temperature_peak";
1130a450197SShawn McCarney break;
1140a450197SShawn McCarney case SensorType::vout:
1150a450197SShawn McCarney name = "vout";
1160a450197SShawn McCarney break;
1170a450197SShawn McCarney case SensorType::vout_peak:
1180a450197SShawn McCarney name = "vout_peak";
1190a450197SShawn McCarney break;
1200a450197SShawn McCarney case SensorType::vout_valley:
1210a450197SShawn McCarney name = "vout_valley";
1220a450197SShawn McCarney break;
1230a450197SShawn McCarney }
1240a450197SShawn McCarney return name;
1250a450197SShawn McCarney }
1260a450197SShawn McCarney
1270a450197SShawn McCarney } // namespace sensors
1280a450197SShawn McCarney
1290a450197SShawn McCarney /**
1300a450197SShawn McCarney * @class Sensors
1310a450197SShawn McCarney *
1320a450197SShawn McCarney * Abstract base class for a service that maintains a list of voltage regulator
1330a450197SShawn McCarney * sensors.
1340a450197SShawn McCarney *
1350a450197SShawn McCarney * This service makes the voltage regulator sensors available to other BMC
1360a450197SShawn McCarney * applications. For example, the Redfish support obtains sensor data from this
1370a450197SShawn McCarney * service.
1380a450197SShawn McCarney *
1390a450197SShawn McCarney * Each voltage rail in the system may provide multiple types of sensor data,
1400a450197SShawn McCarney * such as temperature, output voltage, and output current (see SensorType). A
1410a450197SShawn McCarney * sensor tracks one of these data types for a voltage rail.
1420a450197SShawn McCarney *
1430a450197SShawn McCarney * Voltage regulator sensors are typically read frequently based on a timer.
1440a450197SShawn McCarney * Reading all the sensors once is called a monitoring cycle. The application
1450a450197SShawn McCarney * will loop through all voltage rails, reading all supported sensor types for
1460a450197SShawn McCarney * each rail. During a monitoring cycle, the following sensor service methods
1470a450197SShawn McCarney * should be called in the specified order:
1480a450197SShawn McCarney * - startCycle() // At the start of a sensor monitoring cycle
1490a450197SShawn McCarney * - startRail() // Before reading all the sensors for one rail
1500a450197SShawn McCarney * - setValue() // To set the value of one sensor for the current rail
1510a450197SShawn McCarney * - endRail() // After reading all the sensors for one rail
1520a450197SShawn McCarney * - endCycle() // At the end of a sensor monitoring cycle
1530a450197SShawn McCarney *
1540a450197SShawn McCarney * This service can be enabled or disabled. It is typically enabled when the
1550a450197SShawn McCarney * system is powered on and voltage regulators begin producing output. It is
1560a450197SShawn McCarney * typically disabled when the system is powered off. It can also be
1570a450197SShawn McCarney * temporarily disabled if other BMC applications need to communicate with the
1580a450197SShawn McCarney * voltage regulator devices. When the service is disabled, the sensors still
1590a450197SShawn McCarney * exist but are in an inactive state since their values are not being updated.
1600a450197SShawn McCarney */
1610a450197SShawn McCarney class Sensors
1620a450197SShawn McCarney {
1630a450197SShawn McCarney public:
1640a450197SShawn McCarney // Specify which compiler-generated methods we want
1650a450197SShawn McCarney Sensors() = default;
1660a450197SShawn McCarney Sensors(const Sensors&) = delete;
1670a450197SShawn McCarney Sensors(Sensors&&) = delete;
1680a450197SShawn McCarney Sensors& operator=(const Sensors&) = delete;
1690a450197SShawn McCarney Sensors& operator=(Sensors&&) = delete;
1700a450197SShawn McCarney virtual ~Sensors() = default;
1710a450197SShawn McCarney
1720a450197SShawn McCarney /**
1730a450197SShawn McCarney * Enable the sensors service.
1740a450197SShawn McCarney *
1750a450197SShawn McCarney * While the service is enabled, the sensors that it provides will be in an
1760a450197SShawn McCarney * active state. This indicates that their value is being updated
1770a450197SShawn McCarney * periodically.
1780a450197SShawn McCarney */
179*c9c69518SShawn McCarney virtual void enable() = 0;
1800a450197SShawn McCarney
1810a450197SShawn McCarney /**
1820a450197SShawn McCarney * Notify the sensors service that the current sensor monitoring cycle has
1830a450197SShawn McCarney * ended.
1840a450197SShawn McCarney */
185*c9c69518SShawn McCarney virtual void endCycle() = 0;
1860a450197SShawn McCarney
1870a450197SShawn McCarney /**
1880a450197SShawn McCarney * Notify the sensors service that sensor monitoring has ended for the
1890a450197SShawn McCarney * current voltage rail.
1900a450197SShawn McCarney *
1910a450197SShawn McCarney * @param errorOccurred specifies whether an error occurred while trying to
1920a450197SShawn McCarney * read all the sensors for the current rail
1930a450197SShawn McCarney */
194*c9c69518SShawn McCarney virtual void endRail(bool errorOccurred) = 0;
1950a450197SShawn McCarney
1960a450197SShawn McCarney /**
1970a450197SShawn McCarney * Disable the sensors service.
1980a450197SShawn McCarney *
1990a450197SShawn McCarney * While the service is disabled, the sensors that it provides will be in an
2000a450197SShawn McCarney * inactive state. This indicates that their value is not being updated.
2010a450197SShawn McCarney */
202*c9c69518SShawn McCarney virtual void disable() = 0;
2030a450197SShawn McCarney
2040a450197SShawn McCarney /**
2050a450197SShawn McCarney * Sets the value of one sensor for the current voltage rail.
2060a450197SShawn McCarney *
20703a25f1bSShawn McCarney * Throws an exception if an error occurs.
20803a25f1bSShawn McCarney *
2090a450197SShawn McCarney * @param type sensor type
2100a450197SShawn McCarney * @param value sensor value
2110a450197SShawn McCarney */
212*c9c69518SShawn McCarney virtual void setValue(SensorType type, double value) = 0;
2130a450197SShawn McCarney
2140a450197SShawn McCarney /**
2150a450197SShawn McCarney * Notify the sensors service that a sensor monitoring cycle is starting.
2160a450197SShawn McCarney */
217*c9c69518SShawn McCarney virtual void startCycle() = 0;
2180a450197SShawn McCarney
2190a450197SShawn McCarney /**
2200a450197SShawn McCarney * Notify the sensors service that sensor monitoring is starting for the
2210a450197SShawn McCarney * specified voltage rail.
2220a450197SShawn McCarney *
2230a450197SShawn McCarney * Calls to setValue() will update sensors for this rail.
2240a450197SShawn McCarney *
2250a450197SShawn McCarney * @param rail unique rail ID
2260a450197SShawn McCarney * @param deviceInventoryPath D-Bus inventory path of the voltage regulator
2270a450197SShawn McCarney * device that produces the rail
2280a450197SShawn McCarney * @param chassisInventoryPath D-Bus inventory path of the chassis that
2290a450197SShawn McCarney * contains the voltage regulator device
2300a450197SShawn McCarney */
2310a450197SShawn McCarney virtual void startRail(const std::string& rail,
2320a450197SShawn McCarney const std::string& deviceInventoryPath,
233*c9c69518SShawn McCarney const std::string& chassisInventoryPath) = 0;
2340a450197SShawn McCarney };
2350a450197SShawn McCarney
2360a450197SShawn McCarney } // namespace phosphor::power::regulators
237