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

Subversion Repositories pcie_ds_dma

[/] [pcie_ds_dma/] [trunk/] [soft/] [linux/] [application/] [wb_test/] [src/] [work/] [wb_teststrmout.cpp] - Blame information for rev 28

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

Line No. Rev Author Line
1 2 dsmv
 
2
 
3
#define _USE_MATH_DEFINES
4
 
5
#include <math.h>
6
#include <stdio.h>
7
#include <fcntl.h>
8
#include <pthread.h>
9
#include <sys/types.h>
10
#include <sys/stat.h>
11
 
12
#include "utypes.h"
13
//#include "useful.h"
14
#include "wb_teststrmout.h"
15
#include "cl_wbpex.h"
16
 
17
 
18
 
19
#define BUFSIZEPKG 62
20
 
21
#define TRDIND_MODE0                                    0x0
22
#define TRDIND_MODE1                                    0x9
23
#define TRDIND_MODE2                                    0xA
24
#define TRDIND_SPD_CTRL                                 0x204
25
#define TRDIND_SPD_ADDR                                 0x205
26
#define TRDIND_SPD_DATA                                 0x206
27
 
28
 
29
WB_TestStrmOut::WB_TestStrmOut( BRDCHAR* fname, CL_WBPEX *fotr )
30
{
31
    lc_status=0;
32
 
33
    Terminate=0;
34
    BlockRd=0;
35
    BlockOk=0;
36
    BlockError=0;
37
    TotalError=0;
38
 
39
    pBrd=fotr;
40
 
41
    SetDefault();
42
    GetParamFromFile( fname );
43
    CalculateParams();
44
 
45
    //  pDds=NULL;
46
 
47
    isFirstCallStep=true;
48
 
49
    SetSignalInit();
50
}
51
 
52
WB_TestStrmOut::~WB_TestStrmOut()
53
{
54
    pBrd->StreamDestroy( tr0.Strm );
55
 
56
}
57
 
58
void WB_TestStrmOut::Prepare( void )
59
{
60
 
61
 
62
    PrepareAdm();
63
 
64
    tr0.trd=trdNo;
65
    tr0.Strm=strmNo;
66
    pBrd->StreamInit( tr0.Strm, CntBuffer, SizeBuferOfBytes, tr0.trd, 2, isCycle, isSystem, isAgreeMode );
67
 
68
}
69
 
70
void WB_TestStrmOut::Start( void )
71
{
72
    int res = pthread_attr_init(&attrThread_);
73
    if(res != 0) {
74
        fprintf(stderr, "%s\n", "Stream not started");
75
        return;
76
    }
77
 
78
    res = pthread_attr_setdetachstate(&attrThread_, PTHREAD_CREATE_JOINABLE);
79
    if(res != 0) {
80
        fprintf(stderr, "%s\n", "Stream not started");
81
        return;
82
    }
83
 
84
    res = pthread_create(&hThread, &attrThread_, ThreadFunc, this);
85
    if(res != 0) {
86
        fprintf(stderr, "%s\n", "Stream not started");
87
        return;
88
    }
89
}
90
 
91
void WB_TestStrmOut::Stop( void )
92
{
93
    if( isTest )
94
        TestCtrlStop( &tr0 );
95
 
96
    Terminate=1;
97
    lc_status=3;
98
}
99
 
100
void WB_TestStrmOut::Step( void )
101
{
102
 
103
 
104
    if( isTest )
105
        TestCtrlReadStatus( &tr0 );
106
 
107
    U32 status = 0;// pBrd->RegPeekDir( tr0.trd, 0 ) & 0xFFFF;
108
    BRDC_fprintf( stderr, "%6s %3d %10d %10d %10d %10d  %9.1f %10.1f     0x%.4X  \r", "TRD :", tr0.trd, tr0.BlockWr, tr0.BlockRd, tr0.BlockOk, tr0.BlockError, tr0.VelocityCurrent, tr0.VelocityAvarage, status );
109
 
110
 
111
 
112
 
113
}
114
 
115
int WB_TestStrmOut::isComplete( void )
116
{
117
    if( (lc_status==4)  )
118
        return 1;
119
    return 0;
120
}
121
 
