blob: 838eae33853e2105f6f0028e50d319de3b73a565 [file] [log] [blame]
Ben Tyner9ae5ca42020-02-28 13:13:50 -06001#include <libpdbg.h>
2
Ben Tyner46b5e2b2022-02-16 13:11:23 -06003#include <attn/attention.hpp>
Ben Tyner3fb52e52020-03-31 10:10:07 -05004#include <attn/attn_config.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06005#include <attn/attn_handler.hpp>
Ben Tyner3fb52e52020-03-31 10:10:07 -05006#include <cli.hpp>
Ben Tyner46b5e2b2022-02-16 13:11:23 -06007#include <util/trace.hpp>
8
9#include <vector>
10
11namespace attn
12{
13// these are in the attn_lib but not all exposed via headers
14int handleSpecial(Attention* i_attention);
15int handleCheckstop(Attention* i_attention);
16int handleVital(Attention* i_attention);
17} // namespace attn
Ben Tyner9ae5ca42020-02-28 13:13:50 -060018
Ben Tyner3fb52e52020-03-31 10:10:07 -050019/** @brief Attention handler test application */
20int main(int argc, char* argv[])
Ben Tyner9ae5ca42020-02-28 13:13:50 -060021{
22 int rc = 0; // return code
23
24 // initialize pdbg targets
25 pdbg_targets_init(nullptr);
26
Ben Tyner3fb52e52020-03-31 10:10:07 -050027 // create attention handler config object
Ben Tyner72feadc2020-04-06 12:57:31 -050028 attn::Config attnConfig;
29
30 // convert cmd line args to config values
31 parseConfig(argv, argv + argc, &attnConfig);
Ben Tyner3fb52e52020-03-31 10:10:07 -050032
Ben Tyner9ae5ca42020-02-28 13:13:50 -060033 // exercise attention gpio event path
Ben Tyner72feadc2020-04-06 12:57:31 -050034 attn::attnHandler(&attnConfig);
Ben Tyner9ae5ca42020-02-28 13:13:50 -060035
Ben Tyner46b5e2b2022-02-16 13:11:23 -060036 // 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) {
Patrick Williams27dd6362023-05-10 07:51:20 -050065 trace::inf("calling handler");
66 attention.handle();
67 });
Ben Tyner46b5e2b2022-02-16 13:11:23 -060068 }
69
Ben Tyner9ae5ca42020-02-28 13:13:50 -060070 return rc;
71}