2 #include "rtems_process_wrapper.h"
7 void DOL_read(void *port, void *buf, int len, DOLProcess *process) {
8 RtemsProcessWrapper* process_wrapper = (RtemsProcessWrapper*)process->wptr;
11 #ifdef WORKLOAD_EXTRACT
12 SHOW_DEBUG("log start_read");
13 SHOW_DEBUG_INT((int)get_cycle());
14 SHOW_DEBUG_INT((int)port);
15 SHOW_DEBUG_INT((int)(process_wrapper->start_line));
16 SHOW_DEBUG_INT((int)(process_wrapper->end_line));
17 SHOW_DEBUG_INT((int)len);
20 #ifdef MPARM_SCRATCHPAD_QUEUE
21 for (i = 0; i < process_wrapper->number_of_in_ports; i++) {
22 // len not taken into account yet !!!!!!!
23 if (process_wrapper->in_port_id[i] == (int)port) {
24 SCRATCH_QUEUE_CONSUMER* queue_id =
25 (SCRATCH_QUEUE_CONSUMER*)process_wrapper->in_queue_id[i];
27 #if defined (QUEUE_BUFF_IN_PRODUCER)
28 scratch_queue_read(queue_id, (char *)buf, len);
29 #elif defined (QUEUE_BUFF_IN_PRODUCER_DMA)
30 scratch_queue_read_dma(queue_id, (char *)buf, len);
31 #elif defined (QUEUE_BUFF_IN_CONSUMER)
32 scratch_queue_read(queue_id, (char *)buf, len);
33 #elif defined (QUEUE_BUFF_IN_CONSUMER_DMA)
34 scratch_queue_read(queue_id, (char *)buf, len);
35 #elif defined (QUEUE_BUFF_IN_SHARDMEM)
36 scratch_queue_read(queue_id, (char *)buf, len);
37 #elif defined (QUEUE_BUFF_SHAPER)
38 scratch_queue_read_2(queue_id, (char *)buf, len);
44 for (i = 0; i < process_wrapper->number_of_ports; i++) {
45 if (process_wrapper->port_id[i] == (int)port) {
46 int queue_id = process_wrapper->port_queue_id[i];
49 //receive message byte-per-byte
50 for (j = 0; j < len; j++) {
52 rtems_message_queue_receive(
56 RTEMS_DEFAULT_ATTRIBUTES,
62 #endif // end MPARM_SCRATCHPAD_QUEUE
64 //SHOW_DEBUG("read from app");
65 //SHOW_DEBUG_INT(*(int *)buf);
67 #ifdef WORKLOAD_EXTRACT
68 SHOW_DEBUG("log end_read");
69 SHOW_DEBUG_INT((int)get_cycle());
70 SHOW_DEBUG_INT((int)port);
77 void DOL_write(void *port, void *buf, int len, DOLProcess *process) {
78 RtemsProcessWrapper* process_wrapper = (RtemsProcessWrapper*)process->wptr;
81 #ifdef WORKLOAD_EXTRACT
82 SHOW_DEBUG("log start_write");
83 SHOW_DEBUG_INT((int)get_cycle());
84 SHOW_DEBUG_INT((int)port);
85 SHOW_DEBUG_INT((int)(process_wrapper->start_line));
86 SHOW_DEBUG_INT((int)(process_wrapper->end_line));
87 SHOW_DEBUG_INT((int)len);
90 #if defined MPARM_SCRATCHPAD_QUEUE
91 for (i = 0; i < process_wrapper->number_of_out_ports; i++) {
92 if (process_wrapper->out_port_id[i] == (int)port) {
93 SCRATCH_QUEUE_PRODUCER* queue_id =
94 (SCRATCH_QUEUE_PRODUCER*)process_wrapper->out_queue_id[i];
97 #if defined (QUEUE_BUFF_IN_PRODUCER) || (QUEUE_BUFF_IN_CONSUMER)
98 scratch_queue_write(queue_id, (char *)buf, len);
99 #elif defined (QUEUE_BUFF_IN_PRODUCER_DMA) || (QUEUE_BUFF_IN_CONSUMER_DMA)
100 scratch_queue_write_dma(queue_id, (char *)buf, len);
101 #elif defined (QUEUE_BUFF_IN_SHARDMEM)
102 scratch_queue_write(queue_id, (char *)buf, len);
103 #elif defined(QUEUE_BUFF_SHAPER)
104 scratch_queue_write_2(queue_id, (char *)buf, len); // (2) shaper
111 for (i = 0; i < process_wrapper->number_of_ports; i++) {
112 if (process_wrapper->port_id[i] == (int)port) {
113 int queue_id = process_wrapper->port_queue_id[i];
114 rtems_status_code status;
117 //send message byte-per-byte
118 for (j = 0; j < len; j++) {
120 status = rtems_message_queue_send(queue_id, buf + j, 1);
121 if (status != RTEMS_SUCCESSFUL) {
122 rtems_task_wake_after(0);
124 } while (status != RTEMS_SUCCESSFUL);
130 #endif // end MPARM_SCRATCHPAD_QUEUE
132 #ifdef WORKLOAD_EXTRACT
133 SHOW_DEBUG("log end_write");
134 SHOW_DEBUG_INT((int)get_cycle());
135 SHOW_DEBUG_INT((int)port);
142 void DOL_detach(DOLProcess *process) {
143 //printf("[%s] DOL_detach.\n", (char*)(process->local));
144 ((RtemsProcessWrapper*)process->wptr)->is_detached = 1;
148 * Gets an index of a string, where the index must be separated by
149 * a character specified in tokens.
150 * Returns -1, when an error occurs.
153 * getIndex("name_1_2", "_", 0) will return 1.
154 * getIndex("name_1_2", "_", 1) will return 2.
156 * @param string string to parse
157 * @param tokens delimiter of indices
158 * @param indexNumber position of index (starting at 0)
160 int getIndex(const char* string, char* tokens, int indexNumber) {
165 string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
167 fprintf(stderr, "getIndex(): could not allocate memory.\n");
171 strcpy(string_copy, string);
173 token_pointer = strtok(string_copy, tokens);
175 token_pointer = strtok(NULL, tokens);
177 } while (index <= indexNumber && token_pointer != 0);
180 index = atoi(token_pointer);
190 * Create the port name of an iterated port based on its basename and the
193 * @param port buffer where the result is stored (created using
195 * @param base basename of the port
196 * @param number_of_indices number of dimensions of the port
197 * @param index_range_pairs index and range values for each dimension
199 int *createPort(int *port, int base, int number_of_indices,
200 int index_range_pairs, ...) {
207 va_start(marker, index_range_pairs);
209 value = index_range_pairs;
210 for (i = 0; i < number_of_indices; i++) {
212 value = va_arg(marker, int);
214 if (i < number_of_indices - 1) {
215 value = va_arg(marker, int);
220 for (i = 0; i < number_of_indices; i++) {
223 for (j = 1; j < number_of_indices - i; j ++) {
226 *port += index[i] * weight;
230 switch (number_of_indices) {
232 *port = base + index[0];
235 *port = base + index[0] * range[1]
239 *port = base + index[0] * range[1] * range[2]
240 + index[1] * range[0]
244 *port = base + index[0] * range[1] * range[2] * range[3]
245 + index[1] * range[2] * range[3]
246 + index[2] * range[3]