source: soft/giet_vm/fifo/main.c @ 158

Last change on this file since 158 was 158, checked in by alain, 12 years ago

Introducing the giet_vm and some example applications

File size: 2.0 KB
Line 
1#include <stdio.h>
2#include <mwmr.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    mwmr_channel_t*     mwmr;
14
15    tty_printf( "*** Starting task producer on processor %d at cycle %d ***\n\n", 
16                procid(), proctime() );
17
18    // get mwmr channel base address
19    unsigned int ret = mwmr_base( "fifo" , "seg_mwmr" , &mwmr );
20
21    if ( ret )
22    {
23        tty_printf("\n[ERROR] in fifo application / producer task :\n");
24        tty_printf("          undefined mwmr channel\n");
25        exit();
26    }
27
28    // main loop   
29    for( n = 0 ; n < NMAX ; n++ ) 
30    { 
31        tempo = rand()>>6;
32        val   = n;
33        mwmr_write( mwmr, &val, 1 );
34        for(x = 0 ; x < tempo ; x++) asm volatile ("nop");
35        tty_printf("transmitted value : %d      temporisation = %d\n", val, tempo);
36    }
37
38    tty_printf("\n*** Completing producer at cycle %d ***\n", proctime());
39    exit();
40
41} // end producer()
42
43/////////////////////////////////////////////
44__attribute__ ((constructor)) void consumer()
45{
46    unsigned int        n;
47    unsigned int        x;
48    unsigned int        tempo;
49    unsigned int        val;
50    mwmr_channel_t*     mwmr;
51
52    tty_printf( "*** Starting task consumer on processor %d at cycle %d ***\n\n", 
53                procid(), proctime() );
54
55    // get mwmr channel base address
56    unsigned int ret = mwmr_base( "fifo" , "seg_mwmr" , &mwmr );
57
58    if ( ret )
59    {
60        tty_printf("\n[ERROR] in fifo application / consumer task :\n");
61        tty_printf("          undefined mwmr channel\n");
62        exit();
63    }
64
65    // main loop
66    for( n = 0 ; n < NMAX ; n++ ) 
67    { 
68        tempo = rand()>>6;
69        mwmr_read( mwmr, &val, 1 );
70        for(x = 0 ; x < tempo ; x++) asm volatile ("nop");
71        tty_printf("received value : %d      temporisation = %d\n", val, tempo);
72    }
73
74    tty_printf("\n*** Completing consumer at cycle %d ***\n", proctime());
75    exit();
76
77} // end consumer()
78
Note: See TracBrowser for help on using the repository browser.