blob: 118e28253c57b3f93a16cff63995262298e2b92a [file] [log] [blame]
Zane Shelley508ce582020-05-05 13:47:19 -05001#include <isolator/hei_isolation_chip.hpp>
2
3namespace libhei
4{
5
6//------------------------------------------------------------------------------
7
8bool IsolationChip::analyze(const Chip& i_chip, IsolationData& io_isoData) const
9{
10 bool o_activeAttn = false; // Initially, assume no active attentions.
11
12 // The given chip must be the same type as iv_chipType.
13 HEI_ASSERT(iv_chipType == i_chip.getType());
14
15 // Iterate each root node.
16 for (const auto& node : iv_rootNodes)
17 {
18 if (node.second->analyze(i_chip, node.first, io_isoData))
19 {
20 // At least one attention type had an active attention.
21 o_activeAttn = true;
22 }
23 }
24
25 return o_activeAttn;
26}
27
28//------------------------------------------------------------------------------
29
Zane Shelley4de8ff82020-05-14 15:39:01 -050030void IsolationChip::addHardwareRegister(HardwareRegister::ConstPtr i_hwReg)
Zane Shelley4caa0432020-05-12 22:29:02 -050031{
32 HEI_ASSERT(i_hwReg); // should not be null
33
Zane Shelley4de8ff82020-05-14 15:39:01 -050034 auto ret = iv_regs.emplace(i_hwReg->getKey(), i_hwReg);
Zane Shelley4caa0432020-05-12 22:29:02 -050035
36 // If an entry already exists, it should point to the same object.
37 HEI_ASSERT(ret.second || (ret.first->second == i_hwReg));
38}
39
40//------------------------------------------------------------------------------
41
Zane Shelley4de8ff82020-05-14 15:39:01 -050042void IsolationChip::addIsolationNode(IsolationNode::ConstPtr i_isoNode)
Zane Shelley4caa0432020-05-12 22:29:02 -050043{
44 HEI_ASSERT(i_isoNode); // should not be null
45
Zane Shelley4de8ff82020-05-14 15:39:01 -050046 auto ret = iv_nodes.emplace(i_isoNode->getKey(), i_isoNode);
Zane Shelley4caa0432020-05-12 22:29:02 -050047
48 // If an entry already exists, it should point to the same object.
49 HEI_ASSERT(ret.second || (ret.first->second == i_isoNode));
50}
51
52//------------------------------------------------------------------------------
53
54void IsolationChip::addRootNode(AttentionType_t i_attnType,
Zane Shelley4de8ff82020-05-14 15:39:01 -050055 IsolationNode::ConstPtr i_rootNode)
Zane Shelley4caa0432020-05-12 22:29:02 -050056{
57 HEI_ASSERT(i_rootNode); // should not be null
58
59 auto ret = iv_rootNodes.emplace(i_attnType, i_rootNode);
60
61 // If an entry already exists, it should point to the same object.
62 HEI_ASSERT(ret.second || (ret.first->second == i_rootNode));
63}
64
65//------------------------------------------------------------------------------
66
Zane Shelley4de8ff82020-05-14 15:39:01 -050067HardwareRegister::ConstPtr
68 IsolationChip::getHardwareRegister(HardwareRegister::Key i_key) const
Zane Shelley4caa0432020-05-12 22:29:02 -050069{
Zane Shelley4de8ff82020-05-14 15:39:01 -050070 auto itr = iv_regs.find(i_key);
Zane Shelley4caa0432020-05-12 22:29:02 -050071 HEI_ASSERT(iv_regs.end() != itr); // The register should exist.
72
73 return itr->second;
74}
75
76//------------------------------------------------------------------------------
77
Zane Shelley4de8ff82020-05-14 15:39:01 -050078IsolationNode::ConstPtr
79 IsolationChip::getIsolationNode(IsolationNode::Key i_key) const
Zane Shelley4caa0432020-05-12 22:29:02 -050080{
Zane Shelley4de8ff82020-05-14 15:39:01 -050081 auto itr = iv_nodes.find(i_key);
Zane Shelley4caa0432020-05-12 22:29:02 -050082 HEI_ASSERT(iv_nodes.end() != itr); // The node should exist.
83
84 return itr->second;
85}
86
87//------------------------------------------------------------------------------
88
Zane Shelley508ce582020-05-05 13:47:19 -050089} // end namespace libhei