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

Subversion Repositories pcie_ds_dma

[/] [pcie_ds_dma/] [trunk/] [soft/] [linux/] [common/] [utils/] [cl_ambpex.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...
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
 
#include <sys/select.h>
#include        "board.h"
 
//#include      "brderr.h"
 
#include        "ctrlstrm.h"
 
//#include        "ctrlreg.h"
 
//#include        "useful.h"
 
//#include      "CL_AMBPEX.h"
 
 
 
#ifndef __PEX_BOARD_H__
#ifndef __PEX_BOARD_H__
#include "pex_board.h"
#include "pex_board.h"
#endif
#endif
 
 
#ifndef __BOARD_H__
#ifndef __BOARD_H__
#include "board.h"
#include "board.h"
#endif
#endif
 
 
 
#include        "ctrlstrm.h"
#include "cl_ambpex.h"
#include "cl_ambpex.h"
#include "sys/select.h"
 
//BRD_Handle g_hBrd=0;
 
 
 
 
//---------------------------------------------------------------------------
 
 
 
void Sleep( int ms );
 
 
 
//-----------------------------------------------------------------------------
//!  Инициализация модуля
//!  Инициализация модуля
U32  CL_AMBPEX::init( void )
U32  CL_AMBPEX::init( void )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
    // сброс прошивки ПЛИС
    // сброс прошивки ПЛИС
    RegPokeInd( 0, 0, 1 );
    RegPokeInd( 0, 0, 1 );
    Sleep( 100 );
    Sleep( 100 );
    RegPokeInd( 0, 0, 0 );
    RegPokeInd( 0, 0, 0 );
    Sleep( 100 );
    Sleep( 100 );
 
 
    return 0;
    return 0;
}
}
 
 
 
//-----------------------------------------------------------------------------
//!  Завершение работы с модулем
//!  Завершение работы с модулем
void  CL_AMBPEX::cleanup( void )
void  CL_AMBPEX::cleanup( void )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
}
}
 
 
 
//-----------------------------------------------------------------------------
// Доступ к регистрам 
//! Открываем модуль
CL_AMBPEX::CL_AMBPEX(const char* dev_name)
CL_AMBPEX::CL_AMBPEX(const char *devname)
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    m_pBoard = new pex_board();
    m_pBoard = new pex_board();
 
 
    if(dev_name) {
    if(devname) {
        m_pBoard->brd_open(dev_name);
        m_pBoard->brd_open(devname);
    } else {
    } else {
        m_pBoard->brd_open("/dev/AMBPEX50");
        m_pBoard->brd_open("/dev/pexdrv0");
    }
    }
 
 
    m_pBoard->brd_init();
    m_pBoard->brd_init();
    m_pBoard->brd_board_info();
    m_pBoard->brd_board_info();
    m_pBoard->brd_pld_info();
    m_pBoard->brd_pld_info();
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
CL_AMBPEX::~CL_AMBPEX()
CL_AMBPEX::~CL_AMBPEX()
{
{
    if(m_pBoard) delete m_pBoard;
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
 
 
 
 
//=********************* RegPokeInd *******************
 
//=****************************************************
 
void    CL_AMBPEX::RegPokeInd( S32 trdNo, S32 rgnum, U32 val )
void    CL_AMBPEX::RegPokeInd( S32 trdNo, S32 rgnum, U32 val )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
    m_pBoard->brd_reg_poke_ind( trdNo, rgnum, val );
    m_pBoard->brd_reg_poke_ind( trdNo, rgnum, val );
 
 
}
}
 
 
//=********************* RegPeekInd *******************
//-----------------------------------------------------------------------------
//=****************************************************
 
U32    CL_AMBPEX::RegPeekInd( S32 trdNo, S32 rgnum )
U32    CL_AMBPEX::RegPeekInd( S32 trdNo, S32 rgnum )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
    U32 ret;
    U32 ret;
    ret=m_pBoard->brd_reg_peek_ind( trdNo, rgnum );
    ret=m_pBoard->brd_reg_peek_ind( trdNo, rgnum );
    return ret;
    return ret;
}
}
 
 
//=********************* RegPokeDir *******************
//-----------------------------------------------------------------------------
//=****************************************************
 
