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/] [adm_test/] [src/] [work/] [tf_teststrm.cpp] - Blame information for rev 27

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

Line No. Rev Author Line
1 2 dsmv
 
2
 
3
#include <stdio.h>
4
#include <fcntl.h>
5
#include <pthread.h>
6
#include <unistd.h>
7 6 v.karak
#include <math.h>
8 2 dsmv
#include <sys/types.h>
9
#include <sys/stat.h>
10
#include <pthread.h>
11
#include "utypes.h"
12
#include "tf_teststrm.h"
13
#include "cl_ambpex.h"
14 27 dsmv
#include "sys/time.h"
15 2 dsmv
 
16
#define BUFSIZEPKG 62
17
 
18
#define TRDIND_MODE0                                    0x0
19
#define TRDIND_MODE1                                    0x9
20
#define TRDIND_MODE2                                    0xA
21
#define TRDIND_SPD_CTRL                                 0x204
22
#define TRDIND_SPD_ADDR                                 0x205
23
#define TRDIND_SPD_DATA                                 0x206
24
 
25
#define TRDIND_TESTSEQ                                  0x0C
26 6 v.karak
#define TRDIND_CHAN                                     0x10
27
#define TRDIND_FSRC                                     0x13
28
#define TRDIND_GAIN                                     0x15
29 2 dsmv
#define TRDIND_CONTROL1                                 0x17
30
#define TRDIND_DELAY_CTRL                               0x1F
31
 
32 6 v.karak
//-----------------------------------------------------------------------------
33
 
34 27 dsmv
long GetTickCount(void)
35 2 dsmv
{
36 27 dsmv
 //   return time( NULL);
37
    struct timeval tv;
38
    struct timezone tz;
39
    gettimeofday(&tv, &tz);
40
    long ret=tv.tv_sec*1000 + tv.tv_usec/1000;
41
    return ret;
42 2 dsmv
}
43
 
44 6 v.karak
//-----------------------------------------------------------------------------
45
 
46 2 dsmv
TF_TestStrm::TF_TestStrm( char* fname,  CL_AMBPEX *pex )
47
{
48
    lc_status=0;
49
 
50
    Terminate=0;
51
    BlockRd=0;
52
    BlockOk=0;
53
    BlockError=0;
54
    TotalError=0;
55
 
56
    pBrd=pex;
57
    bufIsvi=NULL;
58
 
59
    SetDefault();
60
    GetParamFromFile( fname );
61
    CalculateParams();
62
 
63
    isFirstCallStep=true;
64
}
65
 
66 6 v.karak
//-----------------------------------------------------------------------------
67
 
68 2 dsmv
TF_TestStrm::~TF_TestStrm()
69
{
70
    pBrd->StreamDestroy( rd0.Strm );
71 6 v.karak
    delete bufIsvi;
72
    bufIsvi=NULL;
73 2 dsmv
}
74
 
75 6 v.karak
//-----------------------------------------------------------------------------
76
 
77 2 dsmv
void TF_TestStrm::Prepare( void )
78
{
79
    PrepareAdm();
80
 
81
    rd0.trd=trdNo;
82
    rd0.Strm=strmNo;
83
    pBrd->StreamInit( rd0.Strm, CntBuffer, SizeBuferOfBytes, rd0.trd, 1, isCycle, isSystem, isAgreeMode );
84
 
85
    bufIsvi = new U32[SizeBlockOfWords*2];
86
}
87
 
88 6 v.karak
//-----------------------------------------------------------------------------
89
 
90 2 dsmv
void TF_TestStrm::Start( void )
91
{
92
    int res = pthread_attr_init(&attrThread_);
93
    if(res != 0) {
94
        fprintf(stderr, "%s\n", "Stream not started");
95
        return;
96
    }
97
 
98
    res = pthread_attr_setdetachstate(&attrThread_, PTHREAD_CREATE_JOINABLE);
99
    if(res != 0) {
100
        fprintf(stderr, "%s\n", "Stream not started");
101
        return;
102
    }
103
 
104
    res = pthread_create(&hThread, &attrThread_, ThreadFunc, this);
105
    if(res != 0) {
106
        fprintf(stderr, "%s\n", "Stream not started");
107
        return;
108
    }
109
 
110
    res = pthread_attr_init(&attrThreadIsvi_);
111
    if(res != 0) {
112
        fprintf(stderr, "%s\n", "Stream not started");
113
        return;
114
    }
115
 
116
    res = pthread_attr_setdetachstate(&attrThreadIsvi_, PTHREAD_CREATE_JOINABLE);
117
    if(res != 0) {
118
        fprintf(stderr, "%s\n", "Stream not started");
119
        return;
120
    }
121
 
122
    res = pthread_create(&hThreadIsvi, &attrThreadIsvi_, ThreadFuncIsvi, this);
123
    if(res != 0) {
124
        fprintf(stderr, "%s\n", "Stream not started");
125
        return;
126
    }
127
}
128
 
