blob: 039a102b18b750b8411e52f0e040945b83e1fc3e [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
Andy YF Wang40247cc2019-09-06 18:30:56 +080018#include "mihawk-cpld.hpp"
Matt Spinler56d90a82017-08-14 14:05:11 -050019#include "pgood_monitor.hpp"
Matt Spinler70849272017-08-22 09:14:40 -050020#include "runtime_monitor.hpp"
Matt Spinlerb2d72512017-08-22 09:07:01 -050021#include "ucd90160.hpp"
Matt Spinlerafb39132017-08-14 13:53:07 -050022
George Liu130ac972023-08-14 18:01:59 +080023#include <CLI/CLI.hpp>
Matt Spinlerf0f02b92018-10-25 16:12:43 -050024#include <sdeventplus/event.hpp>
25
Brandon Wymand1bc4ce2019-12-13 14:20:34 -060026#include <chrono>
27#include <iostream>
28
Lei YUab093322019-10-09 16:43:22 +080029using namespace phosphor::power;
Matt Spinler56d90a82017-08-14 14:05:11 -050030using namespace phosphor::logging;
Matt Spinlerafb39132017-08-14 13:53:07 -050031
32int main(int argc, char** argv)
33{
George Liu130ac972023-08-14 18:01:59 +080034 CLI::App app{"Phosphor sequencer monitor"};
35 std::string action{};
36 std::string interVal{};
Matt Spinlerafb39132017-08-14 13:53:07 -050037
George Liu130ac972023-08-14 18:01:59 +080038 std::vector<std::string> actionTypes = {"pgood-monitor", "runtime-monitor"};
39 app.add_option("-a,--action", action,
40 "Action: pgood-monitor or runtime-monitor\n")
41 ->required()
42 ->transform(CLI::IsMember(actionTypes));
43 app.add_option("-i,--interval", interVal,
44 "Interval in milliseconds:\n"
45 "PGOOD monitor: time allowed for PGOOD to come up\n"
46 "Runtime monitor: polling interval.\n")
47 ->required();
48
49 try
Matt Spinlerafb39132017-08-14 13:53:07 -050050 {
George Liu130ac972023-08-14 18:01:59 +080051 app.parse(argc, argv);
52 }
53 catch (CLI::Error& e)
54 {
55 return app.exit(e);
Matt Spinlerafb39132017-08-14 13:53:07 -050056 }
57
George Liu130ac972023-08-14 18:01:59 +080058 auto i = strtoul(interVal.c_str(), nullptr, 10);
Matt Spinlerafb39132017-08-14 13:53:07 -050059 if (i == 0)
60 {
61 std::cerr << "Invalid interval value\n";
62 exit(EXIT_FAILURE);
63 }
64
Matt Spinler78c5c2b2017-12-14 10:42:07 -060065 std::chrono::milliseconds interval{i};
Matt Spinlerafb39132017-08-14 13:53:07 -050066
Matt Spinlerf0f02b92018-10-25 16:12:43 -050067 auto event = sdeventplus::Event::get_default();
Matt Spinler56d90a82017-08-14 14:05:11 -050068 auto bus = sdbusplus::bus::new_default();
69 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
70
Andy YF Wang40247cc2019-09-06 18:30:56 +080071 auto device = std::make_unique<SEQUENCER>(0, bus);
Matt Spinlerb2d72512017-08-22 09:07:01 -050072
Matt Spinler70849272017-08-22 09:14:40 -050073 std::unique_ptr<DeviceMonitor> monitor;
Matt Spinler56d90a82017-08-14 14:05:11 -050074
Matt Spinler70849272017-08-22 09:14:40 -050075 if (action == "pgood-monitor")
76 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050077 // If PGOOD doesn't turn on within a certain
78 // time, analyze the device for errors
79 monitor = std::make_unique<PGOODMonitor>(std::move(device), bus, event,
80 interval);
Matt Spinler70849272017-08-22 09:14:40 -050081 }
Matt Spinlerf0f02b92018-10-25 16:12:43 -050082 else // runtime-monitor
Matt Spinler70849272017-08-22 09:14:40 -050083 {
Matt Spinlerf0f02b92018-10-25 16:12:43 -050084 // Continuously monitor this device both by polling
85 // and on 'power lost' signals.
86 monitor = std::make_unique<RuntimeMonitor>(std::move(device), bus,
87 event, interval);
Matt Spinler70849272017-08-22 09:14:40 -050088 }
89
90 return monitor->run();
Matt Spinlerafb39132017-08-14 13:53:07 -050091}