1 | #include "stdio.h" |
---|
2 | #include "srl.h" |
---|
3 | |
---|
4 | #define NMAX 1000 |
---|
5 | |
---|
6 | ////////////////////////////////////////////// |
---|
7 | __attribute__ ((constructor)) void producer() |
---|
8 | { |
---|
9 | unsigned int n; |
---|
10 | unsigned int x; |
---|
11 | unsigned int tempo; |
---|
12 | unsigned int val; |
---|
13 | // get mwmr channel base address |
---|
14 | srl_mwmr_t mwmr ; |
---|
15 | vobj_get_vbase( "fifo" , "mwmr", MWMR, (unsigned int*)&mwmr ); |
---|
16 | |
---|
17 | srl_log_printf( TRACE, "*** Starting task producer on processor %d at cycle %d ***\n\n", procid(), proctime() ); |
---|
18 | |
---|
19 | |
---|
20 | if ( !mwmr ) |
---|
21 | { |
---|
22 | srl_log( NONE, "\n[ERROR] in fifo application / producer task :\n"); |
---|
23 | srl_log( NONE, " undefined mwmr channel\n"); |
---|
24 | exit(); |
---|
25 | } |
---|
26 | |
---|
27 | // main loop |
---|
28 | for( n = 0 ; n < NMAX ; n++ ) |
---|
29 | { |
---|
30 | tempo = rand()>>6; |
---|
31 | val = n; |
---|
32 | srl_mwmr_write( mwmr, &val, 1 ); |
---|
33 | for(x = 0 ; x < tempo ; x++) asm volatile ("nop"); |
---|
34 | srl_log_printf( TRACE, "transmitted value : %d temporisation = %d\n", val, tempo); |
---|
35 | } |
---|
36 | |
---|
37 | srl_log_printf( TRACE, "\n*** Completing producer 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 x; |
---|
47 | unsigned int tempo; |
---|
48 | unsigned int val; |
---|
49 | // get mwmr channel base address |
---|
50 | srl_mwmr_t mwmr ; |
---|
51 | vobj_get_vbase( "fifo" , "mwmr", MWMR, (unsigned int*)&mwmr ); |
---|
52 | |
---|
53 | srl_log_printf( TRACE, "*** Starting task consumer on processor %d at cycle %d ***\n\n", |
---|
54 | procid(), proctime() ); |
---|
55 | |
---|
56 | |
---|
57 | if ( !mwmr ) |
---|
58 | { |
---|
59 | srl_log( NONE, "\n[ERROR] in fifo application / consumer task :\n"); |
---|
60 | srl_log( NONE, " undefined mwmr channel\n"); |
---|
61 | exit(); |
---|
62 | } |
---|
63 | |
---|
64 | // main loop |
---|
65 | for( n = 0 ; n < NMAX ; n++ ) |
---|
66 | { |
---|
67 | tempo = rand()>>6; |
---|
68 | srl_mwmr_read( mwmr, &val, 1 ); |
---|
69 | for(x = 0 ; x < tempo ; x++) asm volatile ("nop"); |
---|
70 | srl_log_printf( TRACE, "received value : %d temporisation = %d\n", val, tempo); |
---|
71 | } |
---|
72 | |
---|
73 | srl_log_printf( TRACE, "\n*** Completing consumer at cycle %d ***\n", proctime()); |
---|
74 | exit(); |
---|
75 | |
---|
76 | } // end consumer() |
---|
77 | |
---|