129 6 v.karak
//-----------------------------------------------------------------------------
130
 
131 2 dsmv
void TF_TestStrm::Stop( void )
132
{
133
    Terminate=1;
134
    lc_status=3;
135 6 v.karak
    //BRDC_fprintf( stderr, "TF_TestStrm::Stop(): lc_status = %d\n", lc_status );
136 2 dsmv
}
137
 
138 6 v.karak
//-----------------------------------------------------------------------------
139
 
140 2 dsmv
void TF_TestStrm::Step( void )
141
{
142 6 v.karak
    rd0.testBuf.check_result( &rd0.BlockOk , &rd0.BlockError, NULL, NULL, NULL );
143 2 dsmv
 
144 6 v.karak
    U32 status = pBrd->RegPeekDir( rd0.trd, 0 ) & 0xFFFF;
145 2 dsmv
 
146 6 v.karak
    U32 cnt_rd=rd0.BlockRd;
147 2 dsmv
 
148 27 dsmv
    long currentTime = GetTickCount();
149
    int min, sec_all, sec;
150
    sec_all= currentTime-rd0.time_start;
151
    sec_all/=1000;
152
    sec=sec_all%60;
153
    min=sec_all/60;
154 2 dsmv
 
155 27 dsmv
 
156
 
157
 
158
    BRDC_fprintf( stderr, "%6s %3d %10d %10d %10d %10d  %9.1f %10.1f     0x%.4X       %u:%.2u \r", "TRD :", rd0.trd, rd0.BlockWr, cnt_rd, rd0.BlockOk, rd0.BlockError, rd0.VelocityCurrent, rd0.VelocityAvarage, status, min, sec );
159
 
160 6 v.karak
    if( isSystemMonitor )
161
    {
162
        unsigned temp;
163
        float ty;
164
        pBrd->RegPokeInd( 0, 0x210, 0 );
165
        temp = pBrd->RegPeekInd( 0, 0x211 );
166 2 dsmv
 
167 6 v.karak
        temp >>=6;
168
        temp &= 0x3FF;
169
        ty = (temp*503.975)/1024-273.15;
170 2 dsmv
 
171 6 v.karak
        BRDC_fprintf( stderr, "%6s %3d %10.1f\n", "SYSMON", 0, ty  );
172 2 dsmv
 
173 6 v.karak
    }
174 2 dsmv
}
175
 
176 6 v.karak
//-----------------------------------------------------------------------------
177
 
178 2 dsmv
int TF_TestStrm::isComplete( void )
179
{
180
    if( (lc_status==4) && (IsviStatus==100) )
181
        return 1;
182
    return 0;
183
}
184
 
185 6 v.karak
//-----------------------------------------------------------------------------
186
 
187 2 dsmv
void TF_TestStrm::GetResult( void )
188
{
189 6 v.karak
    BRDC_fprintf( stderr, "\n\nResult of receiving data from trd %d \n", trdNo );
190 2 dsmv
 
191 27 dsmv
    BRDC_fprintf( stderr, "\n Recieved blocks :   %d \n",  rd0.BlockRd );
192
    BRDC_fprintf( stderr,   " Correct blocks  :   %d \n",  rd0.BlockOk );
193
    BRDC_fprintf( stderr,   " Incorrect blocks:   %d \n",  rd0.BlockError );
194
    BRDC_fprintf( stderr,   " Total errors    :   %d \n\n", rd0.TotalError );
195
    BRDC_fprintf( stderr,   " Speed           :   %.1f [Mbytes/s] \n", rd0.VelocityAvarage );
196
 
197
    long currentTime = GetTickCount();
198
    int min, sec_all, sec;
199
    sec_all= currentTime-rd0.time_start;
200
    sec_all/=1000;
201
    sec=sec_all%60;
202
    min=sec_all/60;
203
 
204
    BRDC_fprintf( stderr,   " Time of test    :   %d min %.2d sec\n\n", min, sec );
205
 
206
 
207
    if(rd0.BlockRd!=0 && rd0.BlockError==0)
208
    {
209
        BRDC_fprintf( stderr,"All data is correct. No error\n" );
210
    } else if( rd0.BlockRd==0 )
211
    {
212
        BRDC_fprintf( stderr,"Error - data is not received \n" );
213
 
214
    } else
215
    {
216
        BRDC_fprintf( stderr,"List of error:\n" );
217
        BRDC_fprintf( stderr,"%s\n", rd0.testBuf.report_word_error());
218
    }
219
 
220 2 dsmv
    BRDC_fprintf( stderr, "\n\n" );
221
}
222
 
