blob: 72f96fb51937a1323e4077c386bbc867182451f1 [file] [log] [blame]
Matt Spinlerafb39132017-08-14 13:53:07 -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 */
Andy YF Wang40247cc2019-09-06 18:30:56 +080016#include "config.h"
17
Matt Spinlerafb39132017-08-14 13:53:07 -050018#include "argument.hpp"
Andy YF Wang40247cc2019-09-06 18:30:56 +080019#include "mihawk-cpld.hpp"
Matt Spinler56d90a82017-08-14 14:05:11 -050020#include "pgood_monitor.hpp"
Matt Spinler70849272017-08-22 09:14:40 -050021#include "runtime_monitor.hpp"
Matt Spinlerb2d72512017-08-22 09:07:01 -050022#include "ucd90160.hpp"
Matt Spinlerafb39132017-08-14 13:53:07 -050023
Matt Spinlerf0f02b92018-10-25 16:12:43 -050024#include <phosphor-logging/log.hpp>
25#include <sdeventplus/event.hpp>
26
Brandon Wymand1bc4ce2019-12-13 14:20:34 -060027#include <chrono>
28#include <iostream>
29
Lei YUab093322019-10-09 16:43:22 +080030using namespace phosphor::power;
Matt Spinler56d90a82017-08-14 14:05:11 -050031using namespace phosphor::logging;
Matt Spinlerafb39132017-08-14 13:53:07 -050032
33int main(int argc, char** argv)
34{
35 ArgumentParser args{argc, argv};
36 auto action = args["action"];
37
Matt Spinler70849272017-08-22 09:14:40 -050038 if ((action != "pgood-monitor") && (action != "runtime-monitor"))
Matt Spinlerafb39132017-08-14 13:53:07 -050039 {
40 std::cerr << "Invalid action\n";
41 args.usage(argv);
42 exit(EXIT_FAILURE);
43 }
44
45 auto i = strtoul(args["interval"].c_str(), nullptr, 10);
46 if (i == 0)
47 {
48 std::cerr << "Invalid interval value\n";
49 exit(EXIT_FAILURE);
50 }
51
Matt Spinler78c5c2b2017-12-14 10:42:07 -060052 std::chrono::milliseconds interval{i};
Matt Spinlerafb39132017-08-14 13:53:07 -050053
Matt Spinlerf0f02b92018-10-25 16:12:43 -050054 auto event = sdeventplus::Event::get_default();
Matt Spinler56d90a82017-08-14 14:05:11 -050055 auto bus = sdbusplus::bus::new_default();
56 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
57
Andy YF Wang40247cc2019-09-06 18:30:56 +080058 auto device = std::make_unique<SEQUENCER>(0, bus);
Matt Spinlerb2d72512017-08-22 09:07:01 -050059
Matt Spinler70849272017-08-22 09:14:40 -050060 std::unique_ptr<DeviceMonitor> monitor;
Matt Spinler56d90a82017-08-14 14:05:11 -050061
Matt Spinler70849272017-08-22 09:14:40 -050062 if (action == "pgood-monitor")
63 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050064 // If PGOOD doesn't turn on within a certain
65 // time, analyze the device for errors
66 monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event,
67 interval);
Matt Spinler70849272017-08-22 09:14:40 -050068 }
Matt Spinlerf0f02b92018-10-25 16:12:43 -050069 else // runtime-monitor
Matt Spinler70849272017-08-22 09:14:40 -050070 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050071 // Continuously monitor this device both by polling
72 // and on 'power lost' signals.
73 monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus,
74 event, interval);
Matt Spinler70849272017-08-22 09:14:40 -050075 }
76
77 return monitor->run();
Matt Spinlerafb39132017-08-14 13:53:07 -050078}