dol: initial dol commit
[jump.git] / dol / src / dol / visitor / rtems / lib / rtems_process_wrapper.h
diff --git a/dol/src/dol/visitor/rtems/lib/rtems_process_wrapper.h b/dol/src/dol/visitor/rtems/lib/rtems_process_wrapper.h
new file mode 100644 (file)
index 0000000..c72022b
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef __RTEMS_PROCESS_WRAPPER_H__
+#define __RTEMS_PROCESS_WRAPPER_H__
+
+#include <bsp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include "dol.h"
+
+#ifdef MPARM_SCRATCHPAD_QUEUE
+#include "scratch_queue.h"
+#endif
+
+#ifdef MPARM
+#define printf(format ...) { char stringBuffer[80]; sprintf(stringBuffer, format); SHOW_DEBUG(stringBuffer); }
+#endif
+
+typedef struct _process_wrapper {
+    DOLProcess               *dol_process;
+    char*                    name;
+    int*                     index;
+    int                      is_detached;
+    int                      priority;
+#ifdef WORKLOAD_EXTRACT
+    int                      start_line;
+    int                      end_line;
+#endif
+#ifdef MPARM_SCRATCHPAD_QUEUE
+    int*                     in_port_id;
+    int*                     out_port_id;
+    SCRATCH_QUEUE_PRODUCER** out_queue_id;
+    SCRATCH_QUEUE_CONSUMER** in_queue_id;
+    int                      number_of_in_ports;
+    int                      number_of_out_ports;
+#else  // for pc396
+    int*                     port_id;
+    int*                     port_queue_id;
+    int                      number_of_ports;
+#endif
+} RtemsProcessWrapper;
+
+// define queue memory in consumer scratchpad
+//#define QUEUE_IN_CONSUMER
+
+/**
+ * Gets an index of a string, where the index must be separated by
+ * a character specified in tokens.
+ * Returns -1, when an error occurs.
+ *
+ * Example:
+ * getIndex("name_1_2", "_", 0) will return 1.
+ * getIndex("name_1_2", "_", 1) will return 2.
+ *
+ * @param string string to parse
+ * @param tokens delimiter of indices
+ * @param indexNumber position of index (starting at 0)
+ */
+int getIndex(const char* string, char* tokens, int indexNumber);
+
+/**
+ * Create the port name of an iterated port based on its basename and the
+ * given indices.
+ *
+ * @param port buffer where the result is stored (created using
+ *             CREATEPORTVAR)
+ * @param base basename of the port
+ * @param number_of_indices number of dimensions of the port
+ * @param index_range_pairs index and range values for each dimension
+ */
+int *createPort(int *port, int base, int number_of_indices, int index_range_pairs, ...);
+
+//DOL macros
+#define GETINDEX(dimension) \
+    ((RtemsProcessWrapper*)(p->wptr))->index[dimension]
+
+#define CREATEPORTVAR(name) \
+    int name
+
+#define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \
+    createPort(&port, base, number_of_indices, index_range_pairs)
+
+#ifdef PERFORMANCE_EXTRACT
+#include "Performance_Extraction.h"
+#endif
+
+#ifdef MPARM
+extern unsigned int active_processes;
+inline void Cleanup() {
+    register rtems_interrupt_level level;
+    rtems_interrupt_disable(level);
+    active_processes--;
+
+    if(active_processes==0) {
+#ifdef PERFORMANCE_EXTRACT
+        performance_extraction.write_to_xml_file("calibration");
+#endif
+        printf("All processes detached.");
+        rtems_interrupt_enable(level);
+        exit(0);
+    }
+    rtems_interrupt_enable(level);
+}
+#endif
+
+#endif