223 6 v.karak
//-----------------------------------------------------------------------------
224
 
225 2 dsmv
void* TF_TestStrm::ThreadFunc( void* lpvThreadParm )
226
{
227
    TF_TestStrm *test=(TF_TestStrm*)lpvThreadParm;
228
    UINT ret;
229
    if( !test )
230
        return 0;
231
    ret=test->Execute();
232
    return (void*)ret;
233
}
234
 
235 6 v.karak
//-----------------------------------------------------------------------------
236
 
237 2 dsmv
void* TF_TestStrm::ThreadFuncIsvi( void* lpvThreadParm )
238
{
239
    TF_TestStrm *test=(TF_TestStrm*)lpvThreadParm;
240
    UINT ret;
241
    if( !test )
242
        return 0;
243
 
244
    Sleep( 200 );
245
    ret=test->ExecuteIsvi();
246
    return (void*)ret;
247
}
248
 
249 6 v.karak
//-----------------------------------------------------------------------------
250
 
251 2 dsmv
//! Установка параметров по умолчанию
252
void TF_TestStrm::SetDefault( void )
253
{
254
    int ii=0;
255
 
256 6 v.karak
    array_cfg[ii++]=STR_CFG(  0, "CntBuffer",            "16", (U32*)&CntBuffer, "Stream buffers number" );
257 23 v.karak
    array_cfg[ii++]=STR_CFG(  0, "CntBlockInBuffer",     "1",  (U32*)&CntBlockInBuffer, "Blocks in buffer" );
258
    array_cfg[ii++]=STR_CFG(  0, "SizeBlockOfWords",     "262144",  (U32*)&SizeBlockOfWords, "Block size (in words)" );
259 6 v.karak
    array_cfg[ii++]=STR_CFG(  0, "isCycle",              "1",  (U32*)&isCycle, "1 - Stream working in cycle mode" );
260
    array_cfg[ii++]=STR_CFG(  0, "isSystem",             "1",  (U32*)&isSystem, "1 - system memory allocation" );
261
    array_cfg[ii++]=STR_CFG(  0, "isAgreeMode",          "0",  (U32*)&isAgreeMode, "1 - adjust mode" );
262
    array_cfg[ii++]=STR_CFG(  0, "isRestart",            "0",  (U32*)&isRestart, "1 - Перезапуск АЦП" );
263 2 dsmv
 
264
    array_cfg[ii++]=STR_CFG(  0, "trdNo",        "4",  (U32*)&trdNo, "Номер тетрады" );
265
    array_cfg[ii++]=STR_CFG(  0, "strmNo",       "0",  (U32*)&strmNo, "Номер стрма" );
266
    array_cfg[ii++]=STR_CFG(  0, "isTest",       "0",  (U32*)&isTest, "0 - нет, 1 - проверка псевдослучайной последовательности, 2 - проверка тестовой последовательности" );
267
    array_cfg[ii++]=STR_CFG(  0, "isMainTest",   "0",  (U32*)&isMainTest, "1 - включение режима тестирования в тетраде MAIN" );
268
 
269
    fnameAdmReg=NULL;
270 6 v.karak
    array_cfg[ii++]=STR_CFG(  2, "AdmReg",      "adcreg.ini",  (U32*)&fnameAdmReg, "имя файла регистров" );
271 2 dsmv
 
272
    array_cfg[ii++]=STR_CFG(  0, "isAdmReg",     "0",  (U32*)&isAdmReg, "1 - разрешение записи регистров из файла AdmReg" );
273
 
274
    fnameAdmReg2=NULL;
275 6 v.karak
    array_cfg[ii++]=STR_CFG(  2, "AdmReg2",     "adcreg2.ini",  (U32*)&fnameAdmReg2, "имя файла регистров (выполняется после старта стрима)" );
276 2 dsmv
 
277
    array_cfg[ii++]=STR_CFG(  0, "isAdmReg2",    "0",  (U32*)&isAdmReg2, "1 - разрешение записи регистров из файла AdmReg2" );
278
 
279
    fnameIsvi=NULL;
280
    array_cfg[ii++]=STR_CFG(  2, "ISVI_FILE",   "",  (U32*)&fnameIsvi, "имя файла данных ISVI" );
281
 
282
    array_cfg[ii++]=STR_CFG(  0, "ISVI_HEADER",  "0",  (U32*)&IsviHeaderMode, "режим формирования суффикса ISVI, 0 - нет, 1 - DDC, 2 - ADC" );
283
 
284 6 v.karak
    array_cfg[ii++]=STR_CFG(  0, "FifoRdy",      "0",  (U32*)&isFifoRdy, "1 - генератор тестовой последовательности анализирует флаг готовности FIFO" );
285 2 dsmv
 
286
    array_cfg[ii++]=STR_CFG(  0, "Cnt1", "0",  (U32*)&Cnt1, "Число тактов записи в FIFO, 0 - постоянная запись в FIFO" );
287
 
288
    array_cfg[ii++]=STR_CFG(  0, "Cnt2", "0",  (U32*)&Cnt2, "Число тактов паузы при записи в FIFO" );
289
 
290
    array_cfg[ii++]=STR_CFG(  0, "DataType",     "0",  (U32*)&DataType, "Тип данных при фиксированном типе блока, 6 - счётчик, 8 - псевдослучайная последовательность" );
291
 
292
    array_cfg[ii++]=STR_CFG(  0, "DataFix",      "0",  (U32*)&DataFix, "1 - фиксированный тип блока, 0 - данные в блоке записят от номера блока" );
293
 
294
    array_cfg[ii++]=STR_CFG(  0, "isTestCtrl",   "0",  (U32*)&isTestCtrl, "1 - подготовка тетрады TEST_CTRL" );
295
 
296 6 v.karak
    array_cfg[ii++]=STR_CFG(  0, "TestSeq",      "0",  (U32*)&TestSeq, "Значение регистра TEST_SEQ" );
297 2 dsmv
 
298
    max_item=ii;
299
 
300
    {
301 6 v.karak
        char str[1024];
302 2 dsmv
        for( unsigned ii=0; ii<max_item; ii++ )
303 6 v.karak
        {
304 2 dsmv
            sprintf( str, "%s  %s", array_cfg[ii].name, array_cfg[ii].def );
305
            GetParamFromStr( str );
306 6 v.karak
        }
307 2 dsmv
    }
308
}
309
 
