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 6

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_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 6 v.karak
    //S32 err;
28
    //S32 num;
29 2 dsmv
 
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 6 v.karak
    brd->brd_open( "/dev/pexdrv0" );
45 2 dsmv
    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 6 v.karak
    //S32 ret;
57 2 dsmv
    //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
    StreamParam *pStrm= m_streamParam+strm;
81
    if( pStrm->status!=0 )
82
        return 1;
83
 
84
    pStrm->cnt_buf      = cnt_buf;
85
    pStrm->size_one_buf_of_bytes =      size_one_buf_of_bytes;
86
    pStrm->trd          = trd;
87
    pStrm->cycle        = cycle;
88
    pStrm->system       = system;
89
 
90
    pStrm->indexDma=-1;
91
    pStrm->indexPc=-1;
92
    pStrm->agree_mode=agree_mode;
93
 
94
    StreamDestroy( strm );
95
 
96
 
97
    //U32 size=cnt_buf*size_one_buf_of_bytes/(1024*1024);
98
    __int64 size=cnt_buf*(__int64)size_one_buf_of_bytes/(1024*1024);
99
 
100
    if( system )
101
    {
102
        BRDC_fprintf( stderr, _BRDC("Выделение памяти: \r\n")
103
                     _BRDC(" Тип блока:    Непрерывный (системная память)\r\n")
104
                     _BRDC(" Размер блока: %lld МБ\r\n"), size );
105
    } else
106
    {
107
        BRDC_fprintf( stderr, _BRDC("Выделение памяти: \r\n")
108
                     _BRDC(" Тип блока:    Разрывный (пользовательская память)\r\n")
109
                     _BRDC(" Размер блока: %lld МБ  (%dx%d МБ)\r\n"), size, cnt_buf, size_one_buf_of_bytes/(1024*1024) );
110
    }
111
 
112
 
113
 
114
 
115
    // Перевод на согласованный режим работы
116
    if( agree_mode )
117
    {
118
    } else
119
    {
120
        BRDC_fprintf( stderr, _BRDC("Стрим работает в несогласованном режиме\r\n") );
121
    }
122
    BRDC_fprintf( stderr, "\r\n" );
123
 
124
/*
125
    err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_STOP, NULL);
126
 
127
    err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
128
 
129
 
130
    err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
131
*/
132
    pStrm->status=1;
133
 
134
    return 0;
135
}
136
 
137
int CL_WBPEX::StreamGetNextIndex( U32 strm, U32 index )
138
{
139
    if( strm>1 )
140
        return 0;
141
 
142
    StreamParam *pStrm= m_streamParam+strm;
143
    int n=index+1;
144
    if( (U32)n>=pStrm->cnt_buf )
145
        n=0;
146
    return n;
147
 
148
}
149
 
150
void CL_WBPEX::StreamDestroy( U32 strm )
151
{
152
    S32 err;
153
 
154
    if( strm>1 )
155
        return;
156
 
157
    StreamParam *pStrm= m_streamParam+strm;
158
    if( pStrm->status==0 )
159
        return;
160
 
161
    StreamStop( strm );
162
 
163
    if( 1 )
164
    {
165
        BRDC_fprintf( stderr, _BRDC("\r\nОсвобождение стрима  %.8X\r\n"), err );
166
       // pStrm->hStream=0;
167
    }
168
    pStrm->status=0;
169
 
170
}
171
 
172
U32* CL_WBPEX::StreamGetBufByNum( U32 strm, U32 numBuf )
173
{
174
    if( strm>1 )
175
        return NULL;
176
 
177
    StreamParam *pStrm= m_streamParam+strm;
178
    if( pStrm->status!=1 )
179
        return NULL;
180
 
181
    U32 *ptr;
182
    if( numBuf>=pStrm->cnt_buf )
183
        return NULL;
184
    ptr=(U32*)(pStrm->pBlk[numBuf]);
185
    return ptr;
186
}
187
 
