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