| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019-2020 Robert Bosch GmbH. |
| * |
| * 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 org.eclipse.app4mc.amlt2systemc.m2t.transformers.stimuli |
| |
| import com.google.inject.Inject |
| import com.google.inject.Singleton |
| import org.eclipse.app4mc.amalthea.model.AmaltheaServices |
| import org.eclipse.app4mc.amalthea.model.PeriodicStimulus |
| import org.eclipse.app4mc.amlt2systemc.m2t.module.BaseTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.AmaltheaTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| |
| @Singleton |
| class PeriodicStimulusTransformer extends BaseTransformer { |
| |
| @Inject OutputBuffer outputBuffer |
| |
| static def getModulePath(PeriodicStimulus periodicStimulus) { |
| return AmaltheaTransformer.getModulePath() + "/stimuliModel/" + periodicStimulus.name |
| } |
| |
| def getFunctionDef(PeriodicStimulus periodicStimulus) { |
| return "get_" + periodicStimulus.name + "()" |
| } |
| |
| def create new TranslationUnit transform(PeriodicStimulus periodicStimulus) { |
| if (periodicStimulus === null) { |
| it.module = "UNSPECIFIED_PERIODICSTIMULUS" |
| it.call = it.module |
| return |
| } |
| |
| it.module = getModulePath(periodicStimulus) |
| it.call = getFunctionDef(periodicStimulus) |
| |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(periodicStimulus)) |
| |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(periodicStimulus)) |
| } |
| |
| private def String toH(PeriodicStimulus periodicStimulus) ''' |
| // This code was generated for simulation with app4mc.sim |
| |
| #pragma once |
| #include "Common.h" |
| #include "SoftwareModel.h" |
| |
| //PeriodicStimulus runnableA---- |
| std::shared_ptr<periodicTrigger> «getFunctionDef(periodicStimulus)»; |
| ''' |
| |
| private def String toCpp(PeriodicStimulus periodicStimulus) ''' |
| // This code was generated for simulation with app4mc.sim |
| |
| #include "../../«getModulePath(periodicStimulus)».h" |
| |
| std::shared_ptr<periodicTrigger> «periodicStimulus.name» = nullptr; |
| |
| std::shared_ptr<periodicTrigger> «getFunctionDef(periodicStimulus)» { |
| |
| if («periodicStimulus.name» == nullptr) { |
| //initialize |
| «val timeValPico = AmaltheaServices.convertToPicoSeconds(periodicStimulus.recurrence)» |
| «periodicStimulus.name» = std::make_shared<periodicTrigger>("«periodicStimulus.name»", sc_core::sc_time(«timeValPico», sc_core::SC_PS)); |
| } |
| return «periodicStimulus.name»; |
| } |
| |
| ''' |
| |
| def getCache() { return this._createCache_transform } |
| |
| } |