dol: initial dol commit
[jump.git] / dol / src / dol / visitor / protothread / lib / dolSupport.h
1 #ifndef DOLSUPPORT_H\r
2 #define DOLSUPPORT_H\r
3 \r
4 #include "dol.h"\r
5 #include "ProcessWrapper.h"\r
6 #include "Fifo.h"\r
7 #include "WindowedFifo.h"\r
8 #include "pt.h"\r
9 \r
10 typedef struct _process_data {\r
11     int lc;\r
12     ProcessWrapper *wrapper;\r
13 } process_data;\r
14 \r
15 \r
16 #define DOL_read(port, buf, size, process) \\r
17     PT_WAIT_UNTIL((pt*)(p->wptr), read(port, buf, size, process) == size);\r
18 \r
19 #define DOL_write(port, buf, size, process) \\r
20     PT_WAIT_UNTIL((pt*)(p->wptr), write(port, buf, size, process) == size);\r
21 \r
22 #define DOL_reserve(port, buf, size, process) \\r
23     PT_WAIT_UNTIL((pt*)(p->wptr), reserve(port, (void**)buf, size, process) == size);\r
24 \r
25 #define DOL_release(port, process) \\r
26     release(port, process);\r
27 \r
28 #define DOL_capture(port, buf, size, process) \\r
29     PT_WAIT_UNTIL((pt*)(p->wptr), capture(port, (void**)buf, size, process) == size);\r
30 \r
31 #define DOL_consume(port, process) \\r
32     consume(port, process);\r
33 \r
34 void DOL_detach(DOLProcess* p);\r
35 \r
36 //macros to deal with iterated ports\r
37 /**\r
38  * macro to create a variable to store a port name\r
39  *\r
40  * @param name name of the variable\r
41  */\r
42 #define CREATEPORTVAR(name) static Fifo *name\r
43 \r
44 /**\r
45  * Create the port name of an iterated port based on its basename and the\r
46  * given indices.\r
47  *\r
48  * @param port buffer where the result is stored (created using\r
49  *             CREATEPORTVAR)\r
50  * @param base basename of the port\r
51  * @param number_of_indices number of dimensions of the port\r
52  * @param index_range_pairs index and range values for each dimension\r
53  */\r
54 \r
55 #define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \\r
56   createPort((void**)(&port), base, number_of_indices, index_range_pairs)\r
57 \r
58 #define GETINDEX(dimension) \\r
59   static_cast<ProcessWrapper *>((static_cast<process_data *>(p->wptr))->wrapper)->getIndex(dimension)\r
60 \r
61 void createPort(void** port, void* base, int number_of_indices, int index0, int range0);\r
62 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1);\r
63 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2);\r
64 void createPort(void** port, void* base, int number_of_indices, int index0, int range0, int index1, int range1, int index2, int range2, int index3, int range3);\r
65 \r
66 //fifo access functions\r
67 unsigned write(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
68 unsigned read(void* fifo, void* buf, unsigned len, DOLProcess* p);\r
69 \r
70 //windowed fifo access functions\r
71 unsigned reserve(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
72 void release(void* fifo, DOLProcess* p);\r
73 unsigned capture(void* fifo, void** destination, unsigned len, DOLProcess* p);\r
74 void consume(void* fifo, DOLProcess* p);\r
75 \r
76 #endif\r