source: soft/giet_vm/applications/coproc/main.c @ 706

Last change on this file since 706 was 669, checked in by alain, 9 years ago

Introduce support for the "shared" argument in the giet_tty_alloc() system call,
and replace the giet_shr_printf() system call by giet_tty_printf().

File size: 4.0 KB
RevLine 
[555]1///////////////////////////////////////////////////////////////////////////////////////
2//  file   : main.c  (for coproc application)
3//  date   : avril 2015
4//  author : Alain Greiner
5///////////////////////////////////////////////////////////////////////////////////////
6//  This file describes the single thread "coproc" application.
7//  It uses the embedded GCD (Greater Common Divider) coprocessor to make
8//  the GCD computation between two vectors of 32 bits integers.
9//  The vectors size is defined by the VECTOR_SIZE parameter.
10///////////////////////////////////////////////////////////////////////////////////////
11
12
[533]13#include "stdio.h"
[589]14#include "mapping_info.h"       // for coprocessors types an modes
[533]15
[555]16#define  VECTOR_SIZE 128   
[533]17
[555]18#define  DMA_MODE    MODE_DMA_IRQ
[533]19
[555]20#define VERBOSE      1
21
[533]22// Memory buffers for coprocessor
23unsigned int opa[VECTOR_SIZE] __attribute__((aligned(64)));
24unsigned int opb[VECTOR_SIZE] __attribute__((aligned(64)));
25unsigned int res[VECTOR_SIZE] __attribute__((aligned(64)));
26
27/////////////////////////////////////////
28__attribute__ ((constructor)) void main()
29{
30    // get processor identifiers
31    unsigned int    x;
32    unsigned int    y;
33    unsigned int    lpid;
34    giet_proc_xyp( &x, &y, &lpid );
35
[669]36    // get a private TTY terminal
37    giet_tty_alloc( 0 );
38
39    giet_tty_printf("\n*** Starting coproc application on processor"
[533]40                    "[%d,%d,%d] at cycle %d\n", 
41                    x, y, lpid, giet_proctime() );
42
43    // initializes opa & opb buffers
44    unsigned int word;
45    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
46    {
47        opa[word] = giet_rand() + 1;
48        opb[word] = giet_rand() + 1;
49    }
50
51    unsigned int coproc_info;
52
[555]53    /////////////////////// request a GCD coprocessor
54    giet_coproc_alloc( MWR_SUBTYPE_GCD, &coproc_info );
[533]55
56    // check coprocessor ports
57    unsigned int nb_to_coproc   = (coproc_info    ) & 0xFF;
58    unsigned int nb_from_coproc = (coproc_info>> 8) & 0xFF;
59    unsigned int nb_config      = (coproc_info>>16) & 0xFF;
60    unsigned int nb_status      = (coproc_info>>24) & 0xFF;
61    giet_assert( ((nb_to_coproc   == 2) &&
62                  (nb_from_coproc == 1) &&
63                  (nb_config      == 1) &&
64                  (nb_status      == 0) ) ,
65                  "wrong GCD coprocessor interface" );
66
[555]67if ( VERBOSE )
[669]68giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
[533]69
[555]70    //////////////////////// initializes channel for OPA
71    giet_coproc_channel_t opa_desc;
72    opa_desc.channel_mode = DMA_MODE;
73    opa_desc.buffer_size  = VECTOR_SIZE<<2;
74    opa_desc.buffer_vaddr = (unsigned int)opa;
75    giet_coproc_channel_init( 0 , &opa_desc );
[533]76   
[555]77    //////////////////////// initializes channel for OPB
78    giet_coproc_channel_t opb_desc;
79    opb_desc.channel_mode = DMA_MODE;
80    opb_desc.buffer_size  = VECTOR_SIZE<<2;
81    opb_desc.buffer_vaddr = (unsigned int)opb;
82    giet_coproc_channel_init( 1 , &opb_desc );
[533]83   
[555]84    //////////////////////// initializes channel for RES
85    giet_coproc_channel_t res_desc;
86    res_desc.channel_mode = DMA_MODE;
87    res_desc.buffer_size  = VECTOR_SIZE<<2;
88    res_desc.buffer_vaddr = (unsigned int)res;
89    giet_coproc_channel_init( 2 , &res_desc );
[533]90   
[555]91if ( VERBOSE )
[669]92giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
[533]93
[555]94    /////////////////////// starts communication channels
95    giet_coproc_run( 0 );
[533]96
[555]97if ( VERBOSE )
[669]98giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
[533]99
[555]100    /////////////////////// wait coprocessor completion
101    if ( DMA_MODE == MODE_DMA_NO_IRQ )
102    {
103        giet_coproc_completed( );
104    }
[533]105
[555]106if ( VERBOSE )
[669]107giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
[533]108
109    // display result
110    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
111    {
[669]112        giet_tty_printf("pgcd( %d , %d ) = %d\n",
[533]113        opa[word] , opb[word] , res[word] );
114    }
115
[555]116    ////////////////////// release GCD coprocessor
117    giet_coproc_release( 0 );
118
[533]119    giet_exit("completed");
120
121} // end main
122
Note: See TracBrowser for help on using the repository browser.