1 | #include "stdio.h" |
---|
2 | #include "mwmr_channel.h" |
---|
3 | #include "mapping_info.h" |
---|
4 | #include "hard_config.h" |
---|
5 | |
---|
6 | #define NMAX 50 |
---|
7 | |
---|
8 | ///////////////////////////////////////////// |
---|
9 | __attribute__ ((constructor)) void producer() |
---|
10 | { |
---|
11 | |
---|
12 | unsigned int n; |
---|
13 | unsigned int buf; |
---|
14 | mwmr_channel_t* mwmr; |
---|
15 | |
---|
16 | unsigned int procid = giet_procid(); |
---|
17 | unsigned int cluster_xy = procid/NB_PROCS_MAX; |
---|
18 | unsigned int lpid = procid%NB_PROCS_MAX; |
---|
19 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
20 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
21 | |
---|
22 | giet_tty_printf( "*** Starting task producer on processor[%d,%d,%d] at cycle %d\n\n", |
---|
23 | x, y, lpid, giet_proctime() ); |
---|
24 | |
---|
25 | giet_vobj_get_vbase( "router" , |
---|
26 | "mwmr_in", |
---|
27 | (void*)&mwmr ); |
---|
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_exit( "Producer task completed"); |
---|
38 | |
---|
39 | } // end producer() |
---|
40 | |
---|
41 | ///////////////////////////////////////////// |
---|
42 | __attribute__ ((constructor)) void consumer() |
---|
43 | { |
---|
44 | unsigned int n; |
---|
45 | unsigned int buf; |
---|
46 | mwmr_channel_t* mwmr; |
---|
47 | |
---|
48 | unsigned int procid = giet_procid(); |
---|
49 | unsigned int cluster_xy = procid/NB_PROCS_MAX; |
---|
50 | unsigned int lpid = procid%NB_PROCS_MAX; |
---|
51 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
52 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
53 | |
---|
54 | giet_tty_printf( "*** Starting task consumer on processor[%d,%d,%d] at cycle %d\n\n", |
---|
55 | x, y, lpid, giet_proctime() ); |
---|
56 | |
---|
57 | giet_vobj_get_vbase( "router" , |
---|
58 | "mwmr_out", |
---|
59 | (void*)&mwmr ); |
---|
60 | |
---|
61 | // main loop : display token arrival index and value |
---|
62 | for(n = 0 ; n < NMAX ; n++ ) |
---|
63 | { |
---|
64 | mwmr_read( mwmr, &buf , 1 ); |
---|
65 | giet_tty_printf( "received token %d / value = %d\n", n , buf); |
---|
66 | } |
---|
67 | |
---|
68 | giet_exit( "Consumer task completed"); |
---|
69 | |
---|
70 | } // end consumer() |
---|
71 | |
---|
72 | /////////////////////////////////////////// |
---|
73 | __attribute__ ((constructor)) void router() |
---|
74 | { |
---|
75 | unsigned int buf; |
---|
76 | unsigned int n; |
---|
77 | unsigned int tempo; |
---|
78 | mwmr_channel_t* mwmr_in ; |
---|
79 | mwmr_channel_t* mwmr_out ; |
---|
80 | |
---|
81 | unsigned int procid = giet_procid(); |
---|
82 | unsigned int cluster_xy = procid/NB_PROCS_MAX; |
---|
83 | unsigned int lpid = procid%NB_PROCS_MAX; |
---|
84 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
85 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
86 | |
---|
87 | giet_tty_printf( "*** Starting task router on processor[%d,%d,%d] at cycle %d\n\n", |
---|
88 | x, y, lpid, giet_proctime() ); |
---|
89 | |
---|
90 | giet_vobj_get_vbase( "router" , |
---|
91 | "mwmr_out", |
---|
92 | (void*)&mwmr_out ); |
---|
93 | |
---|
94 | giet_vobj_get_vbase( "router" , |
---|
95 | "mwmr_in", |
---|
96 | (void*)&mwmr_in ); |
---|
97 | // main loop |
---|
98 | while(1) |
---|
99 | { |
---|
100 | mwmr_read( mwmr_in , &buf , 1 ); |
---|
101 | tempo = giet_rand() >> 6; |
---|
102 | for ( n = 0 ; n < tempo ; n++ ) asm volatile (""); |
---|
103 | giet_tty_printf( "token value : %d / temporisation = %d\n", buf, tempo); |
---|
104 | mwmr_write( mwmr_out, &buf , 1 ); |
---|
105 | } |
---|
106 | } |
---|