122
void WB_TestStrmOut::GetResult( void )
123
{
124
    //if(pkg_in.BlockRd!=0 && pkg_in.BlockError!=0)
125
    //  printf("%s\n", pkg_in.testBuf.report_word_error());
126
 
127
    if( isTest )
128
    {
129
        BRDC_fprintf( stderr, "\n\nРезультат передачи данных через тетраду %d \n", trdNo );
130
        TestCtrlResult( &tr0 );
131
    }
132
    BRDC_fprintf( stderr, "\n\n" );
133
}
134
 
135
void* WB_TestStrmOut::ThreadFunc( void*   lpvThreadParm )
136
{
137
    WB_TestStrmOut *test=(WB_TestStrmOut*)lpvThreadParm;
138
    UINT ret;
139
    if( !test )
140
        return 0;
141
    ret=test->Execute();
142
    return (void*)ret;
143
}
144
 
145
 
146
 
147
//! Установка параметров по умолчанию
148
void WB_TestStrmOut::SetDefault( void )
149
{
150
    int ii=0;
151
 
152
    array_cfg[ii++]=STR_CFG(  0, "CntBuffer",                    "16", (U32*)&CntBuffer, "число буферов стрима" );
153
    array_cfg[ii++]=STR_CFG(  0, "CntBlockInBuffer",     "512",  (U32*)&CntBlockInBuffer, "Число блоков в буфере" );
154
    array_cfg[ii++]=STR_CFG(  0, "SizeBlockOfWords",     "2048",  (U32*)&SizeBlockOfWords, "Размер блока в словах" );
155
    array_cfg[ii++]=STR_CFG(  0, "isCycle",                              "1",  (U32*)&isCycle, "1 - Циклический режим работы стрима" );
156
    array_cfg[ii++]=STR_CFG(  0, "isSystem",                     "0",  (U32*)&isSystem, "1 - выделение системной памяти" );
157
    array_cfg[ii++]=STR_CFG(  0, "isAgreeMode",                  "0",  (U32*)&isAgreeMode, "1 - согласованный режим" );
158
 
159
    array_cfg[ii++]=STR_CFG(  0, "trdNo",        "4",  (U32*)&trdNo, "Номер тетрады" );
160
    array_cfg[ii++]=STR_CFG(  0, "strmNo",       "0",  (U32*)&strmNo, "Номер стрма" );
161
    array_cfg[ii++]=STR_CFG(  0, "isSdram",      "0",  (U32*)&isSdram, "1 - тетрада SDRAM" );
162
    array_cfg[ii++]=STR_CFG(  0, "isTest",       "0",  (U32*)&isTest, "0 - нет, 1 - проверка псевдослучайной последовательности" );
163
 
164
    array_cfg[ii++]=STR_CFG(  0, "DataType",     "0",  (U32*)&tr0.DataType, "Тип данных при фиксированном типе блока, 6 - счётчик, 8 - псевдослучайная последовательность" );
165
 
166
    array_cfg[ii++]=STR_CFG(  0, "DataFix",      "0",  (U32*)&tr0.DataFix, "1 - фиксированный тип блока, 0 - данные в блоке записят от номера блока" );
167
 
168
 
169
 
170
    max_item=ii;
171
 
172
    {
173
        char str[1024];
174
        for( unsigned ii=0; ii<max_item; ii++ )
175
        {
176
            sprintf( str, "%s  %s", array_cfg[ii].name, array_cfg[ii].def );
177
            GetParamFromStr( str );
178
        }
179
 
180
 
181
    }
182
 
183
}
184
 
185
//! Расчёт параметров
186
void WB_TestStrmOut::CalculateParams( void )
187
{
188
    SizeBlockOfBytes = SizeBlockOfWords * 4;                                            // Размер блока в байтах
189
    SizeBuferOfBytes    = CntBlockInBuffer * SizeBlockOfBytes  ;        // Размер буфера в байтах
190
    SizeStreamOfBytes   = CntBuffer * SizeBuferOfBytes;                         // Общий размер буфера стрима
191
 
192
    ShowParam();
193
}
194
 
