1 #include <libpdbg.h> 2 3 #include <attn_handler.hpp> 4 #include <attn_monitor.hpp> 5 6 #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 */ 17 bool 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 */ 31 char* 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 41 /** 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 * 47 * Command line arguments: 48 * 49 * breakpoints - enables breakpoint special attn handling 50 * 51 * @return 0 = success 52 */ 53 int main(int argc, char* argv[]) 54 { 55 int rc = 0; // return code 56 57 gpiod_line* line; // gpio line to monitor 58 59 boost::asio::io_service io; // async io monitoring service 60 61 // initialize pdbg targets 62 pdbg_targets_init(nullptr); 63 64 // 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 { 79 // Check command line args for breakpoint handling enable option 80 bool bp_enable = getCliOption(argv, argv + argc, "-breakpoints"); 81 82 // Creating a vector of one gpio to monitor 83 std::vector<std::unique_ptr<attn::AttnMonitor>> gpios; 84 gpios.push_back( 85 std::make_unique<attn::AttnMonitor>(line, config, io, bp_enable)); 86 87 io.run(); // start GPIO monitor 88 } 89 90 return rc; 91 } 92