1 #pragma once 2 3 #include <sdbusplus/bus.hpp> 4 #include <sdbusplus/server.hpp> 5 #include "event.hpp" 6 #include "timer.hpp" 7 8 namespace witherspoon 9 { 10 namespace power 11 { 12 13 /** 14 * @class PGOODMonitor 15 * 16 * Monitors PGOOD and creates an error if it doesn't come on in time. 17 * 18 * The run() function is designed to be called right after the 19 * power sequencer device is told to kick off a power on. 20 * 21 * Future commits will analyze the power sequencer chip for errors 22 * on a PGOOD fail. 23 */ 24 class PGOODMonitor 25 { 26 public: 27 28 PGOODMonitor() = delete; 29 ~PGOODMonitor() = default; 30 PGOODMonitor(const PGOODMonitor&) = delete; 31 PGOODMonitor& operator=(const PGOODMonitor&) = delete; 32 PGOODMonitor(PGOODMonitor&&) = delete; 33 PGOODMonitor& operator=(PGOODMonitor&&) = delete; 34 35 /** 36 * Constructor 37 * 38 * @param[in] b - D-Bus bus object 39 * @param[in] e - event object 40 * @param[in] t - time to allow PGOOD to come up 41 */ 42 PGOODMonitor(sdbusplus::bus::bus& b, 43 event::Event& e, 44 std::chrono::seconds& t) : 45 bus(b), 46 event(e), 47 interval(t), 48 timer(e, [this]() { this->analyze(); }) 49 { 50 } 51 52 /** 53 * The timer callback. 54 * 55 * Creates a PGOOD failure error log. 56 */ 57 void analyze(); 58 59 /** 60 * Waits a specified amount of time for PGOOD to 61 * come on, and if it fails to come on in that time 62 * an error log will be created. 63 * 64 * @return - the return value from sd_event_loop() 65 */ 66 int run(); 67 68 private: 69 70 /** 71 * Enables the properties changed signal callback 72 * on the power object so we can tell when PGOOD 73 * comes on. 74 */ 75 void startListening(); 76 77 /** 78 * The callback function for the properties changed 79 * signal. 80 */ 81 void propertyChanged(); 82 83 /** 84 * Returns true if the system has been turned on 85 * but PGOOD isn't up yet. 86 */ 87 bool pgoodPending(); 88 89 /** 90 * Used to break out of the event loop in run() 91 */ 92 void exitEventLoop(); 93 94 /** 95 * The D-Bus object 96 */ 97 sdbusplus::bus::bus& bus; 98 99 /** 100 * The match object for the properties changed signal 101 */ 102 std::unique_ptr<sdbusplus::bus::match_t> match; 103 104 /** 105 * The sd_event structure used by the timer 106 */ 107 event::Event& event; 108 109 /** 110 * The amount of time to wait for PGOOD to turn on 111 */ 112 std::chrono::seconds interval; 113 114 /** 115 * The timer used to do the callback 116 */ 117 Timer timer; 118 }; 119 120 } 121 } 122