From f33edd8db991447b16f82e7036fded9d90424726 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Fri, 13 Oct 2017 11:43:39 +0000 Subject: [PATCH] First working RasPi deployment. refs 3079 --- .../inc/{ => af3pihal}/temp_actuator.h | 0 .../trunk/code-gen-hal/lib/libaf3pihal.a | Bin 1392302 -> 1392298 bytes .../executable/HeaderCopyGenerator.java | 1 + .../generator/executable/MainGenerator.java | 63 +++++++++++++----- .../executable/RaspberryPIExecutable.java | 5 +- .../generator/templates/MainFile.stg | 3 +- .../generator/templates/RasPiCTemplates.java | 9 +-- 7 files changed, 59 insertions(+), 22 deletions(-) rename org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/{ => af3pihal}/temp_actuator.h (100%) diff --git a/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/temp_actuator.h b/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/af3pihal/temp_actuator.h similarity index 100% rename from org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/temp_actuator.h rename to org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/af3pihal/temp_actuator.h diff --git a/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a b/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a index 3d6219dbd5f7d4fd2e36ff267d21144e75bbfbd9..4ade60d14cacc596134c09ac0aae68d3c07f27e6 100644 GIT binary patch delta 1859 zcmZA1e{54#6bJD89{puIXg4NIv(avpc5Lep+{Q)-bcBctYWj>N!I;=dFoDFliizP5 zlg^N^B_?iWWZxMGEy#~K39X>KPQg_LHyzk9G0w!W1p+Q3af8KV{DJeF-9gYMC%2z_ z&pYql)4q55L8SLVq@%>RuDYhC{-d(LH&uwdfQ-ebUlaCsw?2ye;uWIcmghfFxZNuL z7kDMEtUueS%owmEURc!WHot(V&tB4b)U<nF%-k9?D-<flA_@bAk-|j5YZi(p^qAS2 zf7o1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19>Y&7X^qiM$7FL@(GBQ zcZfsHc$jAcX#8ZZecl<*<p5e6EXn4gEbbE019DA>pVKcxf0;^DWIBp?uaKv(YuqNe z#}N>H7Rb+59|qX_HB3>nh;mJnpNoa814%OpIwNEcNUBL{*k}Pc4q{b&iwlL+fmogB z<7y!<q!TUX{TET-Ahhj3I@dJXQ#rR4m0ZJQB5_U|c0wh9)(2n}yN!E=41rkvFX7M? zkmT9Yxsi<JqSrvLG3)B!E+I!je0;D)n(__wMd%&kz*Z5RIEU!9(G?LPAA&449o}!D zTcJIsql$}#`~Wh|BsJV1<Pk`sNm|)x12Hnjs=vpDLcAbWhX%M>$Xt*#bAJs&>sw`w z)q>pbVAusvz@1l7Y^CVS(23^8>4moak}<L=Zf85)s+&XYunfcUoLR{bmkU{$X;p&r zBYM-QPEkdi9szj;#KW(*OHZKnx1is(HpKysh~-Ieto23g?EslFm#D`)bH$>Ep>K`0 zsX@r~c|@;{w#oP&i9_>=4q1t_xDZH-WD#vNO@6KxlC(hf*2rNV6uk<1rRk{W+^a}a z1~Sunj|_1okXEyFtlj&#S4iUs8A%iB#G($-*1fB^97yY4HtvaZ3F!x^FrP^JHR$)3 zkDbhV-YcXIB+IO(k0T)ZuOJsR{w?V8soCtk4s_~Sq92>MJKyQEy{#SD><mQR)D&+h z(G&RCT$kH+6R+mY&QwiTbc*=U4ZO;-*tmiGr-A<B%q=k~YJdwt^f#9(x*f~G3+^25 z{#17#*{wYM`wgRL#cX^o%-?D<a3NokQH|FS<&V=cUocL~{ORz)o5sqxk#CEKR@13i zGlzUzL|=d|2tT@ORK_imd)e$}P8s(>CrbGklN^dpTk~gS{D-JU#(#-EFKg*H5YdPj gL@Xi>;SRU-#~1a7je<!hd&&a$J>kIpiTB?44>-k1X#fBK diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java index 91c0ca31..c3eda109 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java @@ -47,6 +47,7 @@ final class HeaderCopyGenerator { incLibPack.addUnit(copyAF3Hal("protocol_coordinator.h")); incLibPack.addUnit(copyAF3Hal("protocol_factory.h")); incLibPack.addUnit(copyAF3Hal("protocol_worker.h")); + incLibPack.addUnit(copyAF3Hal("temp_actuator.h")); incLibPack.addUnit(copyAF3Hal("timeutil.h")); } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java index 87dd2ae0..7ffc80ed 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java @@ -51,17 +51,44 @@ import org.fortiss.tooling.kernel.extension.data.ITransformationContext; * @ConQAT.Rating RED Hash: */ class MainGenerator { - /** Creates the main.c file. */ - public AbstractUnit createMain(RaspberryPi executionUnit, + private static final int WAITING_SLEEP_IN_MICROS = 250; + private RaspberryPi executionUnit; + private List<Pair<ExecutionUnit, Component>> deployedComponents; + private List<Pair<PlatformConnectorUnit, Port>> deployedPorts; + private ITransformationContext context; + + private boolean useGamepad; + private boolean usePWM; + + /** Constructor. */ + public MainGenerator(RaspberryPi executionUnit, List<Pair<ExecutionUnit, Component>> deployedComponents, List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) { + this.executionUnit = executionUnit; + this.deployedComponents = deployedComponents; + this.deployedPorts = deployedPorts; + this.context = context; + for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) { + if(!useGamepad && p.getFirst() instanceof GamepadReceiverBase) { + useGamepad = true; + } + if(!usePWM && p.getFirst() instanceof ActuatorPWM) { + usePWM = true; + } + } + } + + /** Creates the main.c file. */ + public AbstractUnit createMain() { String includes = createIncludes(deployedComponents, deployedPorts); + // TODO: compute syncBox size + int syncBoxSize = 0; // TODO: syncbox code String initCode = createInitCode(deployedComponents); String workerCode = createWorkerCode(deployedComponents, deployedPorts); return getMainCFile(executionUnit.getName(), executionUnit.isCoordinatorUnit(), - executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), 250, includes, - "// TODO\n", initCode, workerCode); + executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), + WAITING_SLEEP_IN_MICROS, includes, syncBoxSize, "// TODO\n", initCode, workerCode); } /** Creates the includes of the system headers. */ @@ -72,17 +99,11 @@ class MainGenerator { Component c = p.getSecond(); sb.append("#include <" + c.getName() + "_ID_" + c.getId() + ".h>\n"); } - boolean useGamepad = false; - boolean usePWM = false; - for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) { - if(!useGamepad && p.getFirst() instanceof GamepadReceiverBase) { - sb.append("#include <gamepad.h>\n"); - useGamepad = true; - } - if(!usePWM && p.getFirst() instanceof ActuatorPWM) { - sb.append("#include <temp_actuator.h>\n"); - usePWM = true; - } + if(useGamepad) { + sb.append("#include <gamepad.h>\n"); + } + if(usePWM) { + sb.append("#include <temp_actuator.h>\n"); } return sb.toString(); } @@ -162,6 +183,18 @@ class MainGenerator { /** Create the initialize code. */ private String createInitCode(List<Pair<ExecutionUnit, Component>> deployedComponents) { StringBuilder sb = new StringBuilder(); + if(usePWM) { + sb.append("temp_actuator_initialize(\"/dev/ttyACM0\");\n\n"); + } + if(useGamepad) { + sb.append("gamepad_configuration_t* gamepad_config = malloc(sizeof(gamepad_configuration_t));\n"); + sb.append("gamepad_config->device_id = \"/dev/input/js0\";\n"); + sb.append("gamepad_config->waiting_sleep_in_micros = " + WAITING_SLEEP_IN_MICROS + + ";\n"); + sb.append("gamepad_config->axis_callback = NULL;\n"); + sb.append("gamepad_config->button_callback = NULL;\n"); + sb.append("gamepad_initialize(gamepad_config);\n\n"); + } for(Pair<ExecutionUnit, Component> p : deployedComponents) { Component c = p.getSecond(); sb.append(makeCall("init", c)); diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java index ff4a7bb3..070ede94 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java @@ -107,8 +107,9 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry List<Pair<ExecutionUnit, Component>> deployedComponents, List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) { CSourcePackage srcGenPack = (CSourcePackage)sourcePackage.getSrcGenPackage(); - MainGenerator mg = new MainGenerator(); - srcGenPack.addUnit(mg.createMain(modelElement, deployedComponents, deployedPorts, context)); + MainGenerator mg = + new MainGenerator(modelElement, deployedComponents, deployedPorts, context); + srcGenPack.addUnit(mg.createMain()); } /** Adds the build process files: configure and Makedefs. */ diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg index 1c7db896..62dd488c 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg @@ -6,6 +6,7 @@ MainFile(UNIT_NAME, CYCLE_TIME_IN_MILLIS, WAITING_SLEEPTIME_IN_MICROS, SYSTEM_INCLUDES, + SYNC_BOX_SIZE, SYNC_BOX_SETUP_CODE, SYSTEM_INIT_CODE, WORKER_CODE) ::= << @@ -61,7 +62,7 @@ int main(int argc, char** argv) { // TODO: initialize ControlCenter connection // snychronization message box - sync_inbox = can_inbox_create("$UNIT_NAME$_sync_inbox", 2); + sync_inbox = can_inbox_create("$UNIT_NAME$_sync_inbox", $SYNC_BOX_SIZE$); $SYNC_BOX_SETUP_CODE$ // application message boxes diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java index d3f470c0..d55a37e6 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java @@ -40,10 +40,10 @@ import org.fortiss.af3.generator.common.model.source.StaticContentSourceUnit; */ public final class RasPiCTemplates { /** Returns the 'main.c' file configured using the given arguments. */ - public static AbstractUnit - getMainCFile(String unitName, boolean coordinatorOrWorker, int canIdUnitDone, - int cycletimeInMillis, int waitingSleepInMicros, String systemIncludes, - String syncBoxSetupCode, String systemInitCode, String workerCode) { + public static AbstractUnit getMainCFile(String unitName, boolean coordinatorOrWorker, + int canIdUnitDone, int cycletimeInMillis, int waitingSleepInMicros, + String systemIncludes, int syncBoxSize, String syncBoxSetupCode, String systemInitCode, + String workerCode) { StringTemplate template = makeTemplate("MainFile.stg", "MainFile"); template.setAttribute("UNIT_NAME", unitName); template.setAttribute("COORDINATOR_OR_WORKER", coordinatorOrWorker ? 1 : 0); @@ -51,6 +51,7 @@ public final class RasPiCTemplates { template.setAttribute("CYCLE_TIME_IN_MILLIS", cycletimeInMillis); template.setAttribute("WAITING_SLEEPTIME_IN_MICROS", waitingSleepInMicros); template.setAttribute("SYSTEM_INCLUDES", systemIncludes); + template.setAttribute("SYNC_BOX_SIZE", syncBoxSize); template.setAttribute("SYNC_BOX_SETUP_CODE", syncBoxSetupCode); template.setAttribute("SYSTEM_INIT_CODE", systemInitCode); template.setAttribute("WORKER_CODE", workerCode); -- GitLab