Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 1 | #include <libpdbg.h> |
| 2 | |
Ben Tyner | 46b5e2b | 2022-02-16 13:11:23 -0600 | [diff] [blame] | 3 | #include <attn/attention.hpp> |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 4 | #include <attn/attn_config.hpp> |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 5 | #include <attn/attn_handler.hpp> |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 6 | #include <cli.hpp> |
Ben Tyner | 46b5e2b | 2022-02-16 13:11:23 -0600 | [diff] [blame] | 7 | #include <util/trace.hpp> |
| 8 | |
| 9 | #include <vector> |
| 10 | |
| 11 | namespace attn |
| 12 | { |
| 13 | // these are in the attn_lib but not all exposed via headers |
| 14 | int handleSpecial(Attention* i_attention); |
| 15 | int handleCheckstop(Attention* i_attention); |
| 16 | int handleVital(Attention* i_attention); |
| 17 | } // namespace attn |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 18 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 19 | /** @brief Attention handler test application */ |
| 20 | int main(int argc, char* argv[]) |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 21 | { |
| 22 | int rc = 0; // return code |
| 23 | |
| 24 | // initialize pdbg targets |
| 25 | pdbg_targets_init(nullptr); |
| 26 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 27 | // create attention handler config object |
Ben Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 28 | attn::Config attnConfig; |
| 29 | |
| 30 | // convert cmd line args to config values |
| 31 | parseConfig(argv, argv + argc, &attnConfig); |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 32 | |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 33 | // exercise attention gpio event path |
Ben Tyner | 72feadc | 2020-04-06 12:57:31 -0500 | [diff] [blame] | 34 | attn::attnHandler(&attnConfig); |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 35 | |
Ben Tyner | 46b5e2b | 2022-02-16 13:11:23 -0600 | [diff] [blame] | 36 | // Get first enabled proc for testing |
| 37 | pdbg_target* target = nullptr; |
| 38 | pdbg_for_each_class_target("proc", target) |
| 39 | { |
| 40 | trace::inf("proc: %u", pdbg_target_index(target)); |
| 41 | if (PDBG_TARGET_ENABLED == pdbg_target_probe(target)) |
| 42 | { |
| 43 | trace::inf("target enabled"); |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Exercise special, checkstop and vital attention handler paths |
| 49 | if ((nullptr != target) && |
| 50 | (PDBG_TARGET_ENABLED == pdbg_target_probe(target))) |
| 51 | { |
| 52 | std::vector<attn::Attention> attentions; |
| 53 | |
| 54 | attentions.emplace_back(attn::Attention::AttentionType::Special, |
| 55 | attn::handleSpecial, target, &attnConfig); |
| 56 | |
| 57 | attentions.emplace_back(attn::Attention::AttentionType::Checkstop, |
| 58 | attn::handleCheckstop, target, &attnConfig); |
| 59 | |
| 60 | attentions.emplace_back(attn::Attention::AttentionType::Vital, |
| 61 | attn::handleVital, target, &attnConfig); |
| 62 | |
| 63 | std::for_each(std::begin(attentions), std::end(attentions), |
| 64 | [](attn::Attention attention) { |
| 65 | trace::inf("calling handler"); |
| 66 | attention.handle(); |
| 67 | }); |
| 68 | } |
| 69 | |
Ben Tyner | 9ae5ca4 | 2020-02-28 13:13:50 -0600 | [diff] [blame] | 70 | return rc; |
| 71 | } |