1 | #include "stdio.h" |
---|
2 | #include "mwmr_channel.h" |
---|
3 | |
---|
4 | #define NMAX 200 |
---|
5 | |
---|
6 | ///////////////////////////////////////////// |
---|
7 | __attribute__ ((constructor)) void producer() |
---|
8 | { |
---|
9 | |
---|
10 | unsigned int n; |
---|
11 | unsigned int buf; |
---|
12 | mwmr_channel_t* mwmr; |
---|
13 | |
---|
14 | giet_tty_printf( "*** Starting task producer on processor %d", giet_procid() ); |
---|
15 | giet_tty_printf( " at cycle %d ***\n\n", giet_proctime() ); |
---|
16 | |
---|
17 | if( giet_vobj_get_vbase( "router" , |
---|
18 | "mwmr_in", |
---|
19 | VOBJ_TYPE_MWMR, |
---|
20 | (void*)&mwmr ) ) |
---|
21 | { |
---|
22 | giet_tty_printf( "\n[ERROR] in producer task :\n"); |
---|
23 | giet_tty_printf( " undefined <mwmr_in> channel: %d\n", mwmr); |
---|
24 | giet_tty_printf( "*** &mwmr_in = %x\n\n", (unsigned int)mwmr ); |
---|
25 | giet_exit(); |
---|
26 | } |
---|
27 | |
---|
28 | // main loop : token value = departure index |
---|
29 | for(n = 0 ; n < NMAX ; n++) |
---|
30 | { |
---|
31 | buf = n; |
---|
32 | mwmr_write( mwmr, &buf , 1 ); |
---|
33 | giet_tty_printf( "transmitted value : %d\n", buf); |
---|
34 | } |
---|
35 | |
---|
36 | giet_tty_printf( "\n*** Completing producer task at cycle %d ***\n", giet_proctime()); |
---|
37 | giet_exit(); |
---|
38 | |
---|
39 | } // end producer() |
---|
40 | |
---|
41 | ///////////////////////////////////////////// |
---|
42 | __attribute__ ((constructor)) void consumer() |
---|
43 | { |
---|
44 | unsigned int n; |
---|
45 | unsigned int buf[5]; |
---|
46 | mwmr_channel_t* mwmr; |
---|
47 | |
---|
48 | giet_tty_printf( "*** Starting task consumer on processor %d", giet_procid() ); |
---|
49 | giet_tty_printf( " at cycle %d ***\n\n", giet_proctime() ); |
---|
50 | |
---|
51 | if ( giet_vobj_get_vbase( "router" , |
---|
52 | "mwmr_out", |
---|
53 | VOBJ_TYPE_MWMR, |
---|
54 | (void*)&mwmr ) ) |
---|
55 | { |
---|
56 | giet_tty_printf( "\n[ERROR] in consumer task :\n"); |
---|
57 | giet_tty_printf( " undefined <mwmr_out> channel\n"); |
---|
58 | giet_exit(); |
---|
59 | } |
---|
60 | |
---|
61 | // main loop : display token arrival index and value |
---|
62 | for(n = 0 ; n < NMAX ; n = n+5 ) |
---|
63 | { |
---|
64 | mwmr_read( mwmr, buf , 5 ); |
---|
65 | giet_tty_printf( "received token %d / value = %d\n", n , buf[0]); |
---|
66 | giet_tty_printf( "received token %d / value = %d\n", n+1, buf[1]); |
---|
67 | giet_tty_printf( "received token %d / value = %d\n", n+2, buf[2]); |
---|
68 | giet_tty_printf( "received token %d / value = %d\n", n+3, buf[3]); |
---|
69 | giet_tty_printf( "received token %d / value = %d\n", n+4, buf[4]); |
---|
70 | } |
---|
71 | |
---|
72 | giet_tty_printf( "\n*** Completing consumer task at cycle %d ***\n", giet_proctime()); |
---|
73 | giet_exit(); |
---|
74 | |
---|
75 | } // end consumer() |
---|
76 | |
---|
77 | /////////////////////////////////////////// |
---|
78 | __attribute__ ((constructor)) void router() |
---|
79 | { |
---|
80 | unsigned int buf[2]; |
---|
81 | unsigned int x; |
---|
82 | unsigned int tempo; |
---|
83 | mwmr_channel_t* mwmr_in ; |
---|
84 | mwmr_channel_t* mwmr_out ; |
---|
85 | |
---|
86 | |
---|
87 | giet_tty_printf( "*** Starting task router on processor %d", giet_procid() ); |
---|
88 | giet_tty_printf( " at cycle %d ***\n\n", giet_proctime() ); |
---|
89 | |
---|
90 | if ( giet_vobj_get_vbase( "router" , |
---|
91 | "mwmr_out", |
---|
92 | VOBJ_TYPE_MWMR, |
---|
93 | (void*)&mwmr_out ) ) |
---|
94 | { |
---|
95 | giet_tty_printf( "\n[ERROR] in router task :\n"); |
---|
96 | giet_tty_printf( " undefined <mwmr_in> channel\n"); |
---|
97 | giet_exit(); |
---|
98 | } |
---|
99 | |
---|
100 | if ( giet_vobj_get_vbase( "router" , |
---|
101 | "mwmr_in", |
---|
102 | VOBJ_TYPE_MWMR, |
---|
103 | (void*)&mwmr_in ) ) |
---|
104 | { |
---|
105 | giet_tty_printf( "\n[ERROR] in router task :\n"); |
---|
106 | giet_tty_printf( " undefined <mwmr_out> channel\n"); |
---|
107 | giet_exit(); |
---|
108 | } |
---|
109 | |
---|
110 | // main loop |
---|
111 | while(1) |
---|
112 | { |
---|
113 | mwmr_read( mwmr_in , buf , 2 ); |
---|
114 | tempo = giet_rand() >> 6; |
---|
115 | for ( x = 0 ; x < tempo ; x++ ) asm volatile (""); |
---|
116 | giet_tty_printf( "token value : %d / temporisation = %d\n", buf[0], tempo); |
---|
117 | giet_tty_printf( "token value : %d / temporisation = %d\n", buf[1], tempo); |
---|
118 | mwmr_write( mwmr_out, buf , 2 ); |
---|
119 | } |
---|
120 | } |
---|