blob: 92aaa3fcf2b434d4328cc844b87b6266daa499c2 [file] [log] [blame]
Zane Shelley93b61ad2019-10-16 20:41:03 -05001#pragma once
2
Zane Shelley3a02e242020-05-08 16:25:36 -05003#include <hei_chip.hpp>
4#include <hei_types.hpp>
Zane Shelley93b61ad2019-10-16 20:41:03 -05005
6namespace libhei
7{
8
9/**
Zane Shelley6722b5b2020-05-12 22:09:04 -050010 * @brief A signature represents an active attention from a single bit position
11 * from an isolation node within a chip.
Zane Shelley93b61ad2019-10-16 20:41:03 -050012 *
13 * The isolator will gather a list of all active attentions on a chip and return
14 * a list of signatures to the user application. The user application should be
15 * able to determine what actions to take based on these signatures.
16 */
17class Signature
18{
19 public: // Constructors, destructor, assignment, etc.
Zane Shelley84533532020-06-11 15:20:50 -050020 /**
21 * @brief Default contructor.
22 *
23 * In general the default constructor should not be used, but it is needed
24 * for some STL functions.
25 */
Zane Shelleydc7baeb2020-06-11 14:28:46 -050026 Signature() = default;
27
Zane Shelley93b61ad2019-10-16 20:41:03 -050028 /**
29 * @brief Constructor from components.
30 * @param i_chip The chip containing this register.
Zane Shelley6722b5b2020-05-12 22:09:04 -050031 * @param i_id The node ID.
Zane Shelley93b61ad2019-10-16 20:41:03 -050032 * @param i_instance The instance of this register.
33 * @param i_bit The target bit within this register.
34 * @param i_attnType The attention type reported by this bit.
35 */
Zane Shelley6722b5b2020-05-12 22:09:04 -050036 Signature(const Chip& i_chip, NodeId_t i_id, Instance_t i_instance,
Zane Shelley13b182b2020-05-07 20:23:45 -050037 BitPosition_t i_bit, AttentionType_t i_attnType) :
Zane Shelley7f7a42d2019-10-28 13:28:31 -050038 iv_chip(i_chip),
39 iv_id(i_id), iv_instance(i_instance), iv_bit(i_bit),
40 iv_attnType(i_attnType)
Zane Shelley93b61ad2019-10-16 20:41:03 -050041 {}
42
43 /** @brief Destructor. */
44 ~Signature() = default;
45
46 /** @brief Copy constructor. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050047 Signature(const Signature&) = default;
Zane Shelley93b61ad2019-10-16 20:41:03 -050048
49 /** @brief Assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050050 Signature& operator=(const Signature&) = default;
Zane Shelley93b61ad2019-10-16 20:41:03 -050051
Zane Shelley7c8faa12019-10-28 22:26:28 -050052 private:
Zane Shelley13b182b2020-05-07 20:23:45 -050053 Chip iv_chip; ///< Chip containing this register.
Zane Shelley6722b5b2020-05-12 22:09:04 -050054 NodeId_t iv_id; ///< Node ID.
Zane Shelley13b182b2020-05-07 20:23:45 -050055 Instance_t iv_instance; ///< Instance of this register.
56 BitPosition_t iv_bit; ///< Target bit within this register.
57 AttentionType_t iv_attnType; ///< Attention type reported by this bit.
Zane Shelley93b61ad2019-10-16 20:41:03 -050058
59 public: // Member functions
Zane Shelley93b61ad2019-10-16 20:41:03 -050060 /** @return The chip containing this register. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050061 const Chip& getChip() const
62 {
63 return iv_chip;
64 }
Zane Shelley93b61ad2019-10-16 20:41:03 -050065
Zane Shelleyd280cca2020-11-13 17:08:24 -060066 /** @return The node ID. */
Zane Shelley6722b5b2020-05-12 22:09:04 -050067 NodeId_t getId() const
Zane Shelley7f7a42d2019-10-28 13:28:31 -050068 {
69 return iv_id;
70 }
Zane Shelley93b61ad2019-10-16 20:41:03 -050071
72 /** @return The instance of this register. */
Zane Shelley13b182b2020-05-07 20:23:45 -050073 Instance_t getInstance() const
Zane Shelley7f7a42d2019-10-28 13:28:31 -050074 {
75 return iv_instance;
76 }
Zane Shelley93b61ad2019-10-16 20:41:03 -050077
78 /** @return The target bit within this register. */
Zane Shelley13b182b2020-05-07 20:23:45 -050079 BitPosition_t getBit() const
Zane Shelley7f7a42d2019-10-28 13:28:31 -050080 {
81 return iv_bit;
82 }
Zane Shelley93b61ad2019-10-16 20:41:03 -050083
84 /** @return The attention type reported by this bit. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050085 AttentionType_t getAttnType() const
86 {
87 return iv_attnType;
88 }
Zane Shelley11b89942019-11-07 11:07:28 -060089
Zane Shelleyd280cca2020-11-13 17:08:24 -060090 /** @return A 32-bit integer containing the node ID, instance, and bit. This
91 * should be helpful for consistent logging and tracing. */
92 uint32_t toUint32() const
93 {
94 return getId() << 16 | getInstance() << 8 | getBit();
95 }
96
Zane Shelley11b89942019-11-07 11:07:28 -060097 public: // Operators
98 /** @brief Equals operator. */
99 bool operator==(const Signature& i_r) const
100 {
101 return (getChip() == i_r.getChip() && getId() == i_r.getId() &&
102 getInstance() == i_r.getInstance() &&
103 getBit() == i_r.getBit() && getAttnType() == i_r.getAttnType());
104 }
105
106 /** @brief Less than operator. */
107 bool operator<(const Signature& i_r) const
108 {
109 if (getChip() < i_r.getChip())
110 {
111 return true;
112 }
113 else if (getChip() == i_r.getChip())
114 {
115 if (getId() < i_r.getId())
116 {
117 return true;
118 }
119 else if (getId() == i_r.getId())
120 {
121 if (getInstance() < i_r.getInstance())
122 {
123 return true;
124 }
125 else if (getInstance() == i_r.getInstance())
126 {
127 if (getBit() < i_r.getBit())
128 {
129 return true;
130 }
131 else if (getBit() == i_r.getBit())
132 {
133 return (getAttnType() < i_r.getAttnType());
134 }
135 }
136 }
137 }
138
139 return false;
140 }
Zane Shelley93b61ad2019-10-16 20:41:03 -0500141};
142
143} // end namespace libhei