diff --git a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF index d6667c3acc077dc23ebf54cd79966847f8ced8a8..e9168c2f21f45365055aa5be557283a689ec6a96 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF @@ -14,7 +14,7 @@ Require-Bundle: org.fortiss.af3.project, org.eclipse.emf.ecore;visibility:=reexport, org.eclipse.emf.ecore.xmi;visibility:=reexport, org.fortiss.tooling.kernel;visibility:=reexport, - org.fortiss.af3.platform;bundle-version="2.5.0", + org.fortiss.af3.platform;bundle-version="2.5.0";visibility:=reexport, org.fortiss.tooling.base;visibility:=reexport, org.fortiss.af3.expression, org.eclipse.jface;bundle-version="3.9.1" diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakeMKGeneration.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakeMKGeneration.java new file mode 100644 index 0000000000000000000000000000000000000000..79495e9cf63f584187c0e0cc16f6ed2bd7eac112 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakeMKGeneration.java @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2016 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.af3.platform.raspberry.generated.files; + +/** + * + * @author zverlov + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public class RaspberryMakeMKGeneration { + /** Contents of make.mk. */ + private String content; + + /** Constructor. */ + public RaspberryMakeMKGeneration() { + this.content = ""; + } + + /** Main methods for creation of make.mk. */ + public void createMakeMK() { + // TODO: needs to be implemented + } + + /** Return content. */ + public String getContent() { + return this.content; + } + +} diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakefileGeneration.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakefileGeneration.java new file mode 100644 index 0000000000000000000000000000000000000000..af5c55bd6a91280c4989f680071c4b040baf2bfc --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generated/files/RaspberryMakefileGeneration.java @@ -0,0 +1,59 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2016 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.af3.platform.raspberry.generated.files; + +/** + * + * @author zverlov + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public class RaspberryMakefileGeneration { + + /** The name of the executable. */ + private String binaryTargetName; + + /** Contents of the Makefile. */ + private String content; + + /** Constructor. */ + public RaspberryMakefileGeneration(String targetName) { + this.binaryTargetName = targetName; + this.content = ""; + } + + /** Calls the methods that create the Makefile. */ + public void createMakefile() { + // TODO: needs to be implemented + printFirstTwoLines(); + // .... + } + + /** This methods is only an example. */ + private void printFirstTwoLines() { + content += "SHELL := /bin/bash" + "\n\n"; + content += "TARGET = " + binaryTargetName + "\n"; + + } + + /** Return the current content of the Makefile. */ + public String getContent() { + return this.content; + } +} diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java index 9b5a4a573cd562a876aad1342963c5fbbcbf5d5c..3b65dbcdd96669f6b49eb15afefcac6abf2b1d93 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java @@ -17,6 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.af3.platform.raspberry.generator.executable; +import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createStaticContentSourceUnit; + import java.util.List; import java.util.Map; @@ -26,6 +28,8 @@ import org.fortiss.af3.generator.common.model.source.SourcePackage; import org.fortiss.af3.platform.language.executable.TransmissionUnitExecutableBase; import org.fortiss.af3.platform.model.ExecutionUnit; import org.fortiss.af3.platform.model.TransmissionUnit; +import org.fortiss.af3.platform.raspberry.generated.files.RaspberryMakeMKGeneration; +import org.fortiss.af3.platform.raspberry.generated.files.RaspberryMakefileGeneration; /** * @@ -49,8 +53,30 @@ public class CANBusExecutable extends TransmissionUnitExecutableBase<Transmissio public void createAllFiles(SourcePackage pack, Map<ExecutionUnit, List<Port>> euPortsPair, Map<ExecutionUnit, List<Component>> euComponentList, Component topComponent, int deploymentID) { - // TODO Auto-generated method stub + createMakeFile(pack, "test_targetName"); + createMakeMK(pack); } + // private void createMakeFile(SourcePackage pack) { + // String content = RaspberryTemplateLoader.getMakeFileTemplate("test_executable").toString(); + // pack.addUnit(createStaticContentSourceUnit("Makefile", content, false)); + // } + + /** Creates a Makefile for an executable with a certain targetname. */ + private void createMakeFile(SourcePackage pack, String targetname) { + RaspberryMakefileGeneration rspMakefileGen = new RaspberryMakefileGeneration(targetname); + rspMakefileGen.createMakefile(); + pack.addUnit(createStaticContentSourceUnit("Makefile", rspMakefileGen.getContent(), false)); + + } + + /** Creates the make.mk file. */ + private void createMakeMK(SourcePackage pack) { + // TODO: needs to be implemented similar to createMakeFile methods + RaspberryMakeMKGeneration rspMakeMK = new RaspberryMakeMKGeneration(); + rspMakeMK.createMakeMK(); + pack.addUnit(createStaticContentSourceUnit("make.mk", rspMakeMK.getContent(), false)); + + } } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MainFileTemplate.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MainFileTemplate.stg new file mode 100644 index 0000000000000000000000000000000000000000..bbb5e3ec87e3c02e1a4c7d89e5e3c66b46ee21f1 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MainFileTemplate.stg @@ -0,0 +1,15 @@ +group MainFileTemplate; + +MainFileTemplate(headerFile) ::= << + +#include "$headerFile$" + +int main(int argc, char *argv[]) { + initialize_ports(); + initialize_system(); + while (1) { + run_system(); + } +} + +>> \ No newline at end of file diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg new file mode 100644 index 0000000000000000000000000000000000000000..1cc051ce4e17220aa8d6d6404f9abd2ec87b6df5 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg @@ -0,0 +1,110 @@ +group MakeFileTemplate; + +MakeFileTemplate(binaryName) ::= << + +SHELL := /bin/bash + +TARGET = $binary_name$ + +C_SRC := $(wildcard *.c) +CPP_SRC := $(wildcard *.cpp) +H_SRC := $(wildcard *.h) +LIBRARY := +INCLUDE_PATH := -I. +LIBRARY_PATH := -L. + +CC = gcc +CC_FLAGS = -Wall -O3 -Wno-unused-variable +CCXX = g++ +CCXX_FLAGS = -Wall -O3 -Wno-unused-variable + +LIBRARY := -lwiringPi -lwiringPiDev + +LD = ld +LD_FLAGS = + +#include makefile fragments in subdirectories if they exist +-include ./*/make.mk + +OBJECTS = $(patsubst %.c, %.o, $(C_SRC)) +OBJECTS += $(patsubst %.cpp, %.o, $(CPP_SRC)) + +RAMDISK_DIR = /mnt/ramdisk +# make ramdisj target creates and mounts a tempfs drive +#OBJ_DIR = $(RAMDISK_DIR)/objs +OBJ_DIR = objs + +OBJS = $(addprefix $(OBJ_DIR)/, $(OBJECTS)) +DEPS = $(patsubst %.o, %.o.d, $(OBJS)) + + +all: $(TARGET) silent + +#include all rules generated by gcc into the makefile +-include $(DEPS) + +#dummy target to that we don't get unnecessary mesages ( target is up to date & co) +silent: + @: + +$(TARGET): $(OBJS) + @echo Linking + @$(CCXX) $(LD_FLAGS) $(LIBRARY_PATH) -o $(TARGET) $^ $(LIBRARY) + +#create output directory if it doesn't exist +#generate dependency file for current file +# .o and .d are targets of the rule +# create blank targets for each source/header file. Used to update .d files when you delete a file +$(OBJ_DIR)/%.o: %.c + @mkdir -p $(@D) + @echo Building $< + @$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@ + @echo -n "$@.d $(@D)/" > $@.d + @$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d + @cp $@.d $<.tp + @sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d + @rm -f $<.tp + +$(OBJ_DIR)/%.o: %.cpp + @mkdir -p $(@D) + @echo Building $< + @$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@ + @echo -n "$@.d $(@D)/" > $@.d + @$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d + @cp $@.d $<.tp + @sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d + @rm -f $<.tp + +clean: + @echo Removing objects directory + @rm -rf $(OBJ_DIR) + @echo Removing target + @rm -f $(TARGET) + +#http://blog.jgc.org/2015/04/the-one-line-you-should-add-to-every.html +print-%: ; @echo $*=$($*) + + +test: + @echo $(@D) + @echo $(DEPS) + @echo $(OBJECTS2) + @echo Test + @echo $(C_SRC) + @echo Test + @echo $(H_SRC) + @echo Test + @echo $(LIBRARY) + +run: all + @./$(TARGET) + +ramdisk: + sudo mkdir $(RAMDISK_DIR) + sudo mount -t tmpfs -o size=512m tmpfs $(RAMDISK_DIR) + + +.PHONY: test deploy all ramdisk + + +>> \ No newline at end of file diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..c69487b222b7a2049179b1b1665298611d3c02bd --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java @@ -0,0 +1,76 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2016 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.af3.platform.raspberry.templates; + +import static org.fortiss.af3.generator.common.AF3GeneratorCommonActivator.getDefault; +import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; + +import java.io.IOException; +import java.io.InputStreamReader; + +import org.antlr.stringtemplate.StringTemplate; +import org.antlr.stringtemplate.StringTemplateGroup; +import org.antlr.stringtemplate.language.DefaultTemplateLexer; + +/** + * + * @author zverlov + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public class RaspberryTemplateLoader { + /** + * @param contextClass + * @param stgName + * @return the string template group for a given context class and template group name + */ + public static StringTemplateGroup loadResourceSTG(Class<?> contextClass, String stgName) { + InputStreamReader in = + new InputStreamReader(contextClass.getResourceAsStream(stgName + + (stgName.contains(".") ? "" : ".stg"))); + StringTemplateGroup templates = new StringTemplateGroup(in, DefaultTemplateLexer.class); + try { + in.close(); + } catch(IOException e) { + error(getDefault(), "AF3 generator could not load stringtemplate " + stgName + ".", e); + } + return templates; + } + + /** Returns the Template of a Makefile for the Raspberry Platform. */ + public static StringTemplate getMakeFileTemplate(String binaryName) { + StringTemplate template = + loadResourceSTG(RaspberryTemplateLoader.class, "MakeFileTemplate").getInstanceOf( + "MakeFileTemplate"); + template.setAttribute("binaryName", binaryName); + return template; + } + + /** + * @param string + * @return + */ + public static StringTemplate getMainFileTemplate(String headerFile) { + StringTemplate template = + loadResourceSTG(RaspberryTemplateLoader.class, "MainFileTemplate").getInstanceOf( + "MainFileTemplate"); + template.setAttribute("headerFile", headerFile); + return template; + } +}