310 6 v.karak
//-----------------------------------------------------------------------------
311
 
312 2 dsmv
//! Расчёт параметров
313
void TF_TestStrm::CalculateParams( void )
314
{
315
    SizeBlockOfBytes = SizeBlockOfWords * 4;                                            // Размер блока в байтах
316
    SizeBuferOfBytes    = CntBlockInBuffer * SizeBlockOfBytes  ;        // Размер буфера в байтах
317
    SizeStreamOfBytes   = CntBuffer * SizeBuferOfBytes;                         // Общий размер буфера стрима
318
 
319
    ShowParam();
320
}
321
 
322 6 v.karak
//-----------------------------------------------------------------------------
323
 
324 2 dsmv
//! Отображение параметров
325
void TF_TestStrm::ShowParam( void )
326
{
327
    TF_WorkParam::ShowParam();
328
 
329
    BRDC_fprintf( stderr, "Total stream buffer size: %d MB\n\n", SizeStreamOfBytes/(1024*1024) );
330
}
331
 
332 6 v.karak
//-----------------------------------------------------------------------------
333 2 dsmv
 
334
U32 TF_TestStrm::Execute( void )
335
{
336
    rd0.testBuf.buf_check_start( 32, 64 );
337
 
338
    pBrd->RegPokeInd( rd0.trd, 0, 0x2010 );
339
    pBrd->StreamStart( rd0.Strm );
340
    pBrd->RegPokeInd( rd0.trd, 0, 0x2038 );
341
    if( isTestCtrl )
342
    {
343
        StartTestCtrl();
344
    }
345
 
346 6 v.karak
    if( isAdmReg2 ) {
347 2 dsmv
        PrepareAdmReg( fnameAdmReg2 );
348 6 v.karak
    }
349 2 dsmv
 
350
 
351
    rd0.time_last=rd0.time_start=GetTickCount();
352
 
353 27 dsmv
    isDmaStart=1;
354 2 dsmv
 
355
    for( ; ; )
356
    {
357
        if( Terminate )
358
        {
359
            break;
360
        }
361
 
362
        ReceiveData( &rd0 );
363
    }
364 6 v.karak
 
365 2 dsmv
    pBrd->RegPokeInd( rd0.trd, 0, 2 );
366
    Sleep( 200 );
367
 
368
    pBrd->StreamStop( rd0.Strm );
369
    Sleep( 10 );
370
 
371
    lc_status=4;
372 6 v.karak
 
373
    //BRDC_fprintf( stderr, "TF_TestStrm::Execute(): lc_status = %d\n", lc_status );
374
 
375 2 dsmv
    return 1;
376
}
377
 