188
void CL_WBPEX::StreamStart( U32 strm )
189
{
190
 
191
    if( strm>1 )
192
        return;
193
 
194
    StreamParam *pStrm= m_streamParam+strm;
195
    if( pStrm->status!=1 )
196
        return;
197
 
198 6 v.karak
    //S32 err;
199
    //U32 val;
200 2 dsmv
 
201
    //val=RegPeekInd( pStrm->trd, 0 );
202
    //err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_STOP, NULL);
203
 
204
 
205
    pStrm->indexDma=-1;
206
    pStrm->indexPc=-1;
207
 
208 6 v.karak
    //val=pStrm->cycle; // 0 - однократный режим, 1 - циклический
209 2 dsmv
    //err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_START, &val );
210
}
211
 
212
void CL_WBPEX::StreamStop( U32 strm )
213
{
214
    if( strm>1 )
215
        return;
216
 
217 6 v.karak
    //StreamParam *pStrm= m_streamParam+strm;
218 2 dsmv
 
219 6 v.karak
    //S32 err;
220 2 dsmv
 
221
    //RegPokeInd( pStrm->trd, 0, 2 );
222
 
223
    //err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_CBUF_STOP, NULL);
224
 
225
    //err = BRD_ctrl( pStrm->hStream, 0, BRDctrl_STREAM_RESETFIFO, NULL );
226
 
227
    //RegPokeInd( pStrm->trd, 0, 0 );
228
 
229
}
230
 
231
int CL_WBPEX::StreamGetBuf( U32 strm, U32** ptr )
232
{
233
    U32 *buf;
234
    int ret=0;
235
 
236
    if( strm>1 )
237
        return 0;
238
 
239
    StreamParam *pStrm= m_streamParam+strm;
240
 
241
 
242
    if( pStrm->indexPc==pStrm->indexDma )
243
    {
244
        pStrm->indexDma = StreamGetIndexDma( strm );
245
    }
246
    if( pStrm->indexPc!=pStrm->indexDma )
247
    {
248
        pStrm->indexPc=StreamGetNextIndex( strm, pStrm->indexPc );
249
        buf = StreamGetBufByNum( strm, pStrm->indexPc );
250
        *ptr = buf;
251
        ret=1;
252
        //StreamGetBufDone( strm );
253
    }
254
    return ret;
255
}
256
 
257
int CL_WBPEX::StreamGetIndexDma( U32 strm )
258
{
259
    if( strm>1 )
260
        return -1;
261
 
262 6 v.karak
    //StreamParam *pStrm= m_streamParam+strm;
263 2 dsmv
 
264
 
265
 
266
//    int ret = pStrm->pStub->lastBlock;
267
    return 0;
268
}
269
 
270
void CL_WBPEX::StreamGetBufDone( U32 strm )
271
{
272
    if( strm>1 )
273
        return;
274
 
275
    StreamParam *pStrm= m_streamParam+strm;
276 6 v.karak
    //S32 err;
277
    //static U32 err_code=0;
278 2 dsmv
 
279
    if( pStrm->agree_mode )
280
    {
281
    }
282
}
283
 
284
/*
285
void Sleep( int ms )
286
{
287
    struct timeval tv = {0, 0};
288
    tv.tv_usec = 1000*ms;
289
 
290
    select(0,NULL,NULL,NULL,&tv);
291
 
292
}
293
*/
294
 
295
 
296
 
297
//! Запись в регистр блока на шине WB
298
void CL_WBPEX::wb_block_write( U32 nb, U32 reg, U32 val )
299
{
300
    if( (nb>1) || (reg>31) )
301
        return;
302
    m_pBoard->brd_bar1_write( nb*0x2000/4+reg*2, val );
303
}
304
 
305
//! Чтение из регистра блока на шине WB
306
U32 CL_WBPEX::wb_block_read( U32 nb, U32 reg )
307
{
308
    U32 ret;
309
    if( (nb>1) || (reg>31) )
310
        return -1;
311
    ret=m_pBoard->brd_bar1_read( nb*0x2000/4+reg*2 );
312
    return ret;
313
}
314
 
315
 

powered by: WebSVN 2.1.0

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