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 2

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

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

powered by: WebSVN 2.1.0

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