c72022b0a0e569aaaa161fa78292ecadbb3dd383
[jump.git] / dol / src / dol / visitor / rtems / lib / rtems_process_wrapper.h
1 #ifndef __RTEMS_PROCESS_WRAPPER_H__
2 #define __RTEMS_PROCESS_WRAPPER_H__
3
4 #include <bsp.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdarg.h>
8 #include <string.h>
9 #include "dol.h"
10
11 #ifdef MPARM_SCRATCHPAD_QUEUE
12 #include "scratch_queue.h"
13 #endif
14
15 #ifdef MPARM
16 #define printf(format ...) { char stringBuffer[80]; sprintf(stringBuffer, format); SHOW_DEBUG(stringBuffer); }
17 #endif
18
19 typedef struct _process_wrapper {
20     DOLProcess               *dol_process;
21     char*                    name;
22     int*                     index;
23     int                      is_detached;
24     int                      priority;
25 #ifdef WORKLOAD_EXTRACT
26     int                      start_line;
27     int                      end_line;
28 #endif
29 #ifdef MPARM_SCRATCHPAD_QUEUE
30     int*                     in_port_id;
31     int*                     out_port_id;
32     SCRATCH_QUEUE_PRODUCER** out_queue_id;
33     SCRATCH_QUEUE_CONSUMER** in_queue_id;
34     int                      number_of_in_ports;
35     int                      number_of_out_ports;
36 #else  // for pc396
37     int*                     port_id;
38     int*                     port_queue_id;
39     int                      number_of_ports;
40 #endif
41 } RtemsProcessWrapper;
42
43 // define queue memory in consumer scratchpad
44 //#define QUEUE_IN_CONSUMER
45
46 /**
47  * Gets an index of a string, where the index must be separated by
48  * a character specified in tokens.
49  * Returns -1, when an error occurs.
50  *
51  * Example:
52  * getIndex("name_1_2", "_", 0) will return 1.
53  * getIndex("name_1_2", "_", 1) will return 2.
54  *
55  * @param string string to parse
56  * @param tokens delimiter of indices
57  * @param indexNumber position of index (starting at 0)
58  */
59 int getIndex(const char* string, char* tokens, int indexNumber);
60
61 /**
62  * Create the port name of an iterated port based on its basename and the
63  * given indices.
64  *
65  * @param port buffer where the result is stored (created using
66  *             CREATEPORTVAR)
67  * @param base basename of the port
68  * @param number_of_indices number of dimensions of the port
69  * @param index_range_pairs index and range values for each dimension
70  */
71 int *createPort(int *port, int base, int number_of_indices, int index_range_pairs, ...);
72
73 //DOL macros
74 #define GETINDEX(dimension) \
75     ((RtemsProcessWrapper*)(p->wptr))->index[dimension]
76
77 #define CREATEPORTVAR(name) \
78     int name
79
80 #define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \
81     createPort(&port, base, number_of_indices, index_range_pairs)
82
83 #ifdef PERFORMANCE_EXTRACT
84 #include "Performance_Extraction.h"
85 #endif
86
87 #ifdef MPARM
88 extern unsigned int active_processes;
89 inline void Cleanup() {
90     register rtems_interrupt_level level;
91     rtems_interrupt_disable(level);
92     active_processes--;
93
94     if(active_processes==0) {
95 #ifdef PERFORMANCE_EXTRACT
96         performance_extraction.write_to_xml_file("calibration");
97 #endif
98         printf("All processes detached.");
99         rtems_interrupt_enable(level);
100         exit(0);
101     }
102     rtems_interrupt_enable(level);
103 }
104 #endif
105
106 #endif