void    CL_AMBPEX::RegPokeDir( S32 trdNo, S32 rgnum, U32 val )
void    CL_AMBPEX::RegPokeDir( S32 trdNo, S32 rgnum, U32 val )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
    m_pBoard->brd_reg_poke_dir( trdNo, rgnum, val );
    m_pBoard->brd_reg_poke_dir( trdNo, rgnum, val );
}
}
 
 
//=********************* RegPeekDir *******************
//-----------------------------------------------------------------------------
//=****************************************************
 
U32    CL_AMBPEX::RegPeekDir( S32 trdNo, S32 rgnum )
U32    CL_AMBPEX::RegPeekDir( S32 trdNo, S32 rgnum )
{
{
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
    U32 ret;
    U32 ret;
    ret=m_pBoard->brd_reg_peek_dir( trdNo, rgnum );
    ret=m_pBoard->brd_reg_peek_dir( trdNo, rgnum );
    return ret;
    return ret;
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
 
 
int CL_AMBPEX::StreamInit( U32 strm, U32 cnt_buf, U32 size_one_buf_of_bytes, U32 trd, U32 dir, U32 cycle, U32 system, U32 agree_mode )
int CL_AMBPEX::StreamInit( U32 strm, U32 cnt_buf, U32 size_one_buf_of_bytes, U32 trd, U32 dir, U32 cycle, U32 system, U32 agree_mode )
{
{
    if( strm>1 )
    if( strm>1 )
        return 1;
        return 1;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
    if( pStrm->status!=0 )
    if( pStrm->status!=0 )
        return 1;
        return 1;
 
 
    pStrm->cnt_buf      = cnt_buf;
    pStrm->cnt_buf      = cnt_buf;
Line 118... Line 124...
    pStrm->indexPc=-1;
    pStrm->indexPc=-1;
    pStrm->agree_mode=agree_mode;
    pStrm->agree_mode=agree_mode;
 
 
    StreamDestroy( strm );
    StreamDestroy( strm );
 
 
 
 
    __int64 size=cnt_buf*(__int64)size_one_buf_of_bytes/(1024*1024);
    __int64 size=cnt_buf*(__int64)size_one_buf_of_bytes/(1024*1024);
 
 
    if( system )
    if( system ) {
    {
 
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
                      _BRDC(" Type of block:    system memory\r\n")
                      _BRDC(" Type of block:    system memory\r\n")
                      _BRDC(" Block size: %lld MB\r\n"), size );
                      _BRDC(" Block size: %lld MB\r\n"), size );
    } else
    } else {
    {
 
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
                      _BRDC(" Type of block:    userspace memory\r\n")
                      _BRDC(" Type of block:    userspace memory\r\n")
                      _BRDC(" Block size: %lld MB  (%dx%d MB)\r\n"), size, cnt_buf, size_one_buf_of_bytes/(1024*1024) );
                      _BRDC(" Block size: %lld MB  (%dx%d MB)\r\n"), size, cnt_buf, size_one_buf_of_bytes/(1024*1024) );
    }
    }
 
 