195
//! Отображение параметров
196
void WB_TestStrmOut::ShowParam( void )
197
{
198
    TF_WorkParam::ShowParam();
199
 
200
    BRDC_fprintf( stderr, "Общий размер буфера стрима: %d МБ\n\n", SizeStreamOfBytes/(1024*1024) );
201
 
202
}
203
 
204
 
205
U32 WB_TestStrmOut::Execute( void )
206
{
207
    tr0.testBuf.buf_check_start( 32, 64 );
208
 
209
    { // Начальное заполнение кольцевого буфера
210
        U32 ii, kk, mode;
211
        U32 *ptr, *ptrBlock;
212
        mode = (tr0.DataFix << 7) | (tr0.DataType<<8);
213
        for( kk=0; kk<CntBuffer; kk++ )
214
        {
215
            ptr=pBrd->StreamGetBufByNum( tr0.Strm, kk );
216
            for( ii=0; ii<CntBlockInBuffer; ii++ )
217
            {
218
 
219
                ptrBlock=ptr+ii*SizeBlockOfWords;
220
 
221
                if( isTest )
222
                    tr0.testBuf.buf_set( ptrBlock, tr0.BlockWr, SizeBlockOfWords, mode );
223
                else
224
                    SetSignal( ptrBlock );
225
 
226
                tr0.BlockWr++;
227
 
228
            }
229
        }
230
 
231
        TestCtrlStart( &tr0 );
232
    }
233
 
234
 
235
 
236
 
237
    //pBrd->RegPokeInd( tr0.trd, 0, 0x2030 );
238
 
239
 
240
    pBrd->StreamStart( tr0.Strm );
241
 
242
 
243
 
244
 
245
    tr0.BlockLast=tr0.BlockStart=tr0.BlockWr;
246
 
247
    //pBrd->RegPokeInd( tr0.trd, 0, 0x2038 );
248
 
249
    Sleep( 100 );
250
 
251
 
252
 
253
    tr0.time_last=tr0.time_start=0;//GetTickCount();
254
 
255
 
256
    for( ; ; )
257
    {
258
        if( Terminate )
259
        {
260
            break;
261
        }
262
 
263
        SendData( &tr0 );
264
 
265
    }
266
    //pBrd->RegPokeInd( tr0.trd, 0, 2 );
267
    Sleep( 200 );
268
 
269
    //pBrd->StreamStop( tr0.Strm );
270
    Sleep( 10 );
271
 
272
 
273
    lc_status=4;
274
    return 1;
275
}
276
 
277
 
278
 
279
 
280
void WB_TestStrmOut::SendData(  ParamExchange *pr )
281
{
282
    U32 *ptr;
283
    U32 *ptrBlock;
284
    U32 mode=0;
285
    mode |= pr->DataType<<8;
286
    mode |= pr->DataFix<<7;
287
 
288
    int ret;
289
    int kk;
290
 
291
    //pr->BlockRd++;
292
    //Sleep( 10 );
293
    //return;
294
 
295
 
296
    for( kk=0; kk<16; kk++ )
297
    {
298
        ret=pBrd->StreamGetBuf( pr->Strm, &ptr );
299
        if( ret )
300
        { // Заполнение буфера стрима
301
            for( unsigned ii=0; ii<CntBlockInBuffer; ii++ )
302
            {
303
                ptrBlock=ptr+ii*SizeBlockOfWords;
304
 
305
                if( isTest )
306
                    pr->testBuf.buf_set( ptrBlock, pr->BlockWr, SizeBlockOfWords, mode );
307
                /*
308
                                else
309
                                        SetSignal( ptrBlock );
310
                                */
311
                pr->BlockWr++;
312
                if( isAgreeMode )
313
                {
314
                    pBrd->StreamGetBufDone( pr->Strm );
315
                }
316
 
317
            }
318
        } else
319
        {
320
            //Sleep( 0 );
321
            pr->freeCycle++;
322
            //break;
323
        }
324
    }
325
    //Sleep( 0 );
326
 
327
/*
328
    U32 currentTime = GetTickCount();
329
    if( (currentTime - pr->time_last)>4000 )
330
    {
331
        float t1 = currentTime - pr->time_last;
332
        float t2 = currentTime - pr->time_start;
333
        float v = 1000.0*(pr->BlockWr-pr->BlockLast)*SizeBlockOfBytes/t1;
334
        v/=1024*1024;
335
        pr->VelocityCurrent=v;
336
 
337
        v = 1000.0*(pr->BlockWr-pr->BlockStart)*SizeBlockOfBytes/t2;
338
        v/=1024*1024;
339
        pr->VelocityAvarage=v;
340
        pr->time_last = currentTime;
341
        pr->BlockLast = pr->BlockWr;
342
        pr->freeCycleZ=pr->freeCycle;
343
        pr->freeCycle=0;
344
 
345
    }
346
    //Sleep(1);
347
*/
348
 
349
}
350
 