378 6 v.karak
//-----------------------------------------------------------------------------
379 2 dsmv
 
380
void TF_TestStrm::ReceiveData(  ParamExchange *pr )
381
{
382
    U32 *ptr;
383
    U32 *ptrBlock;
384
    U32 mode=0;
385
    mode |= pr->DataType<<8;
386
    mode |= pr->DataFix<<7;
387
 
388
    int ret;
389
    int kk;
390
 
391
    for( kk=0; kk<16; kk++ )
392
    {
393
        ret=pBrd->StreamGetBuf( pr->Strm, &ptr );
394
        if( ret )
395
        { // Проверка буфера стрима
396
 
397 6 v.karak
            for( unsigned ii=0; ii<CntBlockInBuffer; ii++ )
398
            {
399
                ptrBlock=ptr+ii*SizeBlockOfWords;
400
                if( isIsvi )
401
                    IsviStep( ptrBlock );
402 2 dsmv
 
403 6 v.karak
                if( 1==isTest )
404
                    pr->testBuf.buf_check_psd( ptrBlock, SizeBlockOfWords );
405
                //int a=0;
406
                else if( 2==isTest )
407
                    pr->testBuf.buf_check( ptrBlock, pr->BlockRd, SizeBlockOfWords, BlockMode );
408
                else if( 4==isTest )
409
                    pr->testBuf.buf_check_inv( ptrBlock, SizeBlockOfWords );
410 2 dsmv
 
411 6 v.karak
                pr->BlockRd++;
412
            }
413
            if( isAgreeMode )
414
            {
415
                pBrd->StreamGetBufDone( pr->Strm );
416
            }
417
            if( (1==isRestart) && (pr->BlockRd==(CntBuffer*CntBlockInBuffer) ) )
418
            {
419
                RestartAdc();
420
            }
421 2 dsmv
 
422 6 v.karak
        } else {
423
 
424 2 dsmv
            pr->freeCycle++;
425
            break;
426
        }
427
    }
428
 
429 27 dsmv
    long currentTime = GetTickCount();
430
    if( (currentTime - pr->time_last)>4000 )
431 2 dsmv
    {
432
        float t1 = currentTime - pr->time_last;
433
        float t2 = currentTime - pr->time_start;
434 27 dsmv
        float v = 1000.0*(pr->BlockRd-pr->BlockLast)*SizeBlockOfBytes/t1;
435 2 dsmv
        v/=1024*1024;
436
        pr->VelocityCurrent=v;
437
 
438 27 dsmv
        v = 1000.0*(pr->BlockRd)*SizeBlockOfBytes/t2;
439 2 dsmv
        v/=1024*1024;
440
        pr->VelocityAvarage=v;
441
        pr->time_last = currentTime;
442
        pr->BlockLast = pr->BlockRd;
443
        pr->freeCycleZ=pr->freeCycle;
444
        pr->freeCycle=0;
445
    }
446 27 dsmv
    //Sleep(1);
447 2 dsmv
}
448
 
449 6 v.karak
//-----------------------------------------------------------------------------
450 2 dsmv
 
451
void TF_TestStrm::PrepareAdm( void )
452
{
453
    U32 trd=trdNo;
454
    U32 id, id_mod, ver;
455
    BRDC_fprintf( stderr, "\nPreparing tetrade\n" );
456
 
457
 
458
    id = pBrd->RegPeekInd( trd, 0x100 );
459
    id_mod = pBrd->RegPeekInd( trd, 0x101 );
460
    ver = pBrd->RegPeekInd( trd, 0x102 );
461
 
462
    BRDC_fprintf( stderr, "\nTetrade %d  ID: 0x%.2X MOD: %d  VER: %d.%d \n\n",
463 6 v.karak
                  trd, id, id_mod, (ver>>8) & 0xFF, ver&0xFF );
464 2 dsmv
 
465
 
466
    if( isMainTest )
467
        PrepareMain();
468
 
469
    BlockMode = DataType <<8;
470
    BlockMode |= DataFix <<7;
471
 
472
    if( isTestCtrl )
473
        PrepareTestCtrl();
474
 
475
    if( isAdmReg )
476
        PrepareAdmReg( fnameAdmReg );
477
 
478
    IsviStatus=0;
479
    IsviCnt=0;
480
    isIsvi=0;
481
    if( fnameIsvi )
482
    {
483
        IsviStatus=1;
484
        isIsvi=1;
485
    }
486
}
487
 
