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