blob: c0e2451f4a484d1b1e0475debeb33c15a483643f [file] [log] [blame]
Ben Tyneref320152020-01-09 10:31:23 -06001#include <libpdbg.h>
2
3#include <attn_handler.hpp>
Ben Tyner73ac3682020-01-09 10:46:47 -06004#include <attn_monitor.hpp>
Ben Tyneref320152020-01-09 10:31:23 -06005
Ben Tyner970fd4f2020-02-19 13:46:42 -06006#include <algorithm>
7
8/*
9 * @brief Search the command line arguments for an option
10 *
11 * @param i_begin command line args vector begin
12 * @param i_end command line args vector end
13 * @param i_option configuration option to look for
14 *
15 * @return true = option found on command line
16 */
17bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
18{
19 return (i_end != std::find(i_begin, i_end, i_option));
20}
21
22/*
23 * @brief Search the command line arguments for a setting value
24 *
25 * @param i_begin command line args vector begin
26 * @param i_end command line args vectory end
27 * @param i_setting configuration setting to look for
28 *
29 * @return value of the setting or 0 if setting not found or value not given
30 */
31char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
32{
33 char** value = std::find(i_begin, i_end, i_setting);
34 if (value != i_end && ++value != i_end)
35 {
36 return *value;
37 }
38 return 0; // nullptr
39}
40
Ben Tyneref320152020-01-09 10:31:23 -060041/**
42 * @brief Attention handler application main()
43 *
44 * This is the main interface to the Attention handler application, it will
45 * initialize the libgpd targets and start a gpio mointor.
46 *
Ben Tyner970fd4f2020-02-19 13:46:42 -060047 * Command line arguments:
48 *
49 * breakpoints - enables breakpoint special attn handling
50 *
Ben Tyneref320152020-01-09 10:31:23 -060051 * @return 0 = success
52 */
Ben Tyner970fd4f2020-02-19 13:46:42 -060053int main(int argc, char* argv[])
Ben Tyneref320152020-01-09 10:31:23 -060054{
55 int rc = 0; // return code
56
Ben Tyner73ac3682020-01-09 10:46:47 -060057 gpiod_line* line; // gpio line to monitor
58
59 boost::asio::io_service io; // async io monitoring service
60
Ben Tyneref320152020-01-09 10:31:23 -060061 // initialize pdbg targets
62 pdbg_targets_init(nullptr);
63
Ben Tyner73ac3682020-01-09 10:46:47 -060064 // GPIO line configuration (falling edge, active low)
65 struct gpiod_line_request_config config
66 {
67 "attention", GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, 0
68 };
69
70 // get handle to attention GPIO line
71 line = gpiod_line_get("gpiochip0", 74);
72
73 if (nullptr == line)
74 {
75 rc = 1; // error
76 }
77 else
78 {
Ben Tyner970fd4f2020-02-19 13:46:42 -060079 // Check command line args for breakpoint handling enable option
80 bool bp_enable = getCliOption(argv, argv + argc, "-breakpoints");
81
Ben Tyner73ac3682020-01-09 10:46:47 -060082 // Creating a vector of one gpio to monitor
83 std::vector<std::unique_ptr<attn::AttnMonitor>> gpios;
Ben Tyner970fd4f2020-02-19 13:46:42 -060084 gpios.push_back(
85 std::make_unique<attn::AttnMonitor>(line, config, io, bp_enable));
Ben Tyner73ac3682020-01-09 10:46:47 -060086
87 io.run(); // start GPIO monitor
88 }
89
Ben Tyneref320152020-01-09 10:31:23 -060090 return rc;
91}