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 a8a8c4447ae2d838c8e5d2b3f99bca34f8388ef1..74b343d8ebe8cb6dc3fb016c7f4c9bae6d920855 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 @@ -43,9 +43,50 @@ class MainGenerator { public AbstractUnit createMain(RaspberryPi executionUnit, List<Pair<ExecutionUnit, Component>> deployedComponents, List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) { - // TODO: generate worker and syncbox code + String includes = createIncludes(deployedComponents); + // TODO: syncbox code + String initCode = createInitCode(deployedComponents); + String workerCode = createWorkerCode(deployedComponents); return getMainCFile(executionUnit.getName(), executionUnit.isCoordinatorUnit(), - executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), 250, - "// TODO\n", "// TODO\n"); + executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), 250, includes, + "// TODO\n", initCode, workerCode); + } + + /** Creates the includes of the system headers. */ + private String createIncludes(List<Pair<ExecutionUnit, Component>> deployedComponents) { + StringBuilder sb = new StringBuilder(); + for(Pair<ExecutionUnit, Component> p : deployedComponents) { + Component c = p.getSecond(); + sb.append("#include <" + c.getName() + "_ID_" + c.getId() + ".h>\n"); + } + return sb.toString(); + } + + /** Create the worker code. */ + private String createWorkerCode(List<Pair<ExecutionUnit, Component>> deployedComponents) { + StringBuilder sb = new StringBuilder(); + for(Pair<ExecutionUnit, Component> p : deployedComponents) { + Component c = p.getSecond(); + sb.append(makeCall("perform_step", c)); + } + return sb.toString(); + } + + /** Create the initialize code. */ + private String createInitCode(List<Pair<ExecutionUnit, Component>> deployedComponents) { + StringBuilder sb = new StringBuilder(); + for(Pair<ExecutionUnit, Component> p : deployedComponents) { + Component c = p.getSecond(); + sb.append(makeCall("init", c)); + } + return sb.toString(); + } + + /** Creates the function call code. */ + private String makeCall(String function, Component c) { + StringBuilder sb = new StringBuilder(); + sb.append(function).append('_').append(c.getName()); + sb.append("_ID_").append(c.getId()).append("();\n"); + return sb.toString(); } } 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 e3e3332f40ce0b41852356b0bd267e0906ff56c0..ff4a7bb3b8f120d40167e7b28d1d54affa35bd80 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 @@ -69,8 +69,11 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry /** Folder name for linkable static library files. */ private static final String LIB_SUB_PACKAGE_NAME = "lib"; /** Default library names to be used always. */ - // Note that the order is important! + // Note that the order is important (GCC linker crap!) private static final String LIB_NAMES = "af3pihal rt pthread"; + /** Default library names extended with brick. */ + // Note that the order is important (GCC linker crap!) + private static final String LIB_NAMES_WITH_BRICK = "brick " + LIB_NAMES; /** Constructor. */ public RaspberryPIExecutable(RaspberryPi modelElement) { 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 b274e5ff7da39e2f88ede1878c5f21a6477ccafd..1c7db89666202c0532daee255799f2f0df2757ef 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 @@ -5,8 +5,14 @@ MainFile(UNIT_NAME, CAN_ID_UNIT_DONE, CYCLE_TIME_IN_MILLIS, WAITING_SLEEPTIME_IN_MICROS, + SYSTEM_INCLUDES, SYNC_BOX_SETUP_CODE, + SYSTEM_INIT_CODE, WORKER_CODE) ::= << +// due to current data dictionary declaration of GENTYPE_boolean +// system include must be first +$SYSTEM_INCLUDES$ + #include <stdbool.h> #include <stddef.h> #include <unistd.h> @@ -20,6 +26,7 @@ MainFile(UNIT_NAME, #include <protocol_coordinator.h> #include <protocol_factory.h> + #define WAITING_SLEEPTIME_IN_MICROS (uint64_t)$WAITING_SLEEPTIME_IN_MICROS$ #define STOP_AT_LOGICAL_CLOCK (uint64_t)0 // run infinitely @@ -78,6 +85,8 @@ int main(int argc, char** argv) { app_inbox, app_outbox, 0); + + $SYSTEM_INIT_CODE$ #if $COORDINATOR_OR_WORKER$ int result = protocol_coordinator_main(can_config, clock_config, computation_config); 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 9e05e647ffda9998347788a7a1f7ed12c600107d..d3f470c0ece4042e312f0b434da15617e1536400 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,16 +40,19 @@ 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 syncBoxSetupCode, String workerCode) { + public static AbstractUnit + getMainCFile(String unitName, boolean coordinatorOrWorker, int canIdUnitDone, + int cycletimeInMillis, int waitingSleepInMicros, String systemIncludes, + 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); template.setAttribute("CAN_ID_UNIT_DONE", canIdUnitDone); template.setAttribute("CYCLE_TIME_IN_MILLIS", cycletimeInMillis); template.setAttribute("WAITING_SLEEPTIME_IN_MICROS", waitingSleepInMicros); + template.setAttribute("SYSTEM_INCLUDES", systemIncludes); template.setAttribute("SYNC_BOX_SETUP_CODE", syncBoxSetupCode); + template.setAttribute("SYSTEM_INIT_CODE", systemInitCode); template.setAttribute("WORKER_CODE", workerCode); StaticContentSourceUnit unit = createStaticContentSourceUnit("main.c", template.toString(), false);