Adding PFR Redfish event log support.

This commit adds the support to read cpld
for any events and log them in Redfish events.
There are 3 Types are events logged,
1) Platform firmware panic events
2) Platform firmware recovery events
3) Platforms firmware error code events

Tested:
Restarted BMC, performed power operation on/off etc.. and
verified the event mointor/timer star and stop functionality.
Also verified the redfish event logs using postman tool.
URI: /redfish/v1/Systems/system/LogServices/EventLog/Entries
METHOD: GET

Change-Id: Icd9793d637121621933f84520b7e70fa66c16364
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/libpfr/src/pfr.cpp b/libpfr/src/pfr.cpp
index 59929a2..1ad98b2 100644
--- a/libpfr/src/pfr.cpp
+++ b/libpfr/src/pfr.cpp
@@ -140,5 +140,51 @@
     }
 }
 
+int readCpldReg(const ActionType& action, uint8_t value)
+{
+    uint8_t cpldReg;
+
+    switch (action)
+    {
+        case (ActionType::recoveryCount):
+            cpldReg = recoveryCount;
+            break;
+        case (ActionType::recoveryReason):
+            cpldReg = lastRecoveryReason;
+            break;
+        case (ActionType::panicCount):
+            cpldReg = panicEventCount;
+            break;
+        case (ActionType::panicReason):
+            cpldReg = panicEventReason;
+            break;
+        case (ActionType::majorError):
+            cpldReg = majorErrorCode;
+            break;
+        case (ActionType::minorError):
+            cpldReg = minorErrorCode;
+            break;
+
+        default:
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "Invalid CPLD read action.");
+            return -1;
+    }
+
+    try
+    {
+        I2CFile cpldDev(i2cBusNumber, i2cSlaveAddress, O_RDWR | O_CLOEXEC);
+        value = cpldDev.i2cReadByteData(cpldReg);
+        return 0;
+    }
+    catch (const std::exception& e)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Exception caught in readCpldReg.",
+            phosphor::logging::entry("MSG=%s", e.what()));
+        return -1;
+    }
+}
+
 } // namespace pfr
 } // namespace intel