Add helper to assert GPIOs for a time duration

This change adds a helper that uses the defined polarity to
assert a GPIO for a time duration.  This helper acts as a
middle layer to abstract the actual value from both the caller
and the setGPIOOutputForMs() function.

Tested:
Confirmed that ipmitool power off, on, cycle, and reset all
behave correctly.

Change-Id: Ie3a824b1e23474fc839ce1fc1f6af6283f7aa39d
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/power-control-x86/src/power_control.cpp b/power-control-x86/src/power_control.cpp
index 54cac61..d7899b3 100644
--- a/power-control-x86/src/power_control.cpp
+++ b/power-control-x86/src/power_control.cpp
@@ -1190,40 +1190,31 @@
 static int setGPIOOutputForMs(const ConfigData& config, const int value,
                               const int durationMs)
 {
-    int polarizedvalue;
-    if (!config.polarity)
-    {
-        polarizedvalue = value;
-    }
-    else
-    {
-        polarizedvalue = !value;
-    }
     // If the requested GPIO is masked, use the mask line to set the output
     if (powerButtonMask && config.lineName == powerOutConfig.lineName)
     {
-        return setMaskedGPIOOutputForMs(powerButtonMask, config.lineName,
-                                        polarizedvalue, durationMs);
+        return setMaskedGPIOOutputForMs(powerButtonMask, config.lineName, value,
+                                        durationMs);
     }
     if (resetButtonMask && config.lineName == resetOutConfig.lineName)
     {
-        return setMaskedGPIOOutputForMs(resetButtonMask, config.lineName,
-                                        polarizedvalue, durationMs);
+        return setMaskedGPIOOutputForMs(resetButtonMask, config.lineName, value,
+                                        durationMs);
     }
 
     // No mask set, so request and set the GPIO normally
     gpiod::line gpioLine;
-    if (!setGPIOOutput(config.lineName, polarizedvalue, gpioLine))
+    if (!setGPIOOutput(config.lineName, value, gpioLine))
     {
         return -1;
     }
     const std::string name = config.lineName;
 
     gpioAssertTimer.expires_after(std::chrono::milliseconds(durationMs));
-    gpioAssertTimer.async_wait([gpioLine, polarizedvalue,
+    gpioAssertTimer.async_wait([gpioLine, value,
                                 name](const boost::system::error_code ec) {
         // Set the GPIO line back to the opposite value
-        gpioLine.set_value(!polarizedvalue);
+        gpioLine.set_value(!value);
         std::string logMsg = name + " released";
         phosphor::logging::log<phosphor::logging::level::INFO>(logMsg.c_str());
         if (ec)
@@ -1242,9 +1233,14 @@
     return 0;
 }
 
+static int assertGPIOForMs(const ConfigData& config, const int durationMs)
+{
+    return setGPIOOutputForMs(config, config.polarity, durationMs);
+}
+
 static void powerOn()
 {
-    setGPIOOutputForMs(powerOutConfig, 0, TimerMap["PowerPulseMs"]);
+    assertGPIOForMs(powerOutConfig, TimerMap["PowerPulseMs"]);
 }
 #ifdef CHASSIS_SYSTEM_RESET
 static int slotPowerOn()
@@ -1330,12 +1326,12 @@
 #endif
 static void gracefulPowerOff()
 {
-    setGPIOOutputForMs(powerOutConfig, 0, TimerMap["PowerPulseMs"]);
+    assertGPIOForMs(powerOutConfig, TimerMap["PowerPulseMs"]);
 }
 
 static void forcePowerOff()
 {
-    if (setGPIOOutputForMs(powerOutConfig, 0, TimerMap["ForceOffPulseMs"]) < 0)
+    if (assertGPIOForMs(powerOutConfig, TimerMap["ForceOffPulseMs"]) < 0)
     {
         return;
     }
@@ -1376,7 +1372,7 @@
 
 static void reset()
 {
-    setGPIOOutputForMs(resetOutConfig, 0, TimerMap["ResetPulseMs"]);
+    assertGPIOForMs(resetOutConfig, TimerMap["ResetPulseMs"]);
 }
 
 static void gracefulPowerOffTimerStart()