488 6 v.karak
//-----------------------------------------------------------------------------
489 2 dsmv
//! Подготовка MAIN
490
void TF_TestStrm::PrepareMain( void )
491
{
492
 
493
    if( 4==isTest )
494
    {
495 6 v.karak
        BRDC_fprintf( stderr, "In tetrade MAIN set mode of binary-inversion sequence\n" );
496 2 dsmv
    } else
497
    {
498 6 v.karak
        BRDC_fprintf( stderr, "In tetrade MAIN set of pseudo-random mode sequence\n" );
499 2 dsmv
        pBrd->RegPokeInd( 0, 12, 1 );  // Регистр TEST_MODE[0]=1 - режим формирования псевдослучайной последовательности
500
    }
501
    pBrd->RegPokeInd( 0, 0, 2 );   // Сброс FIFO - перевод в начальное состояние
502
    Sleep( 1 );
503
    pBrd->RegPokeInd( 0, 0, 0 );
504
    Sleep( 1 );
505
}
506
 
507 6 v.karak
//-----------------------------------------------------------------------------
508
 
509 2 dsmv
void TF_TestStrm::IsviStep( U32* ptr )
510
{
511
    unsigned ii;
512
    if( (1==IsviStatus) || (4==IsviStatus ) )
513
    {
514
        for( ii=0; ii<SizeBlockOfWords; ii++ ) bufIsvi[ii]=ptr[ii];
515
        IsviStatus++;
516
    }
517
}
518
 
519 6 v.karak
//-----------------------------------------------------------------------------
520
 
521 2 dsmv
void TF_TestStrm::WriteFlagSinc(int flg, int isNewParam)
522
{
523
    int fs = -1;
524
    int val[2];
525
 
526
    char fname[256];
527
    sprintf( fname, "%s.flg", fnameIsvi );
528
 
529
    while( fs==-1 )
530
    {
531
        fs = open( fname, O_RDWR|O_CREAT, 0666 );
532
        Sleep( 10 );
533
    }
534
    val[0] = flg;
535
    val[1] = isNewParam;
536 6 v.karak
    int res = write( fs, val, 8 );
537
    if(res < 0) {
538
        BRDC_fprintf( stderr, "Error write flag sync\r\n" );
539
    }
540 2 dsmv
    close( fs );
541
}
542
 
543 6 v.karak
//-----------------------------------------------------------------------------
544
 
545 2 dsmv
int  TF_TestStrm::ReadFlagSinc(void)
546
{
547
    int fs = -1;
548
    int flg;
549
 
550
    char fname[256];
551
    sprintf( fname, "%s.flg", fnameIsvi );
552
 
553
    while( fs==-1 )
554
    {
555
        fs = open( fname, O_RDWR|O_CREAT, 0666 );
556
        Sleep( 10 );
557
    }
558 6 v.karak
    int res = read( fs, &flg, 4 );
559
    if(res < 0) {
560
        BRDC_fprintf( stderr, "Error read flag sync\r\n" );
561
    }
562 2 dsmv
    close( fs );
563
 
564
    return flg;
565
}
566
 
567 6 v.karak
//-----------------------------------------------------------------------------
568
 
569 2 dsmv
void TF_TestStrm::WriteDataFile( U32 *pBuf, U32 sizew )
570
{
571
    char fname[256];
572
    sprintf( fname, "%s.bin", fnameIsvi );
573
    int     fl = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
574
 
575
    if( fl==-1 )
576
    {
577
        return;
578
    }
579
 
580
 
581 6 v.karak
    int res = write( fl, pBuf, sizew*4 );
582
    if(res < 0) {
583
        BRDC_fprintf( stderr, "Error write ISVI data\r\n" );
584
    }
585 2 dsmv
 
586 6 v.karak
    res = write( fl, IsviHeaderStr, IsviHeaderLen );
587
    if(res < 0) {
588
        BRDC_fprintf( stderr, "Error write ISVI header\r\n" );
589
    }
590 2 dsmv
 
591
    close( fl );
592
}
593
 
594 6 v.karak
//-----------------------------------------------------------------------------
595 2 dsmv
 
