REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
factory.cpp
Go to the documentation of this file.
1
2#include <block/cblock.h>
3#include <block/ctrlblock.h>
4#include <block/iblock.h>
5#include <block/mblock.h>
6#include <block/ublock.h>
7#include <bus/bus.h>
8#include <entity/base.h>
9
10#include "teensy/cblock.h"
11#include "teensy/ctrlblock.h"
12#include "teensy/iblock.h"
13#include "teensy/mblock_int.h"
14#include "teensy/mblock_mul.h"
15#include "teensy/shblock.h"
16#include "teensy/ublock.h"
17
18FLASHMEM
19blocks::CBlock *blocks::CBlock::from_entity_classifier(entities::EntityClassifier classifier,
20 const bus::addr_t block_address) {
21 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != TYPE)
22 return nullptr;
23
24 if (classifier.version < entities::Version(1, 0))
25 return nullptr;
26 if (classifier.version < entities::Version(1, 1))
27 return new CBlock(new CBlockHAL_V_1_0_X(block_address));
28 if (classifier.version < entities::Version(1, 2))
29 return new CBlock(new CBlockHAL_V_1_1_X(block_address));
30
31 // Any unknown versuin results in a nullptr here.
32 return nullptr;
33}
34
35FLASHMEM blocks::CTRLBlock *blocks::CTRLBlock::from_entity_classifier(entities::EntityClassifier classifier,
36 bus::addr_t block_address) {
37 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != TYPE)
38 return nullptr;
39
40 // Currently, there are no variants.
41 // TODO: After adapting classifier to (major, minor, patch) version,
42 // fail on v1.0.1, which has missing hardware components and should not be used.
43 return new CTRLBlock(new CTRLBlockHAL_V_1_0_2(block_address));
44}
45
46FLASHMEM blocks::IBlock *blocks::IBlock::from_entity_classifier(entities::EntityClassifier classifier,
47 bus::addr_t block_address) {
48 if (!classifier or classifier.class_enum != CLASS_)
49 return nullptr;
50
51 // Currently, there are no different variants
52 if (classifier.variant != entities::EntityClassifier::DEFAULT_)
53 return nullptr;
54
55 if (classifier.version < entities::Version(1, 2))
56 return nullptr;
57 if (classifier.version < entities::Version(1, 3))
58 return new IBlock(new IBlockHAL_V_1_2_X(block_address));
59 return nullptr;
60}
61
62FLASHMEM
63blocks::MBlock *blocks::MBlock::from_entity_classifier(entities::EntityClassifier classifier,
64 const bus::addr_t block_address) {
65 if (!classifier or classifier.class_enum != entities::EntityClass::M_BLOCK)
66 return nullptr;
67
68 auto type = classifier.type_as<TYPES>();
69 switch (type) {
70 case TYPES::UNKNOWN:
71 // This is already checked by !classifier above
72 return nullptr;
73 case TYPES::M_MUL4_BLOCK:
74 return MMulBlock::from_entity_classifier(classifier, block_address);
75 case TYPES::M_INT8_BLOCK:
76 return MIntBlock::from_entity_classifier(classifier, block_address);
77 }
78 // Any unknown value results in a nullptr here.
79 // Adding default case to switch suppresses warnings about missing cases.
80 return nullptr;
81}
82
83FLASHMEM blocks::MIntBlock *blocks::MIntBlock::from_entity_classifier(entities::EntityClassifier classifier,
84 const bus::addr_t block_address) {
85 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != static_cast<uint8_t>(TYPE))
86 return nullptr;
87
88 // Currently, there are no different variants
89 if (classifier.variant != entities::EntityClassifier::DEFAULT_)
90 return nullptr;
91
92 SLOT slot = block_address % 8 == 4 ? SLOT::M0 : SLOT::M1;
93 if (classifier.version < entities::Version(1))
94 return nullptr;
95 if (classifier.version < entities::Version(1, 1))
96 return new MIntBlock(slot, new MIntBlockHAL_V_1_0_X(block_address));
97 if (classifier.version < entities::Version(1, 2))
98 return new MIntBlock(slot, new MIntBlockHAL_V_1_1_X(block_address));
99 return nullptr;
100}
101
102FLASHMEM blocks::MMulBlock *blocks::MMulBlock::from_entity_classifier(entities::EntityClassifier classifier,
103 const bus::addr_t block_address) {
104 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != static_cast<uint8_t>(TYPE))
105 return nullptr;
106
107 // Currently, there are no different variants
108 if (classifier.variant != entities::EntityClassifier::DEFAULT_)
109 return nullptr;
110
111 SLOT slot = block_address % 8 == 4 ? SLOT::M0 : SLOT::M1;
112 // Return default implementation
113 if (classifier.version < entities::Version(1))
114 return nullptr;
115 if (classifier.version < entities::Version(1, 1))
116 return new MMulBlock(slot, new MMulBlockHAL_V_1_0_X(block_address));
117 if (classifier.version == entities::Version(1, -1))
118 return new MMulBlock_FullAutoCalibration(slot, new MMulBlockHAL_V_1_M1_X(block_address));
119 return nullptr;
120}
121
122FLASHMEM
123blocks::SHBlock *blocks::SHBlock::from_entity_classifier(entities::EntityClassifier classifier,
124 bus::addr_t block_address) {
125 if (!classifier or classifier.class_enum != CLASS_)
126 return nullptr;
127
128 // Currently, there are no different variants
129 if (classifier.variant != entities::EntityClassifier::DEFAULT_)
130 return nullptr;
131
132 // TODO fix versions of new sh hal class
133 if (classifier.version < entities::Version(0, 1))
134 return nullptr;
135 if (classifier.version < entities::Version(0, 2))
136 return new SHBlock(new SHBlockHAL_V_1_0_X(block_address));
137 return nullptr;
138}
139
140FLASHMEM
141blocks::UBlock *blocks::UBlock::from_entity_classifier(entities::EntityClassifier classifier,
142 bus::addr_t block_address) {
143 if (!classifier or classifier.class_enum != CLASS_ or classifier.type != TYPE)
144 return nullptr;
145
146 if (classifier.version < entities::Version(1, 2))
147 return nullptr;
148 if (classifier.version < entities::Version(1, 3))
149 return new UBlock(new UBlockHAL_V_1_2_X(block_address));
150 return nullptr;
151}