blob: 7b40dc3c980814273a2ab9721f741a6534908a12 [file] [log] [blame]
/**
* *******************************************************************************
* Copyright (c) 2019 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
* *******************************************************************************
*/
package templates.m2m.sw
import com.google.inject.Inject
import com.inchron.realtime.root.model.Model
import java.util.HashMap
import java.util.Map
import org.eclipse.app4mc.amalthea.model.InterruptController
import org.eclipse.app4mc.amalthea.model.OperatingSystem
import org.eclipse.app4mc.amalthea.model.Process
import org.eclipse.app4mc.amalthea.model.SWModel
import org.eclipse.app4mc.amalthea.model.TaskScheduler
import templates.AbstractAmaltheaInchronTransformer
import templates.utils.AmltCacheModel
import templates.m2m.hw.ProcessingUnitTransformer
import templates.m2m.os.OSTransformer
import templates.m2m.stimuli.StimuliTransformer
import com.google.inject.Singleton
@Singleton
class SWTransformer extends AbstractAmaltheaInchronTransformer {
var AmltCacheModel cacheModel
@Inject TaskTransformer taskTransformer
@Inject ISRTransformer isrTransformer
@Inject CallGraphTransformer callGraphTransformer
@Inject ModeLabelTransformer modeLabelTransformer
@Inject ProcessingUnitTransformer processingUnitTransformer
@Inject OSTransformer osTransformer
@Inject StimuliTransformer stimuliTransformer
def transformSWModel(SWModel amltSwModel, Model inchronModel) {
cacheModel = customObjsStore.getInstance(AmltCacheModel)
val Map<Process, com.inchron.realtime.root.model.Process> amltProcess_inchronProcessMap = new HashMap
cacheModel.amltProcess_inchronProcessMap=amltProcess_inchronProcessMap
amltSwModel?.modeLabels?.forEach[amltModeLabel|{
inchronModel.globalModeGroups.add(modeLabelTransformer.createModeGroup(amltModeLabel))
}]
// amltSwModel?.modes?.forEach[amltMode|{
// inchronModel.globalModeGroups.add(modeTransformer.createModeGroup(amltMode))
// }]
val inchronScheduler_amltSchedulerMap = cacheModel.getInchronScheduler_amltSchedulerMap()
inchronScheduler_amltSchedulerMap.forEach [ inchronScheduler, amltScheduler |
if (amltScheduler !== null) {
var amltOS = amltScheduler.eContainer as OperatingSystem
val inchronComponent = osTransformer.createComponent(amltOS)
if (amltScheduler instanceof TaskScheduler) {
amltScheduler.taskAllocations.forEach [ amltTaskAllocation |
var amltTask = amltTaskAllocation.task
val inchronProcess = taskTransformer.createProcess(amltTask, inchronComponent)
amltProcess_inchronProcessMap.put(amltTask, inchronProcess)
amltTaskAllocation.affinity.forEach [ amltPU |
{
var inchronCpuCore = processingUnitTransformer.createCpuCore(amltPU)
if (inchronCpuCore !== null) {
inchronProcess.cpuCores.add(inchronCpuCore)
}
}
]
inchronScheduler.schedulables.add(inchronProcess)
]
} else if (amltScheduler instanceof InterruptController) {
amltScheduler.isrAllocations.forEach [ amltISRAllocation |
var amltISR = amltISRAllocation.isr
val inchronProcess = isrTransformer.createProcess(amltISR, inchronComponent)
amltProcess_inchronProcessMap.put(amltISR, inchronProcess)
inchronScheduler.schedulables.add(inchronProcess)
]
}
}
]
amltProcess_inchronProcessMap.forEach [ amltProcess, inchronProcess | {
if(amltProcess.callGraph!==null)
{
callGraphTransformer.transformCallGraph(amltProcess.callGraph,amltProcess,amltProcess_inchronProcessMap)
}
amltProcess?.stimuli?.forEach [ amltStimuli |{
val inchronActivationConnection = stimuliTransformer.createActivationConnection(amltStimuli)
if(inchronActivationConnection!==null){
var inchronActivateProcess = inchronModelFactory.createActivateProcess
inchronActivateProcess.target = amltProcess_inchronProcessMap.get(amltProcess)
inchronActivationConnection?.activations?.add(inchronActivateProcess)
}
}]
}]
}
}