| [191] | 1 | #include "stdio.h" | 
|---|
|  | 2 | #include "mwmr_channel.h" | 
|---|
|  | 3 | #include "mapping_info.h" | 
|---|
| [295] | 4 | #include "hard_config.h" | 
|---|
| [191] | 5 |  | 
|---|
| [295] | 6 | #define NMAX 50 | 
|---|
| [191] | 7 |  | 
|---|
|  | 8 | ///////////////////////////////////////////// | 
|---|
|  | 9 | __attribute__ ((constructor)) void producer() | 
|---|
|  | 10 | { | 
|---|
|  | 11 |  | 
|---|
|  | 12 | unsigned int        n; | 
|---|
|  | 13 | unsigned int        buf; | 
|---|
|  | 14 | mwmr_channel_t*     mwmr; | 
|---|
|  | 15 |  | 
|---|
| [295] | 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); | 
|---|
| [191] | 21 |  | 
|---|
| [295] | 22 | giet_tty_printf( "*** Starting task producer on processor[%d,%d,%d] at cycle %d\n\n", | 
|---|
|  | 23 | x, y, lpid, giet_proctime() ); | 
|---|
| [191] | 24 |  | 
|---|
| [295] | 25 | giet_vobj_get_vbase( "router" , | 
|---|
|  | 26 | "mwmr_in", | 
|---|
|  | 27 | (void*)&mwmr ); | 
|---|
|  | 28 |  | 
|---|
| [264] | 29 | // main loop : display token value = source index | 
|---|
| [191] | 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 |  | 
|---|
| [295] | 37 | giet_exit( "Producer task completed"); | 
|---|
| [191] | 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 |  | 
|---|
| [295] | 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); | 
|---|
| [191] | 53 |  | 
|---|
| [295] | 54 | giet_tty_printf( "*** Starting task consumer on processor[%d,%d,%d] at cycle %d\n\n", | 
|---|
|  | 55 | x, y, lpid, giet_proctime() ); | 
|---|
| [191] | 56 |  | 
|---|
| [295] | 57 | giet_vobj_get_vbase( "router" , | 
|---|
|  | 58 | "mwmr_out", | 
|---|
|  | 59 | (void*)&mwmr ); | 
|---|
|  | 60 |  | 
|---|
| [191] | 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 |  | 
|---|
| [295] | 68 | giet_exit( "Consumer task completed"); | 
|---|
| [191] | 69 |  | 
|---|
|  | 70 | } // end consumer() | 
|---|
|  | 71 |  | 
|---|
|  | 72 | /////////////////////////////////////////// | 
|---|
|  | 73 | __attribute__ ((constructor)) void router() | 
|---|
|  | 74 | { | 
|---|
| [264] | 75 | unsigned int        buf; | 
|---|
| [295] | 76 | unsigned int        n; | 
|---|
| [191] | 77 | unsigned int        tempo; | 
|---|
|  | 78 | mwmr_channel_t*     mwmr_in ; | 
|---|
|  | 79 | mwmr_channel_t* mwmr_out ; | 
|---|
|  | 80 |  | 
|---|
| [295] | 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); | 
|---|
| [191] | 86 |  | 
|---|
| [295] | 87 | giet_tty_printf( "*** Starting task router on processor[%d,%d,%d] at cycle %d\n\n", | 
|---|
|  | 88 | x, y, lpid, giet_proctime() ); | 
|---|
| [191] | 89 |  | 
|---|
| [295] | 90 | giet_vobj_get_vbase( "router" , | 
|---|
|  | 91 | "mwmr_out", | 
|---|
|  | 92 | (void*)&mwmr_out ); | 
|---|
| [191] | 93 |  | 
|---|
| [295] | 94 | giet_vobj_get_vbase( "router" , | 
|---|
|  | 95 | "mwmr_in", | 
|---|
|  | 96 | (void*)&mwmr_in ); | 
|---|
| [191] | 97 | // main loop | 
|---|
|  | 98 | while(1) | 
|---|
|  | 99 | { | 
|---|
| [264] | 100 | mwmr_read( mwmr_in , &buf , 1 ); | 
|---|
| [191] | 101 | tempo = giet_rand() >> 6; | 
|---|
| [295] | 102 | for ( n = 0 ; n < tempo ; n++ ) asm volatile (""); | 
|---|
| [264] | 103 | giet_tty_printf( "token value : %d / temporisation = %d\n", buf, tempo); | 
|---|
|  | 104 | mwmr_write( mwmr_out, &buf , 1 ); | 
|---|
| [191] | 105 | } | 
|---|
|  | 106 | } | 
|---|