Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 1 | #include <libpdbg.h> |
| 2 | |
| 3 | #include <attn_handler.hpp> |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 4 | #include <attn_monitor.hpp> |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 5 | |
| 6 | /** |
| 7 | * @brief Attention handler application main() |
| 8 | * |
| 9 | * This is the main interface to the Attention handler application, it will |
| 10 | * initialize the libgpd targets and start a gpio mointor. |
| 11 | * |
| 12 | * @return 0 = success |
| 13 | */ |
| 14 | int main() |
| 15 | { |
| 16 | int rc = 0; // return code |
| 17 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 18 | gpiod_line* line; // gpio line to monitor |
| 19 | |
| 20 | boost::asio::io_service io; // async io monitoring service |
| 21 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 22 | // initialize pdbg targets |
| 23 | pdbg_targets_init(nullptr); |
| 24 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 25 | // GPIO line configuration (falling edge, active low) |
| 26 | struct gpiod_line_request_config config |
| 27 | { |
| 28 | "attention", GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, 0 |
| 29 | }; |
| 30 | |
| 31 | // get handle to attention GPIO line |
| 32 | line = gpiod_line_get("gpiochip0", 74); |
| 33 | |
| 34 | if (nullptr == line) |
| 35 | { |
| 36 | rc = 1; // error |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | // Creating a vector of one gpio to monitor |
| 41 | std::vector<std::unique_ptr<attn::AttnMonitor>> gpios; |
| 42 | gpios.push_back(std::make_unique<attn::AttnMonitor>(line, config, io)); |
| 43 | |
| 44 | io.run(); // start GPIO monitor |
| 45 | } |
| 46 | |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 47 | return rc; |
| 48 | } |