351
 
352
void WB_TestStrmOut::PrepareAdm( void )
353
{
354
    U32 trd=trdNo;
355
    U32 id, id_mod, ver;
356
    BRDC_fprintf( stderr, "\nПодготовка тетрады\n" );
357
 
358
 
359
    //id = pBrd->RegPeekInd( trd, 0x100 );
360
    //id_mod = pBrd->RegPeekInd( trd, 0x101 );
361
    //ver = pBrd->RegPeekInd( trd, 0x102 );
362
 
363
 
364
    //BRDC_fprintf( stderr, "\nТетрада %d  ID: 0x%.2X MOD: %d  VER: %d.%d \n\n",
365
//            trd, id, id_mod, (ver>>8) & 0xFF, ver&0xFF );
366
 
367
 
368
 
369
 
370
 
371
}
372
 
373
 
374
 
375
 
376
//! Запуск проверки в тетраде TestCtrl
377
void WB_TestStrmOut::TestCtrlStart( ParamExchange *pr )
378
{
379
/*
380
    U32 trd=1;
381
 
382
    U32 check_size=SizeBlockOfBytes/4096;
383
    U32 check_ctrl= (pr->DataFix<<7) | (pr->DataType<<8);
384
 
385
    pBrd->RegPokeInd( trd, 0x0F, 1 );
386
 
387
    pBrd->RegPokeInd( trd, 0x1C, 1 ); // Reset
388
    Sleep( 10 );
389
    pBrd->RegPokeInd( trd, 0x1C, 0 );
390
    Sleep( 10 );
391
    pBrd->RegPokeInd( trd, 0x1D, check_size );
392
    pBrd->RegPokeInd( trd, 0x1C, check_ctrl | 0x20 );
393
*/
394
 
395
}
396
 
397
 
398
 
399
//! Остановка проверки в тетраде TestCtrl
400
void WB_TestStrmOut::TestCtrlStop( ParamExchange *pr )
401
{
402
/*
403
    U32 trd=1;
404
 
405
    U32 check_ctrl= (pr->DataFix<<7) | (pr->DataType<<8);
406
 
407
    pBrd->RegPokeInd( trd, 0x1C, check_ctrl ); // Останов
408
*/
409
}
410
 
411
//! Чтение текущего состояния тетрады TestCtrl
412
void WB_TestStrmOut::TestCtrlReadStatus( ParamExchange *pr )
413
{
414
/*
415
    U32 trd=1;
416
    U32 block_rd, block_ok, block_error, total_error;
417
 
418
    U32 reg_l, reg_h;
419
 
420
    reg_l = pBrd->RegPeekInd( trd, 0x210 );
421
    reg_h = pBrd->RegPeekInd( trd, 0x211 );
422
    block_rd = (reg_l&0xFFFF) | (reg_h<<16);
423
 
424
    reg_l = pBrd->RegPeekInd( trd, 0x212 );
425
    reg_h = pBrd->RegPeekInd( trd, 0x213 );
426
    block_ok = (reg_l&0xFFFF) | (reg_h<<16);
427
 
428
    reg_l = pBrd->RegPeekInd( trd, 0x214 );
429
    reg_h = pBrd->RegPeekInd( trd, 0x215 );
430
    block_error = (reg_l&0xFFFF) | (reg_h<<16);
431
 
432
    reg_l = pBrd->RegPeekInd( trd, 0x216 );
433
    reg_h = pBrd->RegPeekInd( trd, 0x217 );
434
    total_error = (reg_l&0xFFFF) | (reg_h<<16);
435
 
436
    pr->BlockRd=block_rd;
437
    pr->BlockOk=block_ok;
438
    pr->BlockError=block_error;
439
    pr->TotalError=total_error;
440
 
441
*/
442
 
443
}
444
 
