--- /dev/null
+#include <string.h>
+#include "rtems_process_wrapper.h"
+
+/**
+ *
+ */
+void DOL_read(void *port, void *buf, int len, DOLProcess *process) {
+ RtemsProcessWrapper* process_wrapper = (RtemsProcessWrapper*)process->wptr;
+ int i;
+
+#ifdef WORKLOAD_EXTRACT
+ SHOW_DEBUG("log start_read");
+ SHOW_DEBUG_INT((int)get_cycle());
+ SHOW_DEBUG_INT((int)port);
+ SHOW_DEBUG_INT((int)(process_wrapper->start_line));
+ SHOW_DEBUG_INT((int)(process_wrapper->end_line));
+ SHOW_DEBUG_INT((int)len);
+#endif
+
+#ifdef MPARM_SCRATCHPAD_QUEUE
+ for (i = 0; i < process_wrapper->number_of_in_ports; i++) {
+ // len not taken into account yet !!!!!!!
+ if (process_wrapper->in_port_id[i] == (int)port) {
+ SCRATCH_QUEUE_CONSUMER* queue_id =
+ (SCRATCH_QUEUE_CONSUMER*)process_wrapper->in_queue_id[i];
+
+#if defined (QUEUE_BUFF_IN_PRODUCER)
+ scratch_queue_read(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_PRODUCER_DMA)
+ scratch_queue_read_dma(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_CONSUMER)
+ scratch_queue_read(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_CONSUMER_DMA)
+ scratch_queue_read(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_SHARDMEM)
+ scratch_queue_read(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_SHAPER)
+ scratch_queue_read_2(queue_id, (char *)buf, len);
+#endif
+ break;
+ }
+ }
+#else // pc386
+ for (i = 0; i < process_wrapper->number_of_ports; i++) {
+ if (process_wrapper->port_id[i] == (int)port) {
+ int queue_id = process_wrapper->port_queue_id[i];
+ int j;
+
+ //receive message byte-per-byte
+ for (j = 0; j < len; j++) {
+ size_t size = 1;
+ rtems_message_queue_receive(
+ queue_id,
+ buf + j,
+ &size,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ RTEMS_NO_TIMEOUT);
+ }
+ break;
+ }
+ }
+#endif // end MPARM_SCRATCHPAD_QUEUE
+
+ //SHOW_DEBUG("read from app");
+ //SHOW_DEBUG_INT(*(int *)buf);
+
+#ifdef WORKLOAD_EXTRACT
+ SHOW_DEBUG("log end_read");
+ SHOW_DEBUG_INT((int)get_cycle());
+ SHOW_DEBUG_INT((int)port);
+#endif
+}
+
+/**
+ *
+ */
+void DOL_write(void *port, void *buf, int len, DOLProcess *process) {
+ RtemsProcessWrapper* process_wrapper = (RtemsProcessWrapper*)process->wptr;
+ int i;
+
+#ifdef WORKLOAD_EXTRACT
+ SHOW_DEBUG("log start_write");
+ SHOW_DEBUG_INT((int)get_cycle());
+ SHOW_DEBUG_INT((int)port);
+ SHOW_DEBUG_INT((int)(process_wrapper->start_line));
+ SHOW_DEBUG_INT((int)(process_wrapper->end_line));
+ SHOW_DEBUG_INT((int)len);
+#endif
+
+#if defined MPARM_SCRATCHPAD_QUEUE
+ for (i = 0; i < process_wrapper->number_of_out_ports; i++) {
+ if (process_wrapper->out_port_id[i] == (int)port) {
+ SCRATCH_QUEUE_PRODUCER* queue_id =
+ (SCRATCH_QUEUE_PRODUCER*)process_wrapper->out_queue_id[i];
+
+
+#if defined (QUEUE_BUFF_IN_PRODUCER) || (QUEUE_BUFF_IN_CONSUMER)
+ scratch_queue_write(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_PRODUCER_DMA) || (QUEUE_BUFF_IN_CONSUMER_DMA)
+ scratch_queue_write_dma(queue_id, (char *)buf, len);
+#elif defined (QUEUE_BUFF_IN_SHARDMEM)
+ scratch_queue_write(queue_id, (char *)buf, len);
+#elif defined(QUEUE_BUFF_SHAPER)
+ scratch_queue_write_2(queue_id, (char *)buf, len); // (2) shaper
+#endif
+
+ break;
+ }
+ }
+#else // pc386
+ for (i = 0; i < process_wrapper->number_of_ports; i++) {
+ if (process_wrapper->port_id[i] == (int)port) {
+ int queue_id = process_wrapper->port_queue_id[i];
+ rtems_status_code status;
+ int j;
+
+ //send message byte-per-byte
+ for (j = 0; j < len; j++) {
+ do {
+ status = rtems_message_queue_send(queue_id, buf + j, 1);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_task_wake_after(0);
+ }
+ } while (status != RTEMS_SUCCESSFUL);
+ }
+
+ break;
+ }
+ }
+#endif // end MPARM_SCRATCHPAD_QUEUE
+
+#ifdef WORKLOAD_EXTRACT
+ SHOW_DEBUG("log end_write");
+ SHOW_DEBUG_INT((int)get_cycle());
+ SHOW_DEBUG_INT((int)port);
+#endif
+}
+
+/**
+ *
+ */
+void DOL_detach(DOLProcess *process) {
+ //printf("[%s] DOL_detach.\n", (char*)(process->local));
+ ((RtemsProcessWrapper*)process->wptr)->is_detached = 1;
+}
+
+/**
+ * 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) {
+ char* string_copy;
+ char* token_pointer;
+ int index = 0;
+
+ string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
+ if (!string_copy) {
+ fprintf(stderr, "getIndex(): could not allocate memory.\n");
+ return -1;
+ }
+
+ strcpy(string_copy, string);
+
+ token_pointer = strtok(string_copy, tokens);
+ do {
+ token_pointer = strtok(NULL, tokens);
+ index++;
+ } while (index <= indexNumber && token_pointer != 0);
+
+ if (token_pointer) {
+ index = atoi(token_pointer);
+ free(string_copy);
+ return index;
+ }
+
+ free(string_copy);
+ return -1;
+}
+
+/**
+ * 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, ...) {
+ int index[4];
+ int range[4];
+ int i;
+ int value;
+
+ va_list marker;
+ va_start(marker, index_range_pairs);
+
+ value = index_range_pairs;
+ for (i = 0; i < number_of_indices; i++) {
+ index[i] = value;
+ value = va_arg(marker, int);
+ range[i] = value;
+ if (i < number_of_indices - 1) {
+ value = va_arg(marker, int);
+ }
+ }
+
+ *port = base;
+ for (i = 0; i < number_of_indices; i++) {
+ int j;
+ int weight = 1;
+ for (j = 1; j < number_of_indices - i; j ++) {
+ weight *= range[j];
+ }
+ *port += index[i] * weight;
+ }
+
+ /*
+ switch (number_of_indices) {
+ case 1:
+ *port = base + index[0];
+ break;
+ case 2:
+ *port = base + index[0] * range[1]
+ + index[1];
+ break;
+ case 3:
+ *port = base + index[0] * range[1] * range[2]
+ + index[1] * range[0]
+ + index[2];
+ break;
+ case 4:
+ *port = base + index[0] * range[1] * range[2] * range[3]
+ + index[1] * range[2] * range[3]
+ + index[2] * range[3]
+ + index[3];
+ break;
+ }
+ */
+
+ return port;
+}