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] - Blame information for rev 15

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

Line No. Rev Author Line
1 2 dsmv
//---------------------------------------------------------------------------
2 6 v.karak
 
3 2 dsmv
#include <stdio.h>
4
#include <stdint.h>
5 6 v.karak
#include <sys/select.h>
6 2 dsmv
 
7
#ifndef __PEX_BOARD_H__
8
#include "pex_board.h"
9
#endif
10
#ifndef __BOARD_H__
11
#include "board.h"
12
#endif
13
 
14 6 v.karak
#include        "ctrlstrm.h"
15
#include        "cl_ambpex.h"
16 2 dsmv
 
17 6 v.karak
//---------------------------------------------------------------------------
18
 
19
void Sleep( int ms );
20
 
21
//-----------------------------------------------------------------------------
22 2 dsmv
//!  Инициализация модуля
23
U32  CL_AMBPEX::init( void )
24
{
25 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
26 2 dsmv
    // сброс прошивки ПЛИС
27
    RegPokeInd( 0, 0, 1 );
28
    Sleep( 100 );
29
    RegPokeInd( 0, 0, 0 );
30
    Sleep( 100 );
31
 
32
    return 0;
33
}
34
 
35 6 v.karak
//-----------------------------------------------------------------------------
36 2 dsmv
//!  Завершение работы с модулем
37
void  CL_AMBPEX::cleanup( void )
38
{
39 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
40 2 dsmv
}
41
 
42 6 v.karak
//-----------------------------------------------------------------------------
43
//! Открываем модуль
44
CL_AMBPEX::CL_AMBPEX(const char *devname)
45
{
46
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
47 2 dsmv
 
48
    m_pBoard = new pex_board();
49
 
50 6 v.karak
    if(devname) {
51
        m_pBoard->brd_open(devname);
52 2 dsmv
    } else {
53 6 v.karak
        m_pBoard->brd_open("/dev/pexdrv0");
54 2 dsmv
    }
55
 
56
    m_pBoard->brd_init();
57
    m_pBoard->brd_board_info();
58
    m_pBoard->brd_pld_info();
59
}
60
 
61 6 v.karak
//-----------------------------------------------------------------------------
62
 
63 2 dsmv
CL_AMBPEX::~CL_AMBPEX()
64
{
65 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
66 2 dsmv
}
67
 
68 6 v.karak
//-----------------------------------------------------------------------------
69 2 dsmv
 
70
void    CL_AMBPEX::RegPokeInd( S32 trdNo, S32 rgnum, U32 val )
71
{
72 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
73 2 dsmv
    m_pBoard->brd_reg_poke_ind( trdNo, rgnum, val );
74
}
75
 
76 6 v.karak
//-----------------------------------------------------------------------------
77
 
78 2 dsmv
U32    CL_AMBPEX::RegPeekInd( S32 trdNo, S32 rgnum )
79
{
80 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
81 2 dsmv
    U32 ret;
82
    ret=m_pBoard->brd_reg_peek_ind( trdNo, rgnum );
83
    return ret;
84
}
85
 
86 6 v.karak
//-----------------------------------------------------------------------------
87
 
88 2 dsmv
void    CL_AMBPEX::RegPokeDir( S32 trdNo, S32 rgnum, U32 val )
89
{
90 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
91 2 dsmv
    m_pBoard->brd_reg_poke_dir( trdNo, rgnum, val );
92
}
93
 
94 6 v.karak
//-----------------------------------------------------------------------------
95
 
96 2 dsmv
U32    CL_AMBPEX::RegPeekDir( S32 trdNo, S32 rgnum )
97
{
98 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
99 2 dsmv
    U32 ret;
100
    ret=m_pBoard->brd_reg_peek_dir( trdNo, rgnum );
101
    return ret;
102
}
103
 
104 6 v.karak
//-----------------------------------------------------------------------------
105 2 dsmv
 
