blob: 59576da4dc93ac521f518b3782c13fc2b20008a6 [file] [log] [blame]
Zakir Meer9f251f52018-06-17 16:21:31 +02001package templates
2
3import com.inchron.realtime.root.model.FrequencyUnit
4import com.inchron.realtime.root.model.GenericSystem
5import com.inchron.realtime.root.model.Model
6import com.inchron.realtime.root.model.memory.MemoryType
7import java.util.ArrayList
8import java.util.List
9import org.eclipse.app4mc.amalthea.model.Cache
10import org.eclipse.app4mc.amalthea.model.Frequency
11import org.eclipse.app4mc.amalthea.model.FrequencyDomain
12import org.eclipse.app4mc.amalthea.model.HWModel
13import org.eclipse.app4mc.amalthea.model.HwStructure
14import org.eclipse.app4mc.amalthea.model.Memory
15import org.eclipse.app4mc.amalthea.model.ProcessingUnit
16import org.eclipse.app4mc.amalthea.model.StructureType
17import templates.utils.AmltCacheModel
18
19/**
20 * This class is responsible for the transformation of AMALTHEA Hardware Model into corresponding INCHRON mdoel elements and accordingly invoke other transformations
21 */
22public class HWTransformer extends AbstractAmaltheaInchronTransformer {
23
24
25
26 public def transfromHWModel(HWModel amltHWModel, Model inchronModel) {
27
28 this.inchronModel=inchronModel
29
30 val AmltCacheModel cacheModel=customObjsStore.getInstance(AmltCacheModel)
31
32 /*- Transformation of FrequencyDomain elements to Clock elements in Inchron */
33
34 amltHWModel?.domains.filter[it instanceof FrequencyDomain].forEach [ amltQuartz |
35
36 val inchronClock = createClock(amltQuartz as FrequencyDomain)
37 inchronModel.clocks.add(inchronClock)
38 ]
39
40 /*- Transformation of each Memory element of SYSTEM to Memory element in Inchron*/
41
42 amltHWModel?.structures.filter[it.structureType==StructureType.SYSTEM]?.forEach[st|
43 st?.modules.filter[it instanceof Memory].forEach[amltMem|
44 val inchronMemory = createMemory(amltMem as Memory)
45 inchronModel.memories.add(inchronMemory)
46 ]
47 ]
48
49 /*- Collecting all Amalthea ECU elements */
50
51 val amltECUs=new ArrayList
52
53 amltHWModel?.structures.filter[it.structureType==StructureType.SYSTEM]?.forEach[it?.structures.filter[it.structureType==StructureType.ECU].forEach[
54 ecu|
55 amltECUs.add(ecu)
56 ]]
57
58 /*- Conversion of Amalthea ECU and its sub-elements into corresponding Inchron elements */
59
60 for (amaltheaEcu : amltECUs) {
61
62 amaltheaEcu?.modules.forEach [ amltMem |
63
64 /*- Transformation of each Memory element of ECU to Memory element in Inchron*/
65
66 if(amltMem instanceof Memory){
67 val inchronMemory = createMemory(amltMem)
68 inchronModel.memories.add(inchronMemory)
69
70 }
71 ]
72
73 val List<GenericSystem> allGenericSystems=new ArrayList<GenericSystem>
74
75 /*- Transformation of each Structure of type MicroController to correspnding Inchron element*/
76
77 for (amaltheaMicroController : amaltheaEcu?.structures.filter[it.structureType==StructureType.MICROCONTROLLER]) {
78
79 /*- Each MicroController is created as GenericSystem element in Inchron and corresponding data of sub-elements is transformed accordingly. */
80
81 val genericSystem = OSTransformerInstance.createGenericSystem(amaltheaMicroController)
82
83 /*-Building Inchron CPU element */
84 val inchronCpu = createCpu(amaltheaMicroController);
85
86 /*-Adding Inchron CPU and GenericSystem elements to Inchron Model */
87
88 inchronModel.cpus.add(inchronCpu)
89
90 inchronModel.systems.add(genericSystem)
91
92 /*- Transformation of each Memory element of MicroController to Memory element in Inchron*/
93
94 amaltheaMicroController?.modules.filter[it instanceof Memory].forEach [ amltMem |
95 val inchronMemory = createMemory(amltMem as Memory)
96 inchronCpu.memories.add(inchronMemory)
97 ]
98
99 /*-Adding Amalthea microController and Inchron GenericSystem into the Cache map. */
100 cacheModel.cacheMappingAmltMicroController_GenericSystem(amaltheaMicroController, genericSystem)
101
102 /*-Collecting all Inchron GenericSystems, so as to process them later */
103 allGenericSystems.add(genericSystem)
104 }
105
106 for (genericSystem : allGenericSystems) {
107
108 /*-======================================Process each Inchron GenericSystem and populate the data ======================================*/
109
110 OSTransformerInstance.fillGenericSystem(genericSystem, amaltheaModel, inchronModel)
111
112 }
113 }
114
115 /*-Adding Stimulation scenarios to Inchron Model */
116 inchronModel.stimulationScenarios.add(stimuliTransformerInstance.createstimulationScenario(amaltheaModel))
117 }
118
119/**
120 * Creating a Inchron CPU element from AMALTHEA HwStructure of type MicroController
121 */
122 public def create inchronModelFactory.createCpu createCpu(HwStructure amltMicrocontroller) {
123
124 it.name = amltMicrocontroller.name
125
126 /*Transformation of Amalthea ProcessingUnit to CpuCore element in Inchron */
127
128 for (amltCore : amltMicrocontroller?.modules.filter[it instanceof ProcessingUnit]) {
129
130 val inchronCpuCore = createCpuCore(amltCore as ProcessingUnit)
131
132 /*- Transformation of each Memory element of ProcessingUnit to Memory element of type CACHE in Inchron*/
133
134 (amltCore as ProcessingUnit)?.caches.forEach [ amltMem |
135 val inchronMemory = createMemory_CacheType(amltMem)
136 inchronMemory.type = MemoryType.CACHE
137 it.memories.add(inchronMemory)
138 ]
139
140 inchronCpuCore.cpu = it
141
142 it.cores.add(inchronCpuCore)
143
144 /*-Transformation of FrequencyDomain of the ProcessingUnit in Amalthea */
145 val amltQuartz = amltCore?.frequencyDomain
146
147 if (amltQuartz != null) {
148 val inchronClock = createClock(amltQuartz)
149
150 //TODO:Clarify if this is correct ? as the CpuCore Clock into is set to the CPU level in Inchron
151 it.clock = (inchronClock) //TODO: Error : In this case, CPU will only hold the Clock of last CpuCore
152 }
153
154 }
155
156 }
157
158/**
159 * Creating Inchron Clock element for FrequencyDomain element of Amalthea
160 */
161 def create inchronModelFactory.createClock createClock(FrequencyDomain amltQuartz) {
162
163 it.name = amltQuartz.name
164 it.frequency = createFrequency(amltQuartz.defaultValue)
165 }
166
167/**
168 * Creating Inchron Frequency element for the corresponding Frequency element of Amalthea
169 */
170 def create inchronModelFactory.createFrequency createFrequency(Frequency amltFrequency) {
171
172 it.unit = FrequencyUnit.getByName(amltFrequency?.unit.getName)
173 it.value = amltFrequency?.value.floatValue
174 }
175
176/**
177 * Creating Inchron CpuCore from ProcessingUnit element of Amalthea
178 */
179 def create inchronModelFactory.createCpuCore createCpuCore(ProcessingUnit core) {
180
181 it.name = core.name
182
183 }
184
185/**
186 * Creating Inchron Memory element from Memory element of Amalthea.
187 * In this method, corresponding FrequencyDomain of the Amalthea element is accordingly converted to Inchron Clock element
188 */
189 def create inchronmemoryFactory.createMemory createMemory(Memory amltMemory) {
190
191 it.name = amltMemory.name
192
193 if (amltMemory.frequencyDomain != null) {
194 it.clock = createClock(amltMemory.frequencyDomain)
195 it.prescaler = amltMemory?.frequencyDomain?.defaultValue?.value
196
197 }
198
199 }
200
201 /** Creating Inchron Memory element from Memory element of Amalthea.
202 * In this method, corresponding FrequencyDomain of the Amalthea element is accordingly converted to Inchron Clock element
203 */
204 def create inchronmemoryFactory.createMemory createMemory_CacheType(Cache amltMemory) {
205
206 it.name = amltMemory.name
207
208 if (amltMemory.frequencyDomain != null) {
209 it.clock = createClock(amltMemory.frequencyDomain)
210 it.prescaler = amltMemory?.frequencyDomain?.defaultValue?.value
211
212 }
213
214 }
215}