Line 143... Line 148...
        (void**)&pStrm->pBlk[0],
        (void**)&pStrm->pBlk[0],
        NULL,
        NULL,
    };
    };
 
 
    u32 err = m_pBoard->dma_alloc( strm, &sSCA );
    u32 err = m_pBoard->dma_alloc( strm, &sSCA );
 
    if(err != 0) {
 
        throw( "Error allocate stream memory\n" );
 
        return -1;
 
    }
 
 
    pStrm->pStub=sSCA.pStub;
    pStrm->pStub=sSCA.pStub;
    if(!pStrm->pStub) {
    if(!pStrm->pStub) {
        throw( "Error allocate stream memory\n" );
        throw( "Error allocate stream memory\n" );
    } else {
    } else {
        printf( "Allocate stream memory - Ok\n" );
        printf( "Allocate stream memory - Ok\n" );
Line 160... Line 170...
    fprintf(stderr, "%s(): Press enter...\n", __FUNCTION__);
    fprintf(stderr, "%s(): Press enter...\n", __FUNCTION__);
    getchar();
    getchar();
*/
*/
    m_pBoard->dma_set_local_addr( strm, trd );
    m_pBoard->dma_set_local_addr( strm, trd );
 
 
    //agree_mode = 1;
 
 
 
    // Перевод на согласованный режим работы
    // Перевод на согласованный режим работы
    if( agree_mode ) {
    if( agree_mode ) {
 
 
        err = m_pBoard->dma_adjust(strm, 1);
        err = m_pBoard->dma_adjust(strm, 1);
        BRDC_fprintf( stderr, _BRDC("Stream working in adjust mode\n"));
        BRDC_fprintf( stderr, _BRDC("Stream working in adjust mode\n"));
Line 173... Line 181...
    } else {
    } else {
 
 
        BRDC_fprintf( stderr, _BRDC("Stream working in regular mode\n"));
        BRDC_fprintf( stderr, _BRDC("Stream working in regular mode\n"));
    }
    }
 
 
    m_pBoard->dma_stop(strm);//err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_STOP, NULL);
    m_pBoard->dma_stop(strm);
    m_pBoard->dma_reset_fifo(strm);//err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
    m_pBoard->dma_reset_fifo(strm);
    m_pBoard->dma_reset_fifo(strm);//err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
    m_pBoard->dma_reset_fifo(strm);
 
 
    pStrm->status=1;
    pStrm->status=1;
 
 
    return 0;
    return 0;
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
int CL_AMBPEX::StreamGetNextIndex( U32 strm, U32 index )
int CL_AMBPEX::StreamGetNextIndex( U32 strm, U32 index )
{
{
    if( strm>1 )
    if( strm>1 )
        return 0;
        return 0;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
    int n=index+1;
    int n=index+1;
    if( (U32)n>=pStrm->cnt_buf )
    if( (U32)n>=pStrm->cnt_buf )
        n=0;
        n=0;
    return n;
    return n;
 
 
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
void CL_AMBPEX::StreamDestroy( U32 strm )
void CL_AMBPEX::StreamDestroy( U32 strm )
{
{
    S32 err;
 
 
 
    if( strm>1 )
    if( strm>1 )
        return;
        return;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
    if( pStrm->status==0 )
    if( pStrm->status==0 )
        return;
        return;
 
 
    StreamStop( strm );
    StreamStop( strm );
 
 
    if( 1 )
    m_pBoard->dma_free_memory( strm );
    {
 
        BRDC_fprintf( stderr, _BRDC("\r\nStream free %.8X\r\n"), err );
 
        // pStrm->hStream=0;
 
    }
 
 
 
    pStrm->status=0;
    pStrm->status=0;
 
 
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
U32* CL_AMBPEX::StreamGetBufByNum( U32 strm, U32 numBuf )
U32* CL_AMBPEX::StreamGetBufByNum( U32 strm, U32 numBuf )
{
{
    if( strm>1 )
    if( strm>1 )
        return NULL;
        return NULL;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
    if( pStrm->status!=1 )
    if( pStrm->status!=1 )
        return NULL;
        return NULL;
 
 
    U32 *ptr;
    U32 *ptr;
Line 234... Line 246...
        return NULL;
        return NULL;
    ptr=(U32*)(pStrm->pBlk[numBuf]);
    ptr=(U32*)(pStrm->pBlk[numBuf]);
    return ptr;
    return ptr;
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
void CL_AMBPEX::StreamStart( U32 strm )
void CL_AMBPEX::StreamStart( U32 strm )
{
{
 
 
    if( strm>1 )
    if( strm>1 )
        return;
        return;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
    if( pStrm->status!=1 )
    if( pStrm->status!=1 )
        return;
        return;
 
 
    //S32 err;
 
    U32 val;
    U32 val;
 
 
    val=RegPeekInd( pStrm->trd, 0 );
    val=RegPeekInd( pStrm->trd, 0 );
    m_pBoard->dma_stop(strm);
    m_pBoard->dma_stop(strm);
 
 
 
 
    pStrm->indexDma=-1;
    pStrm->indexDma=-1;
    pStrm->indexPc=-1;
    pStrm->indexPc=-1;
 
 
    val=pStrm->cycle; // 0 - однократный режим, 1 - циклический
    val=pStrm->cycle; // 0 - однократный режим, 1 - циклический
 
 
    m_pBoard->dma_start(strm, val);
    m_pBoard->dma_start(strm, val);
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
void CL_AMBPEX::StreamStop( U32 strm )
void CL_AMBPEX::StreamStop( U32 strm )
{
{
    if( strm>1 )
    if( strm>1 )
        return;
        return;
 
 
    StreamParam *pStrm= m_streamParam+strm;
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    S32 err;
    StreamParam *pStrm= m_streamParam+strm;
 
 
    RegPokeInd( pStrm->trd, 0, 2 );
    RegPokeInd( pStrm->trd, 0, 2 );
 
 
    m_pBoard->dma_stop(strm);//err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_STOP, NULL);
    m_pBoard->dma_stop(strm);
    m_pBoard->dma_reset_fifo(strm);//err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
    m_pBoard->dma_reset_fifo(strm);
 
 
    RegPokeInd( pStrm->trd, 0, 0 );
    RegPokeInd( pStrm->trd, 0, 0 );
 
 
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
int CL_AMBPEX::StreamGetBuf( U32 strm, U32** ptr )
int CL_AMBPEX::StreamGetBuf( U32 strm, U32** ptr )
{
{
    U32 *buf;
    U32 *buf;
    int ret=0;
    int ret=0;
 
 
    if( strm>1 )
    if( strm>1 )
        return 0;
        return 0;
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    if( pStrm->indexPc==pStrm->indexDma )
    if( pStrm->indexPc==pStrm->indexDma )
    {
    {
        pStrm->indexDma = StreamGetIndexDma( strm );
        pStrm->indexDma = StreamGetIndexDma( strm );
    }
    }
Line 302... Line 321...
        StreamGetBufDone( strm );
        StreamGetBufDone( strm );
    }
    }
    return ret;
    return ret;
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
int CL_AMBPEX::StreamGetIndexDma( U32 strm )
int CL_AMBPEX::StreamGetIndexDma( U32 strm )
{
{
    if( strm>1 )
    if( strm>1 )
        return -1;
        return -1;
 
 
 
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
 
 
    if(!pStrm->pStub) {
    if(!pStrm->pStub) {
        //fprintf(stderr, "%s(): pStub is %p\n", __FUNCTION__, pStrm->pStub);
        //fprintf(stderr, "%s(): pStub is %p\n", __FUNCTION__, pStrm->pStub);
        return 0;
        return 0;
Line 321... Line 344...
    //fprintf(stderr, "%s(): lastBlock = %d\n", __FUNCTION__, lastBlock);
    //fprintf(stderr, "%s(): lastBlock = %d\n", __FUNCTION__, lastBlock);
 
 
    return lastBlock;
    return lastBlock;
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
void CL_AMBPEX::StreamGetBufDone( U32 strm )
void CL_AMBPEX::StreamGetBufDone( U32 strm )
{
{
    //fprintf(stderr, "%s()\n", __FUNCTION__);
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
 
 
    if( strm>1 )
    if( strm>1 )
        return;
        return;
 
 
    StreamParam *pStrm= m_streamParam+strm;
    StreamParam *pStrm= m_streamParam+strm;
Line 342... Line 367...
        if(!err)
        if(!err)
            err_code++; // Ошибка перевода в согласованный режим
            err_code++; // Ошибка перевода в согласованный режим
    }
    }
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
void Sleep( int ms )
void Sleep( int ms )
{
{
    struct timeval tv = {0, 0};
    struct timeval tv = {0, 0};
    tv.tv_usec = 1000*ms;
    tv.tv_usec = 1000*ms;
 
 
    select(0,NULL,NULL,NULL,&tv);
    select(0,NULL,NULL,NULL,&tv);
}
}
 
 
 
//-----------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 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.