Skip to content
Snippets Groups Projects
Commit 5040a9d3 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Added component code initialization and perform step function calls.

refs 3079
parent 5b9982ba
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
......@@ -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) {
......
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment