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