106
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 )
107
{
108
    if( strm>1 )
109
        return 1;
110
 
111 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
112
 
113 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
114
    if( pStrm->status!=0 )
115
        return 1;
116
 
117 6 v.karak
    pStrm->cnt_buf                  = cnt_buf;
118
    pStrm->size_one_buf_of_bytes    = size_one_buf_of_bytes;
119
    pStrm->trd                      = trd;
120
    pStrm->cycle                    = cycle;
121
    pStrm->system                   = system;
122 2 dsmv
 
123
    pStrm->indexDma=-1;
124
    pStrm->indexPc=-1;
125
    pStrm->agree_mode=agree_mode;
126
 
127
    StreamDestroy( strm );
128
 
129
    __int64 size=cnt_buf*(__int64)size_one_buf_of_bytes/(1024*1024);
130
 
131 6 v.karak
    if( system ) {
132
 
133 2 dsmv
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
134
                      _BRDC(" Type of block:    system memory\r\n")
135
                      _BRDC(" Block size: %lld MB\r\n"), size );
136 6 v.karak
    } else {
137
 
138 2 dsmv
        BRDC_fprintf( stderr, _BRDC("Allocation memory: \r\n")
139
                      _BRDC(" Type of block:    userspace memory\r\n")
140
                      _BRDC(" Block size: %lld MB  (%dx%d MB)\r\n"), size, cnt_buf, size_one_buf_of_bytes/(1024*1024) );
141
    }
142
 
143
    BRDctrl_StreamCBufAlloc sSCA = {
144
        dir,
145
        system,
146
        cnt_buf,
147
        size_one_buf_of_bytes,
148
        (void**)&pStrm->pBlk[0],
149
        NULL,
150
    };
151
 
152
    u32 err = m_pBoard->dma_alloc( strm, &sSCA );
153 6 v.karak
    if(err != 0) {
154
        throw( "Error allocate stream memory\n" );
155
        return -1;
156
    }
157
 
158 2 dsmv
    pStrm->pStub=sSCA.pStub;
159
    if(!pStrm->pStub) {
160
        throw( "Error allocate stream memory\n" );
161
    } else {
162
        printf( "Allocate stream memory - Ok\n" );
163
    }
164
    /*
165
    for(int j=0; j<sSCA.blkNum; j++) {
166
        fprintf(stderr, "%s(): pBlk[%d] = %p\n", __FUNCTION__, j, pStrm->pBlk[j]);
167
    }
168
    fprintf(stderr, "%s(): pStub = %p\n", __FUNCTION__, pStrm->pStub);
169
 
170
    fprintf(stderr, "%s(): Press enter...\n", __FUNCTION__);
171
    getchar();
172
*/
173
    m_pBoard->dma_set_local_addr( strm, trd );
174
 
175
    // Перевод на согласованный режим работы
176
    if( agree_mode ) {
177
 
178
        err = m_pBoard->dma_adjust(strm, 1);
179
        BRDC_fprintf( stderr, _BRDC("Stream working in adjust mode\n"));
180
 
181
    } else {
182
 
183
        BRDC_fprintf( stderr, _BRDC("Stream working in regular mode\n"));
184
    }
185
 
186 6 v.karak
    m_pBoard->dma_stop(strm);
187
    m_pBoard->dma_reset_fifo(strm);
188
    m_pBoard->dma_reset_fifo(strm);
189 2 dsmv
 
190
    pStrm->status=1;
191
 
192
    return 0;
193
}
194
 
195 6 v.karak
//-----------------------------------------------------------------------------
196
 
197 2 dsmv
int CL_AMBPEX::StreamGetNextIndex( U32 strm, U32 index )
198
{
199
    if( strm>1 )
200
        return 0;
201
 
202 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
203
 
204 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
205
    int n=index+1;
206
    if( (U32)n>=pStrm->cnt_buf )
207
        n=0;
208
    return n;
209
}
210
 
211 6 v.karak
//-----------------------------------------------------------------------------
212
 
213 2 dsmv
void CL_AMBPEX::StreamDestroy( U32 strm )
214
{
215
    if( strm>1 )
216
        return;
217
 
218 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
219
 
220 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
221
    if( pStrm->status==0 )
222
        return;
223
 
224
    StreamStop( strm );
225
 
226 6 v.karak
    m_pBoard->dma_free_memory( strm );
227 2 dsmv
 
228
    pStrm->status=0;
229
}
230
 
231 6 v.karak
//-----------------------------------------------------------------------------
232
 
233 2 dsmv
U32* CL_AMBPEX::StreamGetBufByNum( U32 strm, U32 numBuf )
234
{
235
    if( strm>1 )
236
        return NULL;
237
 
238 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
239
 
240 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
241
    if( pStrm->status!=1 )
242
        return NULL;
243
 
244
    U32 *ptr;
245
    if( numBuf>=pStrm->cnt_buf )
246
        return NULL;
247
    ptr=(U32*)(pStrm->pBlk[numBuf]);
248
    return ptr;
249
}
250
 
