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