dol: fix shm_t contain the shm-buffers
[jump.git] / minidol / lib / Square_Wrapper.c
1 /* Square_Wrapper
2  * ===================================================================== */
3 #include <e_lib.h>
4 #include <string.h>
5 #include "../esrc/Square.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 Square_wptr = {
15         1,              /* active   */
16         {0,0,0,0}       /* instance */
17 };
18
19 Square_State Square_local;
20 DOLProcess Square_process = {
21         &Square_local,
22         &Square_init,
23         &Square_fire,
24         &Square_wptr,
25 };
26
27 /* Port Read/Write Functions
28  * ===================================================================== */
29 int size_0 (void)               { return(size_shm (&shm.buf0)); }
30 int level_0(void)               { return(level_shm(&shm.buf0)); }
31 int read_0 (void *buf, int len) { return(read_shm (&shm.buf0, buf, len)); }
32 int write_0(void *buf, int len) { return(write_shm(&shm.buf0, buf, len)); }
33 int size_1 (void)               { return(size_shm (&shm.buf1)); }
34 int level_1(void)               { return(level_shm(&shm.buf1)); }
35 int read_1 (void *buf, int len) { return(read_shm (&shm.buf1, buf, len)); }
36 int write_1(void *buf, int len) { return(write_shm(&shm.buf1, buf, len)); }
37
38 /* Port Mapping
39  * ===================================================================== */
40 #define NUM_PORTS 2
41 port_t ports[NUM_PORTS] = {
42         { "0", size_0, level_0, read_0, NULL    },
43         { "1", size_1, level_1, NULL,   write_1 },
44 };
45
46 port_t *get_port(void *port)
47 {
48         for(int i = 0; i < NUM_PORTS; i++) {
49                 if(!strncmp(ports[i].name, port, PORTNAME_MAXLEN)) {
50                         /* found the port */
51                         return(&ports[i]);
52                 }
53         }
54         return(NULL);
55 }
56
57 /* eCore entry point
58  * ===================================================================== */
59 int main(void)
60 {
61         int index = core_id2lin(e_get_coreid());
62         int state = 0;
63
64         Square_process.init((struct _DOLProcess_struct*)&Square_process);
65         while(Square_process.wptr->active) {
66                 shm.states[index] = ++state;
67                 Square_process.fire((struct _DOLProcess_struct*)&Square_process);
68         }
69
70         shm.states[index] = -1;
71         while(1);
72 }
73