251 6 v.karak
//-----------------------------------------------------------------------------
252
 
253 2 dsmv
void CL_AMBPEX::StreamStart( U32 strm )
254
{
255
    if( strm>1 )
256
        return;
257
 
258 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
259
 
260 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
261
    if( pStrm->status!=1 )
262
        return;
263
 
264
    U32 val;
265
 
266
    val=RegPeekInd( pStrm->trd, 0 );
267
    m_pBoard->dma_stop(strm);
268
 
269
 
270
    pStrm->indexDma=-1;
271
    pStrm->indexPc=-1;
272
 
273
    val=pStrm->cycle; // 0 - однократный режим, 1 - циклический
274 6 v.karak
 
275 2 dsmv
    m_pBoard->dma_start(strm, val);
276
}
277
 
278 6 v.karak
//-----------------------------------------------------------------------------
279
 
280 2 dsmv
void CL_AMBPEX::StreamStop( U32 strm )
281
{
282
    if( strm>1 )
283
        return;
284
 
285 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
286
 
287 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
288
 
289
    RegPokeInd( pStrm->trd, 0, 2 );
290
 
291 6 v.karak
    m_pBoard->dma_stop(strm);
292
    m_pBoard->dma_reset_fifo(strm);
293 2 dsmv
 
294
    RegPokeInd( pStrm->trd, 0, 0 );
295
}
296
 
297 6 v.karak
//-----------------------------------------------------------------------------
298
 
299 2 dsmv
int CL_AMBPEX::StreamGetBuf( U32 strm, U32** ptr )
300
{
301
    U32 *buf;
302
    int ret=0;
303
 
304
    if( strm>1 )
305
        return 0;
306
 
307
    StreamParam *pStrm= m_streamParam+strm;
308
 
309 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
310 2 dsmv
 
311
    if( pStrm->indexPc==pStrm->indexDma )
312
    {
313
        pStrm->indexDma = StreamGetIndexDma( strm );
314
    }
315
    if( pStrm->indexPc!=pStrm->indexDma )
316
    {
317
        pStrm->indexPc=StreamGetNextIndex( strm, pStrm->indexPc );
318
        buf = StreamGetBufByNum( strm, pStrm->indexPc );
319
        *ptr = buf;
320
        ret=1;
321
        StreamGetBufDone( strm );
322
    }
323
    return ret;
324
}
325
 
326 6 v.karak
//-----------------------------------------------------------------------------
327
 
328 2 dsmv
int CL_AMBPEX::StreamGetIndexDma( U32 strm )
329
{
330
    if( strm>1 )
331
        return -1;
332
 
333 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
334
 
335 2 dsmv
    StreamParam *pStrm= m_streamParam+strm;
336
 
337
    if(!pStrm->pStub) {
338
        //fprintf(stderr, "%s(): pStub is %p\n", __FUNCTION__, pStrm->pStub);
339
        return 0;
340
    }
341
 
342
    int lastBlock = pStrm->pStub->lastBlock;
343
 
344
    //fprintf(stderr, "%s(): lastBlock = %d\n", __FUNCTION__, lastBlock);
345
 
346
    return lastBlock;
347
}
348
 
349 6 v.karak
//-----------------------------------------------------------------------------
350
 
351 2 dsmv
void CL_AMBPEX::StreamGetBufDone( U32 strm )
352
{
353 6 v.karak
    DEBUG_PRINT("CL_AMBPEX::%s()\n", __FUNCTION__);
354 2 dsmv
 
355
    if( strm>1 )
356
        return;
357
 
358
    StreamParam *pStrm= m_streamParam+strm;
359
    S32 err;
360
    static U32 err_code=0;
361
 
362
    if( pStrm->agree_mode )
363
    {
364
        //fprintf(stderr, "%s(): Press enter to continue block %d...\n", __FUNCTION__, pStrm->indexPc);
365
        //getchar();
366
        err = m_pBoard->dma_done(strm, pStrm->indexPc);
367
        if(!err)
368
            err_code++; // Ошибка перевода в согласованный режим
369
    }
370
}
371
 
372 6 v.karak
//-----------------------------------------------------------------------------
373 2 dsmv
 
374
void Sleep( int ms )
375
{
376
    struct timeval tv = {0, 0};
377
    tv.tv_usec = 1000*ms;
378
 
379
    select(0,NULL,NULL,NULL,&tv);
380
}
381
 
382 6 v.karak
//-----------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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