dol: initial epiphany code generator (untested)
[jump.git] / dol / src / dol / visitor / epiphany / template / process_Wrapper.c
1 /* @@PROCESSNAME@@_Wrapper
2  * ===================================================================== */
3 #include <e_lib.h>
4 #include <string.h>
5 #include "../esrc/@@PROCESSNAME@@.h"
6 #include "../shared.h"
7 #include "ports.h"
8 #include "index.h"
9
10 shm_t shm SECTION(".shared_dram");
11
12 /* DOL structures
13  * ===================================================================== */
14 struct _DOL_wptr @@PROCESSNAME@@_wptr = {
15         1,              /* active   */
16         {0,0,0,0}       /* instance */
17 };
18
19 @@PROCESSNAME@@_State @@PROCESSNAME@@_local;
20 DOLProcess @@PROCESSNAME@@_process = {
21         &@@PROCESSNAME@@_local,
22         &@@PROCESSNAME@@_init,
23         &@@PROCESSNAME@@_fire,
24         &@@PROCESSNAME@@_wptr,
25 };
26
27 /* Port Read/Write Functions
28  * ===================================================================== */
29 @@PORTFUNCTIONS@@
30
31 /* Port Mapping
32  * ===================================================================== */
33 #define NUM_PORTS @@NUM_PORTS@@
34 port_t ports[NUM_PORTS] = {
35 @@PORTMAPPING@@
36 };
37
38 port_t *get_port(void *port)
39 {
40         for(int i = 0; i < NUM_PORTS; i++) {
41                 if(!strncmp(ports[i].name, port, PORTNAME_MAXLEN)) {
42                         /* found the port */
43                         return(&ports[i]);
44                 }
45         }
46         return(NULL);
47 }
48
49 /* eCore entry point
50  * ===================================================================== */
51 int main(void)
52 {
53         int index = core_id2lin(e_get_coreid());
54         int state = 0;
55
56         @@PROCESSNAME@@_process.init((struct _DOLProcess_struct*)&@@PROCESSNAME@@_process);
57         while(@@PROCESSNAME@@_process.wptr->active) {
58                 shm.states[index] = ++state;
59                 @@PROCESSNAME@@_process.fire((struct _DOLProcess_struct*)&@@PROCESSNAME@@_process);
60         }
61
62         shm.states[index] = -1;
63         while(1);
64 }
65