1afb39132SMatt Spinler /**
2afb39132SMatt Spinler * Copyright © 2017 IBM Corporation
3afb39132SMatt Spinler *
4afb39132SMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License");
5afb39132SMatt Spinler * you may not use this file except in compliance with the License.
6afb39132SMatt Spinler * You may obtain a copy of the License at
7afb39132SMatt Spinler *
8afb39132SMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0
9afb39132SMatt Spinler *
10afb39132SMatt Spinler * Unless required by applicable law or agreed to in writing, software
11afb39132SMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS,
12afb39132SMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13afb39132SMatt Spinler * See the License for the specific language governing permissions and
14afb39132SMatt Spinler * limitations under the License.
15afb39132SMatt Spinler */
1640247cceSAndy YF Wang #include "config.h"
1740247cceSAndy YF Wang
1840247cceSAndy YF Wang #include "mihawk-cpld.hpp"
1956d90a89SMatt Spinler #include "pgood_monitor.hpp"
207084927eSMatt Spinler #include "runtime_monitor.hpp"
21b2d72511SMatt Spinler #include "ucd90160.hpp"
22afb39132SMatt Spinler
23*130ac97cSGeorge Liu #include <CLI/CLI.hpp>
24f0f02b9aSMatt Spinler #include <phosphor-logging/log.hpp>
25f0f02b9aSMatt Spinler #include <sdeventplus/event.hpp>
26f0f02b9aSMatt Spinler
27d1bc4cecSBrandon Wyman #include <chrono>
28d1bc4cecSBrandon Wyman #include <iostream>
29d1bc4cecSBrandon Wyman
30ab093328SLei YU using namespace phosphor::power;
3156d90a89SMatt Spinler using namespace phosphor::logging;
32afb39132SMatt Spinler
main(int argc,char ** argv)33afb39132SMatt Spinler int main(int argc, char** argv)
34afb39132SMatt Spinler {
35*130ac97cSGeorge Liu CLI::App app{"Phosphor sequencer monitor"};
36*130ac97cSGeorge Liu std::string action{};
37*130ac97cSGeorge Liu std::string interVal{};
38afb39132SMatt Spinler
39*130ac97cSGeorge Liu std::vector<std::string> actionTypes = {"pgood-monitor", "runtime-monitor"};
40*130ac97cSGeorge Liu app.add_option("-a,--action", action,
41*130ac97cSGeorge Liu "Action: pgood-monitor or runtime-monitor\n")
42*130ac97cSGeorge Liu ->required()
43*130ac97cSGeorge Liu ->transform(CLI::IsMember(actionTypes));
44*130ac97cSGeorge Liu app.add_option("-i,--interval", interVal,
45*130ac97cSGeorge Liu "Interval in milliseconds:\n"
46*130ac97cSGeorge Liu "PGOOD monitor: time allowed for PGOOD to come up\n"
47*130ac97cSGeorge Liu "Runtime monitor: polling interval.\n")
48*130ac97cSGeorge Liu ->required();
49*130ac97cSGeorge Liu
50*130ac97cSGeorge Liu try
51afb39132SMatt Spinler {
52*130ac97cSGeorge Liu app.parse(argc, argv);
53*130ac97cSGeorge Liu }
54*130ac97cSGeorge Liu catch (CLI::Error& e)
55*130ac97cSGeorge Liu {
56*130ac97cSGeorge Liu return app.exit(e);
57afb39132SMatt Spinler }
58afb39132SMatt Spinler
59*130ac97cSGeorge Liu auto i = strtoul(interVal.c_str(), nullptr, 10);
60afb39132SMatt Spinler if (i == 0)
61afb39132SMatt Spinler {
62afb39132SMatt Spinler std::cerr << "Invalid interval value\n";
63afb39132SMatt Spinler exit(EXIT_FAILURE);
64afb39132SMatt Spinler }
65afb39132SMatt Spinler
6678c5c2b0SMatt Spinler std::chrono::milliseconds interval{i};
67afb39132SMatt Spinler
68e5a8b473SWilliam A. Kennington III auto event = sdeventplus::Event::get_default();
6956d90a89SMatt Spinler auto bus = sdbusplus::bus::new_default();
7056d90a89SMatt Spinler bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
7156d90a89SMatt Spinler
7240247cceSAndy YF Wang auto device = std::make_unique<SEQUENCER>(0, bus);
73b2d72511SMatt Spinler
747084927eSMatt Spinler std::unique_ptr<DeviceMonitor> monitor;
7556d90a89SMatt Spinler
767084927eSMatt Spinler if (action == "pgood-monitor")
777084927eSMatt Spinler {
787084927eSMatt Spinler // If PGOOD doesn't turn on within a certain
797084927eSMatt Spinler // time, analyze the device for errors
80f0f02b9aSMatt Spinler monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event,
81f0f02b9aSMatt Spinler interval);
827084927eSMatt Spinler }
837084927eSMatt Spinler else // runtime-monitor
847084927eSMatt Spinler {
857084927eSMatt Spinler // Continuously monitor this device both by polling
867084927eSMatt Spinler // and on 'power lost' signals.
87f0f02b9aSMatt Spinler monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus,
88f0f02b9aSMatt Spinler event, interval);
897084927eSMatt Spinler }
907084927eSMatt Spinler
917084927eSMatt Spinler return monitor->run();
92afb39132SMatt Spinler }
93