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] - Diff between revs 2 and 6

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 6
Line 1... Line 1...
 
 
#ifndef __PEX_H__
#ifndef __BOARD_H__
    #include "pex_board.h"
#include "board.h"
#endif
#endif
 
 
#include <cassert>
#include <cassert>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <cstring>
#include <iostream>
#include <iostream>
#include <iomanip>
#include <iomanip>
#include <climits>
#include <climits>
#include <cstdio>
#include <cstdio>
 
#include <dlfcn.h>
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
 
 
using namespace std;
using namespace std;
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#define NUM_BLOCK   4
#define NUM_BLOCK   8
#define BLOCK_SIZE  0x1000
#define BLOCK_SIZE  0x10000
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
 
 
int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
{
    if(argc == 1) {
    if(argc != 3) {
        std::cerr << "usage: %s <device name>" << argv[0] << endl;
        std::cerr << "usage: " << argv[0] << " <libname.so> </dev/devname>" << endl;
        return -1;
        return -1;
    }
    }
 
 
    std ::cout << "Start testing device " << argv[1] << endl;
    char *libname = argv[1];
 
    char *devname = argv[2];
    int dmaChan = 0;
    int dmaChan = 0;
    void* pBuffers[NUM_BLOCK] = {NULL};
    void* pBuffers[NUM_BLOCK] = {NULL,NULL,NULL,NULL};
 
    void *hlib = NULL;
 
    board_factory factory = NULL;
 
    board *brd = NULL;
 
    u32 *buffer = NULL;
 
 
 
    std ::cout << "Loading library: " << libname << endl;
 
 
 
    hlib = dlopen(libname, RTLD_LAZY);
 
    if(!hlib) {
 
        fprintf(stderr, "%s\n", dlerror());
 
        return -1;
 
    }
 
 
 
    factory = (board_factory)dlsym(hlib, "create_board");
 
    if(!factory) {
 
        fprintf(stderr, "%s\n", dlerror());
 
        dlclose(hlib);
 
        return -1;
 
    }
 
 
 
    std ::cout << "Start testing device " << devname << endl;
 
 
 
    brd = factory();
 
    if(!brd) {
 
        dlclose(hlib);
 
        return -1;
 
    }
 
 
 
    if(brd->brd_open(devname) < 0) {
 
 
 
        delete brd;
 
 
 
        if(hlib) {
 
            int res = dlclose(hlib);
 
            if(res < 0) {
 
                fprintf(stderr, "%s\n", dlerror());
 
                return -1;
 
            }
 
        }
 
 
 
        return -1;
 
    }
 
 
    board *brd = new pex_board();
 
    brd->brd_open(argv[1]);
 
    brd->brd_init();
    brd->brd_init();
    brd->brd_pld_info();
    brd->brd_pld_info();
 
 
 
    std::cout << "Reset FPGA..." << std::endl;
 
    brd->brd_reg_poke_ind(0,0,1);
 
    brd->brd_delay(100);
 
    brd->brd_reg_poke_ind(0,0,0);
 
    brd->brd_delay(100);
 
 
 
    std::cout << "Init FPGA..." << std::endl;
 
    for( int trd=0; trd<8; trd++ ) {
 
        brd->brd_reg_poke_ind( trd, 0, 1 );
 
    }
 
    for( int trd=0; trd<8; trd++ ) {
 
        for( int ii=1; ii<32; ii++ ) {
 
            brd->brd_reg_poke_ind( trd, ii, 0 );
 
        }
 
    }
 
    for( int trd=0; trd<8; trd++ ) {
 
        brd->brd_reg_poke_ind( trd, 0, 0 );
 
    }
 
 
    std ::cout << "Press enter to allocate DMA memory..." << endl;
    std ::cout << "Press enter to allocate DMA memory..." << endl;
    getchar();
    getchar();
 
 
 
    int DmaChan = 1;
 
 
    // Check BRDSHELL DMA interface
    // Check BRDSHELL DMA interface
    BRDctrl_StreamCBufAlloc sSCA = {
    BRDctrl_StreamCBufAlloc sSCA = {
        1,
        1,      //dir
        1,
        1,
        NUM_BLOCK,
        NUM_BLOCK,
        BLOCK_SIZE,
        BLOCK_SIZE,
        &pBuffers[0],
        pBuffers,
        NULL,
        NULL,
    };
    };
 
 
    brd->dma_alloc(dmaChan, &sSCA);
    brd->dma_alloc(dmaChan, &sSCA);
 
 
 
    brd->dma_set_local_addr(DmaChan, 0x1000);
 
    brd->dma_stop(DmaChan);
 
    brd->dma_reset_fifo(DmaChan);
 
    brd->dma_reset_fifo(DmaChan);
 
 
    std ::cout << "Press enter to start DMA channel..." << endl;
    std ::cout << "Press enter to start DMA channel..." << endl;
    getchar();
    getchar();
 
 
 
    // fill data buffers
 
    for(int j=0; j<NUM_BLOCK; j++) {
 
        buffer = (u32*)pBuffers[j];
 
        for(unsigned i=0; i<32; i++) {
 
            buffer[i] = 0xAA556677;
 
        }
 
    }
 
 
    brd->dma_start(dmaChan, 0);
    brd->dma_start(dmaChan, 0);
 
 
    std ::cout << "Press enter to stop DMA channel..." << endl;
    std ::cout << "Press enter to stop DMA channel..." << endl;
    getchar();
    getchar();
 
 
 
 
    brd->dma_stop(dmaChan);
    brd->dma_stop(dmaChan);
 
 
    std ::cout << "Press enter to view DMA data (buffer 0)..." << endl;
    // show data buffers
    getchar();
    for(int j=0; j<NUM_BLOCK; j++) {
 
 
    u32 *buffer = (u32*)pBuffers[0];
        std ::cout << "DMA data buffer " << j << ":" << endl;
    for(unsigned i=0; i<BLOCK_SIZE/4; i+=128) {
        buffer = (u32*)pBuffers[j];
 
        for(unsigned i=0; i<32; i++) {
        std::cout << hex << buffer[i] << " ";
        std::cout << hex << buffer[i] << " ";
    }
    }
 
        std ::cout << endl;
 
    }
    std::cout << dec << endl;
    std::cout << dec << endl;
 
 
    std ::cout << "Press enter to free DMA memory..." << endl;
    std ::cout << "Press enter to free DMA memory..." << endl;
    getchar();
    getchar();
 
 
    brd->dma_free_memory(dmaChan);
    brd->dma_free_memory(dmaChan);
/*
 
    for(int i=0; i<16; i++)
 
        std ::cout << "BAR0[" << i << "] = 0x" << hex << brd->brd_bar0_read(i) << dec << endl;
 
 
 
    fprintf(stderr, "Press enter to read BAR1...\n");
 
    getchar();
 
 
 
    for(int i=0; i<16; i++)
 
        std ::cout << "BAR1[" << i << "] = 0x" << hex << brd->brd_bar1_read(i) << dec << endl;
 
*/
 
    brd->brd_close();
    brd->brd_close();
 
 
    delete brd;
    delete brd;
 
 
 
    if(hlib) {
 
        int res = dlclose(hlib);
 
        if(res < 0) {
 
            fprintf(stderr, "%s\n", dlerror());
 
            return -1;
 
        }
 
    }
 
 
    return 0;
    return 0;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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