regulators: Enable phase fault detection

Modify the top level Manager class to perform phase fault detection
every 15 seconds.

If the chassis is powered on, phase faults will be detected in every
regulator device in the system.

Tested:
* Tested where no phase fault found for a regulator.
* Tested where an N phase fault found for a regulator.
* Tested where an N+1 phase fault found for a regulator.
* Tested where additional data was captured in phase fault error log.
* Verified detection occurs every 15 seconds
* Verified detection starts during power on after regulators are
  enabled.
* Verified detection stops during power off before regulators are
  disabled.
* Tested where no JSON configuration file was loaded.
* Tested when application was restarted while system was powered on.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I12ac16dfcf4f754e168ce1ff76795520f823349f
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index e39273f..663d280 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -73,7 +73,10 @@
 
 Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
     ManagerObject{bus, managerObjPath, true}, bus{bus}, eventLoop{event},
-    services{bus}, timer{event, std::bind(&Manager::timerExpired, this)}
+    services{bus}, phaseFaultTimer{event,
+                                   std::bind(&Manager::phaseFaultTimerExpired,
+                                             this)},
+    sensorTimer{event, std::bind(&Manager::sensorTimerExpired, this)}
 {
     // Subscribe to D-Bus interfacesAdded signal from Entity Manager.  This
     // notifies us if the compatible interface becomes available later.
@@ -197,8 +200,11 @@
     {
         services.getJournal().logDebug("Monitoring enabled");
 
-        // Restart timer to have a repeating 1 second interval
-        timer.restart(std::chrono::seconds(1));
+        // Restart phase fault detection timer with repeating 15 second interval
+        phaseFaultTimer.restart(std::chrono::seconds(15));
+
+        // Restart sensor monitoring timer with repeating 1 second interval
+        sensorTimer.restart(std::chrono::seconds(1));
 
         // Enable sensors service; put all sensors in an active state
         services.getSensors().enable();
@@ -207,8 +213,9 @@
     {
         services.getJournal().logDebug("Monitoring disabled");
 
-        // Disable timer
-        timer.setEnabled(false);
+        // Disable timers
+        phaseFaultTimer.setEnabled(false);
+        sensorTimer.setEnabled(false);
 
         // Disable sensors service; put all sensors in an inactive state
         services.getSensors().disable();
@@ -225,14 +232,17 @@
     }
 }
 
-void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
-                            const struct signalfd_siginfo* /*sigInfo*/)
+void Manager::phaseFaultTimerExpired()
 {
-    // Reload the JSON configuration file
-    loadConfigFile();
+    // Verify config file has been loaded and System object is valid
+    if (isConfigFileLoaded())
+    {
+        // Detect redundant phase faults in regulator devices in the system
+        system->detectPhaseFaults(services);
+    }
 }
 
-void Manager::timerExpired()
+void Manager::sensorTimerExpired()
 {
     // Notify sensors service that a sensor monitoring cycle is starting
     services.getSensors().startCycle();
@@ -248,6 +258,13 @@
     services.getSensors().endCycle();
 }
 
+void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
+                            const struct signalfd_siginfo* /*sigInfo*/)
+{
+    // Reload the JSON configuration file
+    loadConfigFile();
+}
+
 void Manager::clearHardwareData()
 {
     // Clear any cached hardware presence data and VPD values
diff --git a/phosphor-regulators/src/manager.hpp b/phosphor-regulators/src/manager.hpp
index d9b62a0..c056b27 100644
--- a/phosphor-regulators/src/manager.hpp
+++ b/phosphor-regulators/src/manager.hpp
@@ -104,6 +104,16 @@
     void monitor(bool enable) override;
 
     /**
+     * Phase fault detection timer expired callback function.
+     */
+    void phaseFaultTimerExpired();
+
+    /**
+     * Sensor monitoring timer expired callback function.
+     */
+    void sensorTimerExpired();
+
+    /**
      * Callback function to handle receiving a HUP signal
      * to reload the configuration data.
      *
@@ -113,11 +123,6 @@
     void sighupHandler(sdeventplus::source::Signal& sigSrc,
                        const struct signalfd_siginfo* sigInfo);
 
-    /**
-     * Timer expired callback function
-     */
-    void timerExpired();
-
   private:
     /**
      * Clear any cached data or error history related to hardware devices.
@@ -211,9 +216,14 @@
     BMCServices services;
 
     /**
-     * Event timer used to initiate regulator monitoring.
+     * Event timer used to initiate phase fault detection.
      */
-    Timer timer;
+    Timer phaseFaultTimer;
+
+    /**
+     * Event timer used to initiate sensor monitoring.
+     */
+    Timer sensorTimer;
 
     /**
      * List of D-Bus signal matches