blob: 4c64c52f06c41c0c4714d52a103eb3f6f307d85c [file] [log] [blame]
Matt Spinler70849272017-08-22 09:14:40 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <phosphor-logging/log.hpp>
Matt Spinler45a054a2017-08-22 15:07:07 -050017#include "config.h"
Matt Spinler70849272017-08-22 09:14:40 -050018#include "runtime_monitor.hpp"
19#include "utility.hpp"
20
21namespace witherspoon
22{
23namespace power
24{
25
26using namespace phosphor::logging;
27
28int RuntimeMonitor::run()
29{
Matt Spinler45a054a2017-08-22 15:07:07 -050030#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050031 device->clearFaults();
32
33 return DeviceMonitor::run();
Matt Spinler45a054a2017-08-22 15:07:07 -050034#else
35 return EXIT_SUCCESS;
36#endif
Matt Spinler70849272017-08-22 09:14:40 -050037}
38
39void RuntimeMonitor::onPowerLost(sdbusplus::message::message& msg)
40{
41 log<level::INFO>("PGOOD failure detected. Checking for faults.");
42
43 try
44 {
45 timer.stop();
46
Matt Spinler45a054a2017-08-22 15:07:07 -050047#ifdef UCD90160_DEVICE_ACCESS
Matt Spinler70849272017-08-22 09:14:40 -050048 device->onFailure();
Matt Spinler45a054a2017-08-22 15:07:07 -050049#endif
Matt Spinler70849272017-08-22 09:14:40 -050050 //Note: This application only runs when the system has
51 //power, so it will be killed by systemd sometime shortly
52 //after this power off is issued.
53
54 util::powerOff(bus);
55 }
56 catch (std::exception& e)
57 {
58 //No need to crash
59 log<level::ERR>(e.what());
60 }
61}
62
63}
64}