+#include <bsp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rtems_process_wrapper.h"
+
+#ifdef WORKLOAD_EXTRACT
+#define DOL_read(port, buf, len, process) \
+{ ((RtemsProcessWrapper*)process->wptr)->end_line = __LINE__; \
+ DOL_read(port, buf, len, process); \
+ ((RtemsProcessWrapper*)process->wptr)->start_line = __LINE__; }
+
+#define DOL_write(port, buf, len, process) \
+{ ((RtemsProcessWrapper*)process->wptr)->end_line = __LINE__; \
+ DOL_write(port, buf, len, process); \
+ ((RtemsProcessWrapper*)process->wptr)->start_line = __LINE__; }
+#endif
+
+#ifdef PRINTF_TO_DEBUG
+#undef printf
+#define printf(...) \
+ do { \
+ char _buffer[128]; \
+ sprintf(_buffer, __VA_ARGS__); \
+ SHOW_DEBUG((int)_buffer); \
+ } while (0)
+#endif
+
+//#include "@PROCESSNAME@.c"
+
+//DOL-specific implementation
+rtems_task @PROCESSNAME@_task(rtems_task_argument argument) {
+ RtemsProcessWrapper* wrapper = (RtemsProcessWrapper*)argument;
+ DOLProcess* process;
+ LocalState state;
+ int number_of_activations = 0;
+ int i;
+ rtems_task_priority old_priority;
+
+ process = (DOLProcess *)malloc(sizeof(DOLProcess));
+ state = (LocalState)malloc(sizeof(@Processname@_State));
+ process->init = @PROCESSNAME@_init;
+ process->fire = @PROCESSNAME@_fire;
+ process->local = state;
+ process->wptr = wrapper;
+
+ //initialize the index array
+ wrapper->index = (int *)malloc(4 * sizeof(int));
+ for (i = 0; i < 4; i++) {
+ wrapper->index[i] = getIndex(wrapper->name, "_", i);
+ }
+
+ printf("Start process %s.\n", wrapper->name);
+ process->init(process);
+
+ //yield process such that other processes can be initialized
+#ifdef MPARM
+ do {
+ rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
+ } while((int)get_cycle() < 1511576);
+#endif
+ rtems_task_set_priority(RTEMS_SELF, wrapper->priority, &old_priority);
+
+ while (!wrapper->is_detached) {
+
+ //placeholder for periodic trigger
+
+#ifdef WORKLOAD_EXTRACT
+ wrapper->start_line = 0;
+ SHOW_DEBUG("log start_fire");
+ SHOW_DEBUG_INT((int)get_cycle());
+#endif
+
+ process->fire(process);
+
+#ifdef WORKLOAD_EXTRACT
+ SHOW_DEBUG("log end_fire");
+ SHOW_DEBUG_INT((int)get_cycle());
+ wrapper->end_line = 0;
+#endif
+ number_of_activations++;
+ }
+
+#ifdef MPARM_SCRATCHPAD_QUEUE
+ #ifdef QUEUE_BUFF_SHAPER
+ @ENDING_SHAPER@
+ #endif
+#else // pc386
+ //below is not necessary if no dynamic switching
+ //printf("Detached @PROCESSNAME@. Cleanup... ");
+ if (wrapper->index) {
+ free(wrapper->index);
+ } else {
+ printf("Could not free memory for index of @PROCESSNAME@.\n");
+ }
+
+ if (wrapper->port_id) {
+ free(wrapper->port_id);
+ } else {
+ printf("Could not free memory for port_id of @PROCESSNAME@.\n");
+ }
+
+ if (wrapper->port_queue_id) {
+ } else {
+ printf("Could not free memory for port_queue_id of @PROCESSNAME@.\n");
+ }
+#endif // MPARM_SCRATCHPAD_QUEUE
+ //printf("Done.\n");
+
+ printf("Detach process %s.\n", wrapper->name);
+#ifdef MPARM
+ Cleanup();
+#endif
+
+ rtems_task_delete(RTEMS_SELF);
+}