blob: 0726a8f861a7c90dccef3cc6dfe47364a7c2b2fa [file] [log] [blame]
package templates.m2m.mapping
import com.inchron.realtime.root.model.Model
import com.inchron.realtime.root.model.Scheduler
import org.eclipse.app4mc.amalthea.model.MappingModel
import org.eclipse.app4mc.amalthea.model.TaskScheduler
import templates.AbstractAmaltheaInchronTransformer
import templates.utils.AmltCacheModel
class MappingTransformer extends AbstractAmaltheaInchronTransformer{
public def transfromMappingModel(MappingModel amltMappingModel, Model inchronModel) {
this.inchronModel=inchronModel
val AmltCacheModel cacheModel=customObjsStore.getInstance(AmltCacheModel)
//building cache
cacheModel.buildProcesses_SchedulerAllocationMap(amltMappingModel)
val rootTaskSchedulers = amltMappingModel?.schedulerAllocation?.map [ amltSchedulerAllocation |
if (amltSchedulerAllocation.scheduler instanceof TaskScheduler) {
return (amltSchedulerAllocation.scheduler as TaskScheduler).rootScheduler
}
].toSet.filter[it != null]
//group elements based on the OS
var amltOsTaskSchedulersMap=cacheModel.groupTaskSchdulers(rootTaskSchedulers);
for(amltOS : amltOsTaskSchedulersMap.keySet){
var amlRootTaskSchedulers=amltOsTaskSchedulersMap.get(amltOS)
val Scheduler inchronRootIsrScheduler = inchronModelFactory.createScheduler
//Adding Root ISR scheduler to RTOSConfig
cacheModel.getInchronRtosConfig(amltOS.name)?.schedulables.add(inchronRootIsrScheduler)
if(amltOS.interruptControllers.size== 0){
inchronRootIsrScheduler.name=amltOS.name+"_ISRDummy"
//TODO: Migration rule -> considering responsibility from the first TaskScheduler of this OS
var amltSchedulerAllocation=cacheModel.taskScheduler_SchedulerAllocationMap.get(amlRootTaskSchedulers.get(0))
amltSchedulerAllocation.responsibility.forEach[amltProcessingUnit|{
inchronRootIsrScheduler.cpuCores.add(cacheModel.getInchronCpuCore(amltProcessingUnit.name))
}]
}else if(amltOS.interruptControllers.size== 1){
inchronRootIsrScheduler.name=amltOS.interruptControllers.get(0).name
var amltSchedulerAllocation=cacheModel.taskScheduler_SchedulerAllocationMap.get( amltOS.interruptControllers.get(0))
amltSchedulerAllocation.responsibility.forEach[amltProcessingUnit|{
inchronRootIsrScheduler.cpuCores.add(cacheModel.getInchronCpuCore(amltProcessingUnit.name))
}]
}else{
//todo: validation rule
}
//associating all the Root task schedulers to the ISR root scheduler
for(amltRootTaskScheduler : amlRootTaskSchedulers){
createInchronScheduler(amltRootTaskScheduler, inchronRootIsrScheduler, cacheModel)
}
}
}
protected def void createInchronScheduler(TaskScheduler amltTaskschduler, Scheduler parentISRScheduler, AmltCacheModel cacheModel) {
val Scheduler inchronScheduler = inchronModelFactory.createScheduler
inchronScheduler.name=amltTaskschduler.name
parentISRScheduler.schedulables.add(inchronScheduler)
var amltSchedulerAllocation=cacheModel.taskScheduler_SchedulerAllocationMap.get(amltTaskschduler)
amltSchedulerAllocation.responsibility.forEach[amltProcessingUnit|{
inchronScheduler.cpuCores.add(cacheModel.getInchronCpuCore(amltProcessingUnit.name))
}]
var amltChildTaskSchedulers=amltTaskschduler.childSchedulers
for (amltChildTaskScheduler : amltChildTaskSchedulers) {
createInchronScheduler(amltChildTaskScheduler,inchronScheduler,cacheModel )
}
}
/**
* This method is used to return the root TaskScheduler object
*/
def TaskScheduler getRootScheduler(TaskScheduler sch) {
if (sch.parentScheduler == null) {
return sch
}
return getRootScheduler(sch.parentScheduler)
}
}