DOL 'square' example including Makefile
authorSebastian <basti@sraa.de>
Mon, 19 Aug 2013 21:29:21 +0000 (23:29 +0200)
committerSebastian <basti@sraa.de>
Mon, 19 Aug 2013 21:29:21 +0000 (23:29 +0200)
dol_example1/Makefile [new file with mode: 0644]
dol_example1/example1.xml [new file with mode: 0644]
dol_example1/src/Makefile [new file with mode: 0644]
dol_example1/src/consumer.c [new file with mode: 0644]
dol_example1/src/consumer.h [new file with mode: 0644]
dol_example1/src/example1.xml [new file with mode: 0644]
dol_example1/src/generator.c [new file with mode: 0644]
dol_example1/src/generator.h [new file with mode: 0644]
dol_example1/src/global.h [new file with mode: 0644]
dol_example1/src/square.c [new file with mode: 0644]
dol_example1/src/square.h [new file with mode: 0644]

diff --git a/dol_example1/Makefile b/dol_example1/Makefile
new file mode 100644 (file)
index 0000000..b97cf9c
--- /dev/null
@@ -0,0 +1,81 @@
+# Makefile to generate a DOL program
+
+# Target List:
+#      all     -- generate the main executable [default]
+#      run     -- run the main executable
+#      systemc -- generate SystemC code and Makefile.new
+#      dotty   -- show flattened process network
+#      clean   -- clean all generated files
+
+PROGRAM = example1
+
+# change according to your system
+DOLPATH     = /home/basti/dol/bin
+SYSTEMC_INC = /home/basti/systemc/include
+SYSTEMC_LIB = /home/basti/systemc/lib-linux64/libsystemc.a
+
+# list of programs
+JAVA   ?= java
+JAVAC  ?= javac
+DOTTY  ?= dotty
+ECHO   ?= echo
+SED    ?= sed
+CP     ?= cp
+RM     ?= rm
+
+# don't change anything below
+# ===========================================================================
+
+CLASSPATH = $(DOLPATH)/dol.jar:$(DOLPATH)/jdom.jar:$(DOLPATH)/xercesImpl.jar
+.PHONY : all run systemc dotty clean 
+
+all: $(PROGRAM)
+
+systemc: systemc/src/Makefile.new
+
+run: $(PROGRAM)
+       @$(ECHO) "\t[RUN]\t$^"
+       @./$(PROGRAM)
+
+clean:
+       @$(ECHO) "\t[CLEAN]"
+       @$(RM) -rf $(PROGRAM) systemc/ $(PROGRAM)_flattened.xml \
+               $(PROGRAM)_Generator.java $(PROGRAM)_Generator.class \
+               $(PROGRAM).dot profile.txt
+
+$(PROGRAM): systemc/src/sc_application
+       @$(ECHO) "\t[COPY]\t$@"
+       @$(CP) $^ $@
+
+systemc/src/sc_application: systemc/src/Makefile.new
+       @$(ECHO) "\t[MAKE]\t$<"
+       @$(MAKE) -f Makefile.new -C systemc/src
+
+systemc/src/Makefile.new: systemc/src/Makefile
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(SED) -e 's@^SYSTEMC_INC.*@SYSTEMC_INC = -I $(SYSTEMC_INC)@' \
+               -e 's@^SYSTEMC_LIB.*@SYSTEMC_LIB = $(SYSTEMC_LIB)@' \
+               -e 's@# -lpthread@-lpthread #@' \
+               systemc/src/Makefile > systemc/src/Makefile.new
+
+systemc/src/Makefile: $(PROGRAM)_flattened.xml
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \
+               -H systemc -c >/dev/null
+       
+$(PROGRAM)_flattened.xml: $(PROGRAM).xml
+       @$(ECHO) "\t[FLAT]\t$^"
+       @$(JAVA) -cp $(CLASSPATH) dol.helper.flattener.XMLFlattener \
+               $(PROGRAM).xml $(PROGRAM)_Generator >/dev/null
+       @$(JAVAC) $(PROGRAM)_Generator.java
+       @$(JAVA) $(PROGRAM)_Generator > $(PROGRAM)_flattened.xml
+
+$(PROGRAM).dot: $(PROGRAM)_flattened.xml
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \
+               -D $(PROGRAM).dot -c >/dev/null
+
+dotty: $(PROGRAM).dot
+       @$(ECHO) "\t[RUN]\t$(DOTTY) $(PROGRAM).dot"
+       @$(DOTTY) $(PROGRAM).dot
+
diff --git a/dol_example1/example1.xml b/dol_example1/example1.xml
new file mode 100644 (file)
index 0000000..d5abe14
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<processnetwork name="example1"
+       xmlns="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK" 
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+       xsi:schemaLocation="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK
+       http://www.tik.ee.ethz.ch/~shapes/schema/processnetwork.xsd">
+
+       <!-- processes -->
+       <process name="generator"> 
+               <port type="output" name="1"/>
+               <source type="c" location="generator.c"/>
+       </process>
+
+       <process name="consumer"> 
+               <port type="input" name="1"/> 
+               <source type="c" location="consumer.c"/>
+       </process>
+
+       <process name="square"> 
+               <port type="input" name="1"/>
+               <port type="output" name="2"/>
+               <source type="c" location="square.c"/>
+       </process>
+
+       <!-- sw_channels -->
+       <sw_channel type="fifo" size="10" name="C1">
+               <port type="input" name="0"/>
+               <port type="output" name="1"/>
+       </sw_channel>
+
+       <sw_channel type="fifo" size="10" name="C2">
+               <port type="input" name="0"/>
+               <port type="output" name="1"/>
+       </sw_channel>
+
+       <!-- connections -->
+       <connection name="g-c">
+               <origin name="generator">
+                       <port name="1"/>
+               </origin>
+               <target name="C1">
+                       <port name="0"/>
+               </target>
+       </connection>
+
+       <connection name="c-c">
+               <origin name="C2">
+                       <port name="1"/>
+               </origin>
+               <target name="consumer">
+                       <port name="1"/>
+               </target>
+       </connection>
+
+       <connection name="s-c">
+               <origin name="square">
+                       <port name="2"/>
+               </origin>
+               <target name="C2">
+                       <port name="0"/>
+               </target>
+       </connection>
+
+       <connection name="c-s">
+               <origin name="C1">
+                       <port name="1"/>
+               </origin>
+               <target name="square">
+                       <port name="1"/>
+               </target>
+       </connection>
+</processnetwork>
diff --git a/dol_example1/src/Makefile b/dol_example1/src/Makefile
new file mode 100644 (file)
index 0000000..a6aa502
--- /dev/null
@@ -0,0 +1,75 @@
+# Makefile to generate a DOL program
+
+# Target List:
+#      dotty   -- show flattened process network
+#      systemc -- generate SystemC code
+#      all     -- generate the main executable
+#      run     -- run SystemC example
+
+PROGRAM = example1
+
+# change according to your system
+DOLPATH     = /home/basti/dol/bin
+SYSTEMC_INC = /home/basti/systemc/include
+SYSTEMC_LIB = /home/basti/systemc/lib-linux64/libsystemc.a
+
+# list of programs
+JAVA   ?= java
+JAVAC  ?= javac
+DOTTY  ?= dotty
+ECHO   ?= echo
+SED    ?= sed
+CP     ?= cp
+RM     ?= rm
+
+# don't change anything below
+# ===========================================================================
+
+CLASSPATH = $(DOLPATH)/dol.jar:$(DOLPATH)/jdom.jar:$(DOLPATH)/xercesImpl.jar
+
+all: $(PROGRAM)
+
+systemc: systemc/src/Makefile.new
+
+clean:
+       @$(ECHO) "\t[CLEAN]"
+       @$(RM) -rf $(PROGRAM) systemc/ $(PROGRAM)_flattened.xml \
+               $(PROGRAM)_Generator.java $(PROGRAM)_Generator.class \
+               $(PROGRAM).dot
+
+$(PROGRAM): systemc/src/sc_application
+       @$(ECHO) "\t[COPY]\t$@"
+       @$(CP) $^ $@
+
+systemc/src/sc_application: systemc/src/Makefile.new
+       @$(ECHO) "\t[MAKE]\t$<"
+       @$(MAKE) -f Makefile.new -C systemc/src
+
+systemc/src/Makefile.new: systemc/src/Makefile
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(SED) -e 's@^SYSTEMC_INC.*@SYSTEMC_INC = -I $(SYSTEMC_INC)@' \
+               -e 's@^SYSTEMC_LIB.*@SYSTEMC_LIB = $(SYSTEMC_LIB)@' \
+               -e 's@# -lpthread@-lpthread #@' \
+               systemc/src/Makefile > systemc/src/Makefile.new
+
+systemc/src/Makefile: $(PROGRAM)_flattened.xml
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \
+               -H systemc -c >/dev/null
+       
+$(PROGRAM)_flattened.xml: $(PROGRAM).xml
+       @$(ECHO) "\t[FLAT]\t$^"
+       @$(JAVA) -cp $(CLASSPATH) dol.helper.flattener.XMLFlattener \
+               $(PROGRAM).xml $(PROGRAM)_Generator >/dev/null
+       @$(JAVAC) $(PROGRAM)_Generator.java
+       @$(JAVA) $(PROGRAM)_Generator > $(PROGRAM)_flattened.xml
+
+$(PROGRAM).dot: $(PROGRAM)_flattened.xml
+       @$(ECHO) "\t[GEN]\t$@"
+       @$(JAVA) -cp $(CLASSPATH) dol.main.Main -P $(PROGRAM)_flattened.xml \
+               -D $(PROGRAM).dot -c >/dev/null
+
+dotty: $(PROGRAM).dot
+       @$(ECHO) "\t[RUN]\t$(DOTTY) $(PROGRAM).dot"
+       @$(DOTTY) $(PROGRAM).dot
+
diff --git a/dol_example1/src/consumer.c b/dol_example1/src/consumer.c
new file mode 100644 (file)
index 0000000..711614b
--- /dev/null
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+#include "consumer.h"
+
+void consumer_init(DOLProcess *p) {
+    sprintf(p->local->name, "consumer");
+    p->local->index = 0;
+    p->local->len = LENGTH;
+}
+
+int consumer_fire(DOLProcess *p) {
+    float c;
+    if (p->local->index < p->local->len) {
+        DOL_read((void*)PORT_IN, &c, sizeof(float), p);
+        printf("%s: %f\n", p->local->name, c);
+        p->local->index++;
+    }
+
+    if (p->local->index >= p->local->len) {
+        DOL_detach(p);
+        return -1;
+    }
+
+    return 0;
+}
+
diff --git a/dol_example1/src/consumer.h b/dol_example1/src/consumer.h
new file mode 100644 (file)
index 0000000..677609a
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef CONSUMER_H
+#define CONSUMER_H
+
+#include <dol.h>
+#include "global.h"
+
+#define PORT_IN 1
+
+typedef struct _local_states {
+    char name[10];
+    int index;
+    int len;
+} Consumer_State;
+
+void consumer_init(DOLProcess *);
+int consumer_fire(DOLProcess *);
+
+#endif
diff --git a/dol_example1/src/example1.xml b/dol_example1/src/example1.xml
new file mode 100644 (file)
index 0000000..d5abe14
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<processnetwork name="example1"
+       xmlns="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK" 
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+       xsi:schemaLocation="http://www.tik.ee.ethz.ch/~shapes/schema/PROCESSNETWORK
+       http://www.tik.ee.ethz.ch/~shapes/schema/processnetwork.xsd">
+
+       <!-- processes -->
+       <process name="generator"> 
+               <port type="output" name="1"/>
+               <source type="c" location="generator.c"/>
+       </process>
+
+       <process name="consumer"> 
+               <port type="input" name="1"/> 
+               <source type="c" location="consumer.c"/>
+       </process>
+
+       <process name="square"> 
+               <port type="input" name="1"/>
+               <port type="output" name="2"/>
+               <source type="c" location="square.c"/>
+       </process>
+
+       <!-- sw_channels -->
+       <sw_channel type="fifo" size="10" name="C1">
+               <port type="input" name="0"/>
+               <port type="output" name="1"/>
+       </sw_channel>
+
+       <sw_channel type="fifo" size="10" name="C2">
+               <port type="input" name="0"/>
+               <port type="output" name="1"/>
+       </sw_channel>
+
+       <!-- connections -->
+       <connection name="g-c">
+               <origin name="generator">
+                       <port name="1"/>
+               </origin>
+               <target name="C1">
+                       <port name="0"/>
+               </target>
+       </connection>
+
+       <connection name="c-c">
+               <origin name="C2">
+                       <port name="1"/>
+               </origin>
+               <target name="consumer">
+                       <port name="1"/>
+               </target>
+       </connection>
+
+       <connection name="s-c">
+               <origin name="square">
+                       <port name="2"/>
+               </origin>
+               <target name="C2">
+                       <port name="0"/>
+               </target>
+       </connection>
+
+       <connection name="c-s">
+               <origin name="C1">
+                       <port name="1"/>
+               </origin>
+               <target name="square">
+                       <port name="1"/>
+               </target>
+       </connection>
+</processnetwork>
diff --git a/dol_example1/src/generator.c b/dol_example1/src/generator.c
new file mode 100644 (file)
index 0000000..88c801f
--- /dev/null
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "generator.h"
+
+// initialization function
+void generator_init(DOLProcess *p) {
+    p->local->index = 0;
+    p->local->len = LENGTH;
+}
+
+int generator_fire(DOLProcess *p) {
+
+    if (p->local->index < p->local->len) {
+        float x = (float)p->local->index;
+        DOL_write((void*)PORT_OUT, &(x), sizeof(float), p);
+        p->local->index++;
+    }
+
+    if (p->local->index >= p->local->len) {
+        DOL_detach(p);
+        return -1;
+    }
+
+    return 0;
+}
+
diff --git a/dol_example1/src/generator.h b/dol_example1/src/generator.h
new file mode 100644 (file)
index 0000000..b938a38
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef GENERATOR_H
+#define GENERATOR_H
+
+#include <dol.h>
+#include "global.h"
+
+#define  PORT_OUT 1
+
+typedef struct _local_states {
+    int index;
+    int len;
+} Generator_State;
+
+void generator_init(DOLProcess *);
+int generator_fire(DOLProcess *);
+
+#endif
diff --git a/dol_example1/src/global.h b/dol_example1/src/global.h
new file mode 100644 (file)
index 0000000..8197dec
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include <stdio.h>
+
+#define ARRAY_LEN 10
+#define DEBUG 1
+#define LENGTH 16
+
+#endif
diff --git a/dol_example1/src/square.c b/dol_example1/src/square.c
new file mode 100644 (file)
index 0000000..126378b
--- /dev/null
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+#include "square.h"
+
+void square_init(DOLProcess *p) {
+    p->local->index = 0;
+    p->local->len = LENGTH;
+}
+
+int square_fire(DOLProcess *p) {
+    float i;
+
+    if (p->local->index < p->local->len) {
+        DOL_read((void*)PORT_IN, &i, sizeof(float), p);
+        i = i*i;
+        DOL_write((void*)PORT_OUT, &i, sizeof(float), p);
+        p->local->index++;
+    }
+
+    if (p->local->index >= p->local->len) {
+        DOL_detach(p);
+        return -1;
+    }
+
+    return 0;
+}
+
diff --git a/dol_example1/src/square.h b/dol_example1/src/square.h
new file mode 100644 (file)
index 0000000..2db7edc
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef SQUARE_H
+#define SQUARE_H
+
+#include <dol.h>
+#include "global.h"
+
+#define PORT_IN  1
+#define PORT_OUT 2
+
+typedef struct _local_states {
+    int index;
+    int len;
+} Square_State;
+
+void square_init(DOLProcess *);
+int square_fire(DOLProcess *);
+
+#endif