445
 
446
//! Получение результата в тетраде TestCtrl
447
void WB_TestStrmOut::TestCtrlResult( ParamExchange *pr )
448
{
449
/*
450
    U32 trd=1;
451
    U32 block_rd, block_ok, block_error, total_error;
452
 
453
    U32 reg_l, reg_h;
454
 
455
    reg_l = pBrd->RegPeekInd( trd, 0x210 );
456
    reg_h = pBrd->RegPeekInd( trd, 0x211 );
457
    block_rd = (reg_l&0xFFFF) | (reg_h<<16);
458
 
459
    reg_l = pBrd->RegPeekInd( trd, 0x212 );
460
    reg_h = pBrd->RegPeekInd( trd, 0x213 );
461
    block_ok = (reg_l&0xFFFF) | (reg_h<<16);
462
 
463
    reg_l = pBrd->RegPeekInd( trd, 0x214 );
464
    reg_h = pBrd->RegPeekInd( trd, 0x215 );
465
    block_error = (reg_l&0xFFFF) | (reg_h<<16);
466
 
467
    reg_l = pBrd->RegPeekInd( trd, 0x216 );
468
    reg_h = pBrd->RegPeekInd( trd, 0x217 );
469
    total_error = (reg_l&0xFFFF) | (reg_h<<16);
470
 
471
    pr->BlockRd=block_rd;
472
    pr->BlockOk=block_ok;
473
    pr->BlockError=block_error;
474
    pr->TotalError=total_error;
475
 
476
    BRDC_fprintf( stderr, "\n Число принятых   блоков: %d \n",  block_rd );
477
    BRDC_fprintf( stderr, " Число правильных блоков: %d \n", block_ok );
478
    BRDC_fprintf( stderr, " Число ошибочных  блоков: %d \n", block_error );
479
    BRDC_fprintf( stderr, " Общее число ошибок:      %d \n\n", total_error );
480
 
481
    if( total_error>0 )
482
    {
483
        BRDC_fprintf( stderr, " Список ошибок:\n" );
484
        int cnt=total_error;
485
        if( cnt>16 )
486
            cnt=16;
487
 
488
        int ii;
489
        U32 block, adr, _adr;
490
        __int64 data_ex, data_in;
491
        __int64 r0, r1, r2, r3;
492
 
493
        BRDC_fprintf( stderr, "%5s %10s %10s %20s %20s   \n", "N", "Блок", "Адрес", "Ожидается", "Принято" );
494
        for( ii=0; ii<cnt; ii++ )
495
        {
496
            adr=(ii<<4) + 0; pBrd->RegPokeInd( trd, 0x218, adr ); r0 = pBrd->RegPeekInd( trd, 0x219 );
497
            adr=(ii<<4) + 1; pBrd->RegPokeInd( trd, 0x218, adr ); r1 = pBrd->RegPeekInd( trd, 0x219 );
498
            adr=(ii<<4) + 2; pBrd->RegPokeInd( trd, 0x218, adr ); r2 = pBrd->RegPeekInd( trd, 0x219 );
499
            adr=(ii<<4) + 3; pBrd->RegPokeInd( trd, 0x218, adr ); r3 = pBrd->RegPeekInd( trd, 0x219 );
500
            data_in = ((r3&0xFFFF)<<48) | ((r2&0xFFFF)<<32) | ((r1&0xFFFF)<<16) | (r0&0xFFFF);
501
 
502
            adr=(ii<<4) + 4; pBrd->RegPokeInd( trd, 0x218, adr ); r0 = pBrd->RegPeekInd( trd, 0x219 );
503
            adr=(ii<<4) + 5; pBrd->RegPokeInd( trd, 0x218, adr ); r1 = pBrd->RegPeekInd( trd, 0x219 );
504
            adr=(ii<<4) + 6; pBrd->RegPokeInd( trd, 0x218, adr ); r2 = pBrd->RegPeekInd( trd, 0x219 );
505
            adr=(ii<<4) + 7; pBrd->RegPokeInd( trd, 0x218, adr ); r3 = pBrd->RegPeekInd( trd, 0x219 );
506
            data_ex = ((r3&0xFFFF)<<48) | ((r2&0xFFFF)<<32) | ((r1&0xFFFF)<<16) | (r0&0xFFFF);
507
 
508
            adr=(ii<<4) + 8; pBrd->RegPokeInd( trd, 0x218, adr ); r0 = pBrd->RegPeekInd( trd, 0x219 );
509
            adr=(ii<<4) + 9; pBrd->RegPokeInd( trd, 0x218, adr ); r1 = pBrd->RegPeekInd( trd, 0x219 );
510
            _adr = ((r1&0xFFFF)<<16) | (r0&0xFFFF);
511
 
512
            adr=(ii<<4) + 10; pBrd->RegPokeInd( trd, 0x218, adr ); r0 = pBrd->RegPeekInd( trd, 0x219 );
513
            adr=(ii<<4) + 11; pBrd->RegPokeInd( trd, 0x218, adr ); r1 = pBrd->RegPeekInd( trd, 0x219 );
514
            block = ((r1&0xFFFF)<<16) | (r0&0xFFFF);
515
 
516
            //BRDC_fprintf( stderr, "%5d %10d %10d     %.16ll64X     %.16ll64X \n", ii, block, _adr, data_ex, data_in );
517
            BRDC_fprintf( stderr, "%5d %10d %10d     %.llX     %.llX \n", ii, block, _adr, (long long)data_ex, (long long)data_in );
518
        }
519
 
520
        BRDC_fprintf( stderr, "\n" );
521
    }
522
 
523
*/
524
 
525
}
526
 
