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] - Rev 55

Compare with Previous | Blame | View Log

 
#ifndef __BOARD_H__
#include "board.h"
#endif
 
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <dlfcn.h>
 
//-----------------------------------------------------------------------------
 
using namespace std;
 
//-----------------------------------------------------------------------------
#define NUM_BLOCK   8
#define BLOCK_SIZE  0x10000
//-----------------------------------------------------------------------------
 
int main(int argc, char *argv[])
{
    if(argc != 3) {
        std::cerr << "usage: " << argv[0] << " <libname.so> </dev/devname>" << endl;
        return -1;
    }
 
    char *libname = argv[1];
    char *devname = argv[2];
    int dmaChan = 0;
    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;
    }
 
    brd->brd_init();
    brd->brd_pld_info();
 
    std ::cout << "Press enter to allocate DMA memory..." << endl;
    getchar();
 
    // Check BRDSHELL DMA interface
    BRDctrl_StreamCBufAlloc sSCA = {
        1,	//dir
        1,
        NUM_BLOCK,
        BLOCK_SIZE,
        pBuffers,
        NULL,
    };
 
    brd->dma_allocate_memory(dmaChan, &sSCA);
 
    brd->dma_set_local_addr(dmaChan, 0x1000);
    brd->dma_stop(dmaChan);
    brd->dma_reset_fifo(dmaChan);
 
    brd->brd_reg_poke_dir(0, 0x1, 0x1);
    brd->brd_reg_poke_dir(0, 0x1, 0x1);
    brd->brd_reg_poke_ind(0, 0xC, 0x1);
    brd->brd_reg_poke_ind(0, 0x0, 0x2);
    brd->brd_reg_poke_ind(0, 0x0, 0x0);
 
    std ::cout << "Press enter to start DMA channel..." << endl;
    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);
 
    std ::cout << "Press enter to stop DMA channel..." << endl;
    getchar();
 
 
    brd->dma_stop(dmaChan);
 
    // show data buffers
    for(int j=0; j<NUM_BLOCK; j++) {
 
        fprintf(stdout, "DMA BLOCK %d\n", j);
        buffer = (u32*)pBuffers[j];
        for(unsigned i=0; i<8; i++) {
            fprintf(stdout, "0x%08X ", buffer[i]);
        }
        fprintf(stdout, "\n\n");
    }
    std::cout << dec << endl;
 
    std ::cout << "Press enter to free DMA memory..." << endl;
    getchar();
 
    brd->dma_free_memory(dmaChan);
 
    brd->brd_close();
 
    delete brd;
 
    if(hlib) {
        int res = dlclose(hlib);
        if(res < 0) {
            fprintf(stderr, "%s\n", dlerror());
            return -1;
        }
    }
 
    return 0;
}
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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