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