527
static U32 fa_data[4096];
528
 
529
//! Заполнение блока синусом
530
void WB_TestStrmOut::SetSignalInit( void )
531
{
532
    int ii;
533
    float v, arg;
534
    int   d;
535
    for( ii=0; ii<4096; ii++ )
536
    {
537
        arg=2*M_PI*ii/4096;
538
        v=10000*sin( arg );
539
        d=v;
540
        fa_data[ii]=d;
541
    }
542
 
543
    fa_cnt_re=0;
544
    fa_cnt_im=0x40000000;
545
    fa_inc_re=0x1000000;
546
    fa_inc_im=fa_inc_re;
547
 
548
}
549
 
550
 
551
//! Заполнение блока синусом
552
void WB_TestStrmOut::SetSignal( U32* ptr )
553
{
554
    int re, im;
555
    unsigned ii;
556
    int adr_re;
557
    int adr_im;
558
    U32 data;
559
    U32 *dst=ptr;
560
 
561
    fa_cnt_re=0;
562
    fa_cnt_im=0x40000000;
563
    fa_inc_re=0x4000000;
564
    fa_inc_im=fa_inc_re;
565
 
566
    U32 d=0x4000000/(SizeBlockOfWords/2);
567
 
568
    for( ii=0; ii<(SizeBlockOfWords); ii++ )
569
    {
570
        adr_re=(fa_cnt_re>>20) & 0x0FFF;
571
        adr_im=(fa_cnt_im>>20) & 0x0FFF;
572
        re=fa_data[adr_re];
573
        im=fa_data[adr_im];
574
        data = (im<<16) | (re&0xFFFF);
575
        *dst++=data;
576
 
577
        fa_cnt_re+=fa_inc_re;
578
        fa_cnt_im+=fa_inc_im;
579
 
580
        fa_inc_re-=d;
581
        fa_inc_im=fa_inc_re;
582
    }
583
 
584
 
585
}

powered by: WebSVN 2.1.0

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