| /** |
| * ******************************************************************************* |
| * 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.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 |
| import templates.m2m.hw.ProcessingUnitTransformer |
| import com.google.inject.Inject |
| import templates.m2m.os.OSTransformer |
| import com.google.inject.Singleton |
| |
| @Singleton |
| class MappingTransformer extends AbstractAmaltheaInchronTransformer { |
| |
| var AmltCacheModel cacheModel |
| @Inject ProcessingUnitTransformer processingUnitTransformer |
| @Inject OSTransformer osTransformer |
| |
| def transfromMappingModel(MappingModel amltMappingModel, Model inchronModel) { |
| |
| 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 |
| |
| inchronRootIsrScheduler.timeSlice = inchronModelFactory.createTime |
| inchronRootIsrScheduler.period = inchronModelFactory.createTime |
| inchronRootIsrScheduler.maxRetard = inchronModelFactory.createTime |
| inchronRootIsrScheduler.maxAdvance = inchronModelFactory.createTime |
| |
| // Adding Root ISR scheduler to RTOSConfig |
| osTransformer.createRtosConfig(amltOS).schedulables.add(inchronRootIsrScheduler) |
| //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.scheduler_SchedulerAllocationMap.get( |
| amlRootTaskSchedulers.get(0)) |
| |
| amltSchedulerAllocation.responsibility.forEach [ amltProcessingUnit | |
| inchronRootIsrScheduler.cpuCores.add(processingUnitTransformer.createCpuCore(amltProcessingUnit)) |
| ] |
| |
| } else if (amltOS.interruptControllers.size == 1) { |
| |
| inchronRootIsrScheduler.name = amltOS.interruptControllers.get(0).name |
| |
| var amltSchedulerAllocation = cacheModel.scheduler_SchedulerAllocationMap.get( |
| amltOS.interruptControllers.get(0)) |
| |
| amltSchedulerAllocation.responsibility.forEach [ amltProcessingUnit | |
| { |
| inchronRootIsrScheduler.cpuCores.add(processingUnitTransformer.createCpuCore(amltProcessingUnit)) |
| } |
| ] |
| |
| cacheModel.addInchronScheduler_amltSchedulerMap(inchronRootIsrScheduler, |
| amltOS.interruptControllers.get(0)) |
| |
| } 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 amltTaskScheduler, Scheduler parentISRScheduler, |
| AmltCacheModel cacheModel) { |
| |
| val Scheduler inchronScheduler = inchronModelFactory.createScheduler |
| |
| inchronScheduler.timeSlice = inchronModelFactory.createTime |
| inchronScheduler.period = inchronModelFactory.createTime |
| inchronScheduler.maxRetard = inchronModelFactory.createTime |
| inchronScheduler.maxAdvance = inchronModelFactory.createTime |
| |
| inchronScheduler.name = amltTaskScheduler.name |
| |
| parentISRScheduler.schedulables.add(inchronScheduler) |
| |
| var amltSchedulerAllocation = cacheModel.scheduler_SchedulerAllocationMap.get(amltTaskScheduler) |
| |
| amltSchedulerAllocation.responsibility.forEach [ amltProcessingUnit | |
| inchronScheduler.cpuCores.add(processingUnitTransformer.createCpuCore(amltProcessingUnit)) |
| ] |
| |
| var amltChildTaskSchedulers = amltTaskScheduler.childSchedulers |
| |
| for (amltChildTaskScheduler : amltChildTaskSchedulers) { |
| createInchronScheduler(amltChildTaskScheduler, inchronScheduler, cacheModel) |
| } |
| |
| cacheModel.addInchronScheduler_amltSchedulerMap(inchronScheduler, amltTaskScheduler) |
| } |
| |
| /** |
| * 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) |
| } |
| |
| } |