Add support for FLAG_ACTIVE_LOW in libgpiod

During the port to meson, this parameter needs to be set to avoid a
build error. Instead of defaulting to zero, it makes sense to use
FLAG_ACTIVE_LOW where appropriate.

The benefits are that get_value() returns the asserted status of the
GPIO which simplifies checking for events, and 'gpioinfo' now shows
which GPIO lines are configured as active-low.

Tested:
Confirmed that both active-high and active-low events are detected
correctly.

Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Change-Id: I515bee9f29b64bfd63f125be9676aaaacbd855c5
diff --git a/include/error_monitors/base_gpio_monitor.hpp b/include/error_monitors/base_gpio_monitor.hpp
index 63be49c..74e1f88 100644
--- a/include/error_monitors/base_gpio_monitor.hpp
+++ b/include/error_monitors/base_gpio_monitor.hpp
@@ -35,7 +35,6 @@
 class BaseGPIOMonitor : public host_error_monitor::base_monitor::BaseMonitor
 {
     AssertValue assertValue;
-    int assertEvent;
 
     gpiod::line line;
     boost::asio::posix::stream_descriptor event;
@@ -54,8 +53,11 @@
 
         try
         {
-            line.request(
-                {"host-error-monitor", gpiod::line_request::EVENT_BOTH_EDGES});
+            line.request({"host-error-monitor",
+                          gpiod::line_request::EVENT_BOTH_EDGES,
+                          assertValue == AssertValue::highAssert
+                              ? 0
+                              : gpiod::line_request::FLAG_ACTIVE_LOW});
         }
         catch (std::exception&)
         {
@@ -82,7 +84,7 @@
             std::cerr << "Checking " << signalName << " state\n";
         }
 
-        return (line.get_value() == static_cast<int>(assertValue));
+        return (line.get_value());
     }
 
     void checkEvent(bool assertEvent)
@@ -146,7 +148,10 @@
 
                 gpiod::line_event gpioLineEvent = line.event_read();
 
-                checkEvent(gpioLineEvent.event_type == assertEvent);
+                // With FLAG_ACTIVE_LOW enabled, both active-high and active-low
+                // signals have a RISING_EDGE event when asserted
+                checkEvent(gpioLineEvent.event_type ==
+                           gpiod::line_event::RISING_EDGE);
                 waitForEvent();
             });
     }
@@ -169,10 +174,6 @@
         BaseMonitor(io, conn, signalName),
         event(io), assertValue(assertValue)
     {
-        assertEvent = (assertValue == AssertValue::lowAssert)
-                          ? gpiod::line_event::FALLING_EDGE
-                          : gpiod::line_event::RISING_EDGE;
-
         if (!requestEvents())
         {
             return;
diff --git a/include/error_monitors/base_gpio_poll_monitor.hpp b/include/error_monitors/base_gpio_poll_monitor.hpp
index 3d79f18..8b4fe1f 100644
--- a/include/error_monitors/base_gpio_poll_monitor.hpp
+++ b/include/error_monitors/base_gpio_poll_monitor.hpp
@@ -59,8 +59,11 @@
 
         try
         {
-            line.request(
-                {"host-error-monitor", gpiod::line_request::EVENT_BOTH_EDGES});
+            line.request({"host-error-monitor",
+                          gpiod::line_request::EVENT_BOTH_EDGES,
+                          assertValue == AssertValue::highAssert
+                              ? 0
+                              : gpiod::line_request::FLAG_ACTIVE_LOW});
         }
         catch (std::exception&)
         {
@@ -96,7 +99,7 @@
             return false;
         }
 
-        return (line.get_value() == static_cast<int>(assertValue));
+        return (line.get_value());
     }
 
   public:
diff --git a/include/error_monitors/cpld_crc_monitor.hpp b/include/error_monitors/cpld_crc_monitor.hpp
index 3732f8e..cd5eb24 100644
--- a/include/error_monitors/cpld_crc_monitor.hpp
+++ b/include/error_monitors/cpld_crc_monitor.hpp
@@ -55,8 +55,9 @@
         // Request GPIO input
         try
         {
-            cpuPresenceLine.request(
-                {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT});
+            cpuPresenceLine.request({"host-error-monitor",
+                                     gpiod::line_request::DIRECTION_INPUT,
+                                     gpiod::line_request::FLAG_ACTIVE_LOW});
         }
         catch (std::exception&)
         {
@@ -64,8 +65,7 @@
             return false;
         }
 
-        // CPU presence is low-assert
-        cpuPresent = !cpuPresenceLine.get_value();
+        cpuPresent = cpuPresenceLine.get_value();
 
         return true;
     }
diff --git a/include/error_monitors/cpu_mismatch_monitor.hpp b/include/error_monitors/cpu_mismatch_monitor.hpp
index c378f75..2d65767 100644
--- a/include/error_monitors/cpu_mismatch_monitor.hpp
+++ b/include/error_monitors/cpu_mismatch_monitor.hpp
@@ -53,8 +53,9 @@
         // Request GPIO input
         try
         {
-            cpuMismatchLine.request(
-                {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT});
+            cpuMismatchLine.request({"host-error-monitor",
+                                     gpiod::line_request::DIRECTION_INPUT,
+                                     0}); // 0 indicates ACTIVE_HIGH
         }
         catch (std::exception&)
         {
@@ -72,7 +73,7 @@
             std::cerr << "Checking " << signalName << " state\n";
         }
 
-        return (cpuMismatchLine.get_value() == 1);
+        return (cpuMismatchLine.get_value());
     }
 
     void cpuMismatchAssertHandler()
diff --git a/include/error_monitors/cpu_presence_monitor.hpp b/include/error_monitors/cpu_presence_monitor.hpp
index 3625a88..2866d48 100644
--- a/include/error_monitors/cpu_presence_monitor.hpp
+++ b/include/error_monitors/cpu_presence_monitor.hpp
@@ -62,8 +62,9 @@
         // Request GPIO input
         try
         {
-            cpuPresenceLine.request(
-                {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT});
+            cpuPresenceLine.request({"host-error-monitor",
+                                     gpiod::line_request::DIRECTION_INPUT,
+                                     gpiod::line_request::FLAG_ACTIVE_LOW});
         }
         catch (const std::exception&)
         {
@@ -71,8 +72,7 @@
             return false;
         }
 
-        // CPU presence is low-assert
-        cpuPresent = !cpuPresenceLine.get_value();
+        cpuPresent = cpuPresenceLine.get_value();
 
         return true;
     }