source: soft/giet_vm/applications/router/main.c @ 432

Last change on this file since 432 was 432, checked in by alain, 10 years ago

1) Introduce the "applications" directory.
2) Introduce the fixed format (X_WIDTH / Y_WIDTH / P_WIDTH) for processor index in all applications.

File size: 2.8 KB
Line 
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    // get processor identifiers
23    unsigned int    x;
24    unsigned int    y;
25    unsigned int    lpid;
26    giet_proc_xyp( &x, &y, &lpid );
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    // get processor identifiers
55    unsigned int    x;
56    unsigned int    y;
57    unsigned int    lpid;
58    giet_proc_xyp( &x, &y, &lpid );
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    // get processor identifiers
88    unsigned int    x;
89    unsigned int    y;
90    unsigned int    lpid;
91    giet_proc_xyp( &x, &y, &lpid );
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}
Note: See TracBrowser for help on using the repository browser.