596
U32 TF_TestStrm::ExecuteIsvi( void )
597
{
598
    for( ; ; )
599
    {
600
        if( Terminate )
601
        {
602
            break;
603
        }
604
 
605
        int rr;
606
        switch( IsviStatus )
607
        {
608
        case 2: // Подготовка суффикса
609 6 v.karak
        {
610
            IsviHeaderStr[0]=0;
611
            /*
612
                    switch( IsviHeaderMode )
613
                    {
614
                        case 1:  SetFileHeaderDdc( SizeBlockOfWords, IsviHeaderStr ); break;
615
                        case 2:  SetFileHeaderAdc( SizeBlockOfWords, IsviHeaderStr ); break;
616
                    }
617
                    */
618
            IsviHeaderLen = 0; //strlen( IsviHeaderStr );
619
            WriteFlagSinc(0,0);
620
            WriteDataFile( bufIsvi, SizeBlockOfWords );
621
            WriteFlagSinc(0xffffffff,0xffffffff);
622 2 dsmv
 
623 6 v.karak
            IsviCnt++;
624
            IsviStatus=3;
625
        }
626 2 dsmv
            break;
627
 
628
        case 3:
629 6 v.karak
        {
630
            rr=ReadFlagSinc();
631
            if( 0==rr )
632
                IsviStatus=4;
633 2 dsmv
 
634 6 v.karak
        }
635 2 dsmv
            break;
636
 
637
        case 4:
638
            // Ожидание получения данных
639
            Sleep( 100 );
640
            break;
641
 
642
        case 5:
643 6 v.karak
        {
644
            WriteDataFile( bufIsvi, SizeBlockOfWords );
645
            WriteFlagSinc(0xffffffff,0 );
646
            IsviStatus=3;
647
            IsviCnt++;
648
        }
649 2 dsmv
            break;
650
 
651
        }
652
 
653
        Sleep( 100 );
654
    }
655
    IsviStatus=100;
656
    return 0;
657
}
658
 
659 6 v.karak
//-----------------------------------------------------------------------------
660 2 dsmv
 
661
#define TRD_CTRL 1
662
#define REG_MUX_CTRL  0x0F
663
#define REG_GEN_CNT1  0x1A
664
#define REG_GEN_CNT2  0x1B
665
#define REG_GEN_CTRL  0x1E
666
#define REG_GEN_SIZE  0x1F
667
#define TRD_DIO_IN    6
668
#define TRD_CTRL      1
669 6 v.karak
 
670
//-----------------------------------------------------------------------------
671 2 dsmv
//! Подготовка TEST_CTRL
672
void TF_TestStrm::PrepareTestCtrl( void )
673
{
674 27 dsmv
    BRDC_fprintf( stderr, "\nPrepare trd TEST_CTRL\n" );
675 2 dsmv
 
676
    BlockMode = DataType <<8;
677
    BlockMode |= DataFix <<7;
678
 
679
    if( !isFifoRdy )
680
        BlockMode |=0x1000;
681
 
682
    U32 block_mode=BlockMode;
683
 
684
    pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CTRL, 1 );
685
 
686
    //U32 mode0=pBrd->RegPeekInd( TRD_DIO_IN, 0 );
687
    // pBrd->RegPokeInd( TRD_DIO_IN, 0, 2 );
688
 
689
    Sleep( 1 );
690
 
691
    //pBrd->RegPokeInd( TRD_DIO_IN, 0, 0 );
692
 
693
    pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CTRL, 0 );
694
 
695
    pBrd->RegPokeInd( TRD_CTRL, REG_MUX_CTRL, 1 );
696
 
697
    U32  val=SizeBlockOfBytes/4096;
698
 
699
    pBrd->RegPokeInd( TRD_CTRL, REG_GEN_SIZE, val );
700
 
701
    if( block_mode & 0x80 )
702
    {
703 27 dsmv
        BRDC_fprintf( stderr, "Use a short test sequence\r\n" );
704 2 dsmv
    } else
705
    {
706 27 dsmv
        BRDC_fprintf( stderr, "Use a full test sequence\r\n" );
707 2 dsmv
    }
708
 
709
 
710
    if( Cnt1 || Cnt2 )
711
    {
712
        pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CNT1, Cnt1 );
713
        pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CNT2, Cnt2 );
714
        float sp=1907.348632812 * (Cnt1-1)/(Cnt1+Cnt2-2);
715 27 dsmv
        BRDC_fprintf( stderr, "Set limit of speed:  %6.1f Mbytes/s \r\n"
716 6 v.karak
                      "REG_CNT1=%d  REGH_CNT2=%d   \r\n", sp, Cnt1, Cnt2 );
717 2 dsmv
        if( block_mode&0x1000 )
718
        {
719 27 dsmv
            BRDC_fprintf( stderr, "Set mode without wait of FIFO ready\r\n\r\n" );
720 2 dsmv
        } else
721
        {
722 27 dsmv
            BRDC_fprintf( stderr, "Set mode with wait of FIFO ready \r\n\r\n"        );
723 2 dsmv
        }
724
    }  else
725
    {
726
        pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CNT1, 0 );
727
        pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CNT2, 0 );
728 27 dsmv
        BRDC_fprintf( stderr, "Set max speed of data transfer: 1907 Mbytes/s \r\n"
729
                      "Set mode with wait of FIFO ready \r\n\r\n"        );
730 2 dsmv
    }
731
}
732
 
733 6 v.karak
//-----------------------------------------------------------------------------
734 2 dsmv
//! Запуск TestCtrl
735
void TF_TestStrm::StartTestCtrl( void )
736
{
737
 
738
    U32 ctrl=0x20;
739
    ctrl|=BlockMode;
740
    if( Cnt1 || Cnt2 )
741
        ctrl|=0x40;
742
 
743
    if( !isFifoRdy )
744
        ctrl |=0x1000;
745
    //  ctrl&= ~0x1000;
746
    //BRDC_fprintf( stderr, "TEST_CTRL: REG_GEN_CTRL = 0x%.4X \r\n", ctrl );
747
 
748
    pBrd->RegPokeInd( TRD_CTRL, REG_GEN_CTRL, ctrl );  // Запуск DIO_IN
749
 
750
    //U32 mode0=pBrd->RegPeekInd( 6, 0 );
751
    //mode0 |=0x30;
752
    //pBrd->RegPokeInd( 6, 0, mode0 );          // Запуск DIO_IN
753
 
754
 
755
}
756
 
757 6 v.karak
//-----------------------------------------------------------------------------
758 2 dsmv
//! Запись регистров из файла
759
void TF_TestStrm::PrepareAdmReg( char* fname )
760
{
761 6 v.karak
    BRDC_fprintf( stderr, "\nSetting up ADM registers from file: %s\r\n\n", fname );
762 2 dsmv
 
763
    FILE *in = fopen( fname, "rt" );
764
    if( in==NULL )
765
    {
766 6 v.karak
        throw( "Error file access" );
767 2 dsmv
    }
768
 
769
    char str[256];
770
    U32 trd, reg, val;
771
    int ret;
772
    for( ; ; )
773
    {
774
        if( fgets( str, 200, in )==NULL )
775
            break;
776
 
777
        if( str[0]==';' )
778
            continue;
779
 
780
        ret=sscanf( str, "%i %i %i", &trd, &reg, &val );
781
        if( 3==ret )
782
        {
783
            BRDC_fprintf( stderr, "  TRD: %d  REG[0x%.2X]=0x%.4X \n", trd, reg, val );
784
            pBrd->RegPokeInd( trd, reg, val );
785
        }
786
 
787
    }
788
    BRDC_fprintf( stderr, "\n\n" );
789
}
790
 
791 6 v.karak
//-----------------------------------------------------------------------------
792
 
793
void TF_TestStrm::RestartAdc( void )
794
{
795
    pBrd->RegPokeInd( rd0.trd, 0, 2 );
796
    Sleep( 100 );
797
 
798
    pBrd->StreamStop( rd0.Strm );
799
    Sleep( 100 );
800
 
801
    pBrd->RegPokeInd( rd0.trd, 0, 0x2000 );
802
 
803
    pBrd->StreamStart( rd0.Strm );
804
    Sleep( 100 );
805
 
806
    rd0.BlockRd=0;
807
    cntRestart++;
808
 
809
    pBrd->RegPokeInd( rd0.trd, 0, 0x2038 );
810
}
811
 
812
//-----------------------------------------------------------------------------
813
 
814
void TF_TestStrm::RestartDac( void )
815
{
816
    U32 trdDac = 5;
817
 
818
    pBrd->RegPokeInd( trdDac, 0, 2 );
819
    Sleep( 100 );
820
}
821
 
822
//-----------------------------------------------------------------------------
823
 
824
void TF_TestStrm::PrepareDac( void )
825
{
826
    U32 trdDac = 5;
827
 
828
    fprintf(stderr,"%s(): Start DAC\n", __FUNCTION__);
829
    pBrd->RegPokeInd( trdDac, 0x0, 0x0010 );
830
    Sleep( 1 );
831
    pBrd->RegPokeInd( trdDac, 0x0, 0x0030 );
832
}
833
 
834
//-----------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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