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

Last change on this file since 595 was 589, checked in by alain, 9 years ago

Modify all applications to support two new rules:
1) introduce a local Makefile for each application.
2) change "application.elf" name to "application/appli.elf" name in the application.py" file.
Introduce the shell application.

File size: 3.9 KB
Line 
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
13#include "stdio.h"
14#include "mapping_info.h"       // for coprocessors types an modes
15
16#define  VECTOR_SIZE 128   
17
18#define  DMA_MODE    MODE_DMA_IRQ
19
20#define VERBOSE      1
21
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
36    giet_shr_printf("\n*** Starting coproc application on processor"
37                    "[%d,%d,%d] at cycle %d\n", 
38                    x, y, lpid, giet_proctime() );
39
40    // initializes opa & opb buffers
41    unsigned int word;
42    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
43    {
44        opa[word] = giet_rand() + 1;
45        opb[word] = giet_rand() + 1;
46    }
47
48    unsigned int coproc_info;
49
50    /////////////////////// request a GCD coprocessor
51    giet_coproc_alloc( MWR_SUBTYPE_GCD, &coproc_info );
52
53    // check coprocessor ports
54    unsigned int nb_to_coproc   = (coproc_info    ) & 0xFF;
55    unsigned int nb_from_coproc = (coproc_info>> 8) & 0xFF;
56    unsigned int nb_config      = (coproc_info>>16) & 0xFF;
57    unsigned int nb_status      = (coproc_info>>24) & 0xFF;
58    giet_assert( ((nb_to_coproc   == 2) &&
59                  (nb_from_coproc == 1) &&
60                  (nb_config      == 1) &&
61                  (nb_status      == 0) ) ,
62                  "wrong GCD coprocessor interface" );
63
64if ( VERBOSE )
65giet_shr_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
66
67    //////////////////////// initializes channel for OPA
68    giet_coproc_channel_t opa_desc;
69    opa_desc.channel_mode = DMA_MODE;
70    opa_desc.buffer_size  = VECTOR_SIZE<<2;
71    opa_desc.buffer_vaddr = (unsigned int)opa;
72    giet_coproc_channel_init( 0 , &opa_desc );
73   
74    //////////////////////// initializes channel for OPB
75    giet_coproc_channel_t opb_desc;
76    opb_desc.channel_mode = DMA_MODE;
77    opb_desc.buffer_size  = VECTOR_SIZE<<2;
78    opb_desc.buffer_vaddr = (unsigned int)opb;
79    giet_coproc_channel_init( 1 , &opb_desc );
80   
81    //////////////////////// initializes channel for RES
82    giet_coproc_channel_t res_desc;
83    res_desc.channel_mode = DMA_MODE;
84    res_desc.buffer_size  = VECTOR_SIZE<<2;
85    res_desc.buffer_vaddr = (unsigned int)res;
86    giet_coproc_channel_init( 2 , &res_desc );
87   
88if ( VERBOSE )
89giet_shr_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
90
91    /////////////////////// starts communication channels
92    giet_coproc_run( 0 );
93
94if ( VERBOSE )
95giet_shr_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
96
97    /////////////////////// wait coprocessor completion
98    if ( DMA_MODE == MODE_DMA_NO_IRQ )
99    {
100        giet_coproc_completed( );
101    }
102
103if ( VERBOSE )
104giet_shr_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
105
106    // display result
107    for ( word = 0 ; word < VECTOR_SIZE ; word++ )
108    {
109        giet_shr_printf("pgcd( %d , %d ) = %d\n",
110        opa[word] , opb[word] , res[word] );
111    }
112
113    ////////////////////// release GCD coprocessor
114    giet_coproc_release( 0 );
115
116    giet_exit("completed");
117
118} // end main
119
Note: See TracBrowser for help on using the repository browser.