OpenCores
URL https://opencores.org/ocsvn/pcie_ds_dma/pcie_ds_dma/trunk

Subversion Repositories pcie_ds_dma

[/] [pcie_ds_dma/] [trunk/] [soft/] [linux/] [application/] [board_exam/] [main.cpp] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dsmv
 
2 6 v.karak
#ifndef __BOARD_H__
3
#include "board.h"
4 2 dsmv
#endif
5
 
6
#include <cassert>
7
#include <cstdlib>
8
#include <cstring>
9
#include <iostream>
10
#include <iomanip>
11
#include <climits>
12
#include <cstdio>
13 6 v.karak
#include <dlfcn.h>
14 2 dsmv
 
15
//-----------------------------------------------------------------------------
16
 
17
using namespace std;
18
 
19
//-----------------------------------------------------------------------------
20 6 v.karak
#define NUM_BLOCK   8
21
#define BLOCK_SIZE  0x10000
22 2 dsmv
//-----------------------------------------------------------------------------
23
 
24
int main(int argc, char *argv[])
25
{
26 6 v.karak
    if(argc != 3) {
27
        std::cerr << "usage: " << argv[0] << " <libname.so> </dev/devname>" << endl;
28 2 dsmv
        return -1;
29
    }
30
 
31 6 v.karak
    char *libname = argv[1];
32
    char *devname = argv[2];
33 2 dsmv
    int dmaChan = 0;
34 6 v.karak
    void* pBuffers[NUM_BLOCK] = {NULL,NULL,NULL,NULL};
35
    void *hlib = NULL;
36
    board_factory factory = NULL;
37
    board *brd = NULL;
38
    u32 *buffer = NULL;
39 2 dsmv
 
40 6 v.karak
    std ::cout << "Loading library: " << libname << endl;
41
 
42
    hlib = dlopen(libname, RTLD_LAZY);
43
    if(!hlib) {
44
        fprintf(stderr, "%s\n", dlerror());
45
        return -1;
46
    }
47
 
48
    factory = (board_factory)dlsym(hlib, "create_board");
49
    if(!factory) {
50
        fprintf(stderr, "%s\n", dlerror());
51
        dlclose(hlib);
52
        return -1;
53
    }
54
 
55
    std ::cout << "Start testing device " << devname << endl;
56
 
57
    brd = factory();
58
    if(!brd) {
59
        dlclose(hlib);
60
        return -1;
61
    }
62
 
63
    if(brd->brd_open(devname) < 0) {
64
 
65
        delete brd;
66
 
67
        if(hlib) {
68
            int res = dlclose(hlib);
69
            if(res < 0) {
70
                fprintf(stderr, "%s\n", dlerror());
71
                return -1;
72
            }
73
        }
74
 
75
        return -1;
76
    }
77
 
78 2 dsmv
    brd->brd_init();
79
    brd->brd_pld_info();
80
 
81 6 v.karak
    std::cout << "Reset FPGA..." << std::endl;
82
    brd->brd_reg_poke_ind(0,0,1);
83
    brd->brd_delay(100);
84
    brd->brd_reg_poke_ind(0,0,0);
85
    brd->brd_delay(100);
86
 
87
    std::cout << "Init FPGA..." << std::endl;
88
    for( int trd=0; trd<8; trd++ ) {
89
        brd->brd_reg_poke_ind( trd, 0, 1 );
90
    }
91
    for( int trd=0; trd<8; trd++ ) {
92
        for( int ii=1; ii<32; ii++ ) {
93
            brd->brd_reg_poke_ind( trd, ii, 0 );
94
        }
95
    }
96
    for( int trd=0; trd<8; trd++ ) {
97
        brd->brd_reg_poke_ind( trd, 0, 0 );
98
    }
99
 
100 2 dsmv
    std ::cout << "Press enter to allocate DMA memory..." << endl;
101
    getchar();
102
 
103 6 v.karak
    int DmaChan = 1;
104
 
105 2 dsmv
    // Check BRDSHELL DMA interface
106
    BRDctrl_StreamCBufAlloc sSCA = {
107 6 v.karak
        1,      //dir
108 2 dsmv
        1,
109
        NUM_BLOCK,
110
        BLOCK_SIZE,
111 6 v.karak
        pBuffers,
112 2 dsmv
        NULL,
113
    };
114
 
115
    brd->dma_alloc(dmaChan, &sSCA);
116
 
117 6 v.karak
    brd->dma_set_local_addr(DmaChan, 0x1000);
118
    brd->dma_stop(DmaChan);
119
    brd->dma_reset_fifo(DmaChan);
120
    brd->dma_reset_fifo(DmaChan);
121
 
122 2 dsmv
    std ::cout << "Press enter to start DMA channel..." << endl;
123
    getchar();
124
 
125 6 v.karak
    // fill data buffers
126
    for(int j=0; j<NUM_BLOCK; j++) {
127
        buffer = (u32*)pBuffers[j];
128
        for(unsigned i=0; i<32; i++) {
129
            buffer[i] = 0xAA556677;
130
        }
131
    }
132
 
133 2 dsmv
    brd->dma_start(dmaChan, 0);
134
 
135
    std ::cout << "Press enter to stop DMA channel..." << endl;
136
    getchar();
137
 
138 6 v.karak
 
139 2 dsmv
    brd->dma_stop(dmaChan);
140
 
141 6 v.karak
    // show data buffers
142
    for(int j=0; j<NUM_BLOCK; j++) {
143 2 dsmv
 
144 6 v.karak
        std ::cout << "DMA data buffer " << j << ":" << endl;
145
        buffer = (u32*)pBuffers[j];
146
        for(unsigned i=0; i<32; i++) {
147
            std::cout << hex << buffer[i] << " ";
148
        }
149
        std ::cout << endl;
150 2 dsmv
    }
151
    std::cout << dec << endl;
152
 
153
    std ::cout << "Press enter to free DMA memory..." << endl;
154
    getchar();
155
 
156
    brd->dma_free_memory(dmaChan);
157
 
158
    brd->brd_close();
159
 
160
    delete brd;
161
 
162 6 v.karak
    if(hlib) {
163
        int res = dlclose(hlib);
164
        if(res < 0) {
165
            fprintf(stderr, "%s\n", dlerror());
166
            return -1;
167
        }
168
    }
169
 
170 2 dsmv
    return 0;
171
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.