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_wbpex.cpp] - Blame information for rev 55

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

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

powered by: WebSVN 2.1.0

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