Add capability of handling GPIO initial values
The edge handling currently allows us to monitor
changes after the service has started. But, a GPIO
could have changed state when the BMC/service is
down and thus potentially missing an error condition.
To address this, two additional keys "INIT_HIGH" and
"INIT_LOW" are added. which will be called at start-up
depending on the current GPIO value.
Tested: Tested on QEMU with a test configuration
and ensured that the systemd units are called
correctly.
Change-Id: I8a6c969b9609080cf0846611831206376fd96c7d
Signed-off-by: Amithash Prasad <amithash@meta.com>
diff --git a/gpioMon.cpp b/gpioMon.cpp
index 3648556..20805cd 100644
--- a/gpioMon.cpp
+++ b/gpioMon.cpp
@@ -31,6 +31,8 @@
constexpr auto falling = "FALLING";
constexpr auto rising = "RISING";
+constexpr auto init_high = "INIT_HIGH";
+constexpr auto init_low = "INIT_LOW";
void GpioMonitor::scheduleEventHandler()
{
@@ -120,6 +122,22 @@
scheduleEventHandler();
}
+void GpioMonitor::gpioHandleInitialState(bool value)
+{
+ if (auto itr = targets.find(value ? init_high : init_low);
+ itr != targets.end())
+ {
+ auto bus = sdbusplus::bus::new_default();
+ for (const auto& tar : itr->second)
+ {
+ auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_ROOT,
+ SYSTEMD_INTERFACE, "StartUnit");
+ method.append(tar, "replace");
+ bus.call_noreply(method);
+ }
+ }
+}
+
int GpioMonitor::requestGPIOEvents()
{
/* Request an event to monitor for respected gpio line */
@@ -136,6 +154,17 @@
return -1;
}
+ int value = gpiod_line_get_value(gpioLine);
+ if (value < 0)
+ {
+ lg2::error("Failed to get value for {GPIO} Error: {ERROR}", "GPIO",
+ gpioLineMsg, "ERROR", strerror(errno));
+ }
+ else
+ {
+ gpioHandleInitialState(value != 0);
+ }
+
lg2::info("{GPIO} monitoring started", "GPIO", gpioLineMsg);
/* Assign line fd to descriptor for monitoring */