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 */ 16*40247cceSAndy YF Wang #include "config.h" 17*40247cceSAndy YF Wang 18afb39132SMatt Spinler #include "argument.hpp" 19*40247cceSAndy YF Wang #include "mihawk-cpld.hpp" 2056d90a89SMatt Spinler #include "pgood_monitor.hpp" 217084927eSMatt Spinler #include "runtime_monitor.hpp" 22b2d72511SMatt Spinler #include "ucd90160.hpp" 23afb39132SMatt Spinler 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 33afb39132SMatt Spinler int main(int argc, char** argv) 34afb39132SMatt Spinler { 35afb39132SMatt Spinler ArgumentParser args{argc, argv}; 36afb39132SMatt Spinler auto action = args["action"]; 37afb39132SMatt Spinler 387084927eSMatt Spinler if ((action != "pgood-monitor") && (action != "runtime-monitor")) 39afb39132SMatt Spinler { 40afb39132SMatt Spinler std::cerr << "Invalid action\n"; 41afb39132SMatt Spinler args.usage(argv); 42afb39132SMatt Spinler exit(EXIT_FAILURE); 43afb39132SMatt Spinler } 44afb39132SMatt Spinler 45afb39132SMatt Spinler auto i = strtoul(args["interval"].c_str(), nullptr, 10); 46afb39132SMatt Spinler if (i == 0) 47afb39132SMatt Spinler { 48afb39132SMatt Spinler std::cerr << "Invalid interval value\n"; 49afb39132SMatt Spinler exit(EXIT_FAILURE); 50afb39132SMatt Spinler } 51afb39132SMatt Spinler 5278c5c2b0SMatt Spinler std::chrono::milliseconds interval{i}; 53afb39132SMatt Spinler 54e5a8b473SWilliam A. Kennington III auto event = sdeventplus::Event::get_default(); 5556d90a89SMatt Spinler auto bus = sdbusplus::bus::new_default(); 5656d90a89SMatt Spinler bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 5756d90a89SMatt Spinler 58*40247cceSAndy YF Wang auto device = std::make_unique<SEQUENCER>(0, bus); 59b2d72511SMatt Spinler 607084927eSMatt Spinler std::unique_ptr<DeviceMonitor> monitor; 6156d90a89SMatt Spinler 627084927eSMatt Spinler if (action == "pgood-monitor") 637084927eSMatt Spinler { 647084927eSMatt Spinler // If PGOOD doesn't turn on within a certain 657084927eSMatt Spinler // time, analyze the device for errors 66f0f02b9aSMatt Spinler monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event, 67f0f02b9aSMatt Spinler interval); 687084927eSMatt Spinler } 697084927eSMatt Spinler else // runtime-monitor 707084927eSMatt Spinler { 717084927eSMatt Spinler // Continuously monitor this device both by polling 727084927eSMatt Spinler // and on 'power lost' signals. 73f0f02b9aSMatt Spinler monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus, 74f0f02b9aSMatt Spinler event, interval); 757084927eSMatt Spinler } 767084927eSMatt Spinler 777084927eSMatt Spinler return monitor->run(); 78afb39132SMatt Spinler } 79