diff --git a/Pcie40Applications/main_pcie40_ul.cpp b/Pcie40Applications/main_pcie40_ul.cpp index f4198b10384ffc0f59884ce487d98ab6c4216160..e097330e34723772772b95703294c13cb27d917f 100644 --- a/Pcie40Applications/main_pcie40_ul.cpp +++ b/Pcie40Applications/main_pcie40_ul.cpp @@ -111,11 +111,11 @@ int crc_calc_event( unsigned int* data, int start_pos ){ printf("End\n"); #endif int bad = 0; - // printf("good flag %d\n", good_flag); fflush(stdout); while( offset + 4 < size ){ // 4 = ROB trailer size cur_pos = start_pos + offset; - int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ; if ( 0 >= size_link || size_link > 10000000 ){ + int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ; + if ( 0 >= size_link || size_link > 10000000 ){ printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num); return -1 ; // it could be that the memory was read } @@ -152,16 +152,14 @@ int crc_calc_event( unsigned int* data, int start_pos ){ }else{ good_flag = 1; - // printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] ); - - + // printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", + // link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, size, size_link, data[ (cur_pos+1) % DMASIZE ] ); } link_num++; offset += size_link; } - if( bad ){ // if( evenum > 50000 ){ // if( 1 ){ @@ -176,54 +174,6 @@ int crc_calc_event( unsigned int* data, int start_pos ){ } - int decode_data_wUL( unsigned int * data , unsigned int * ce , int * crc , int * run , - int * bad , int *evn , int * retry , int * pctime , int * putime , - int * nmissed ) { - - int magic; - int size, size_link; - int ix ; - - int offset; - unsigned int exp_run, evenum, ctime, utime; - int start_pos = *ce; - int cnt = 0; - int cur_pos = *ce + 1; - int ret = 0; - - while( !( ( ( magic = data[ cur_pos % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 ) ){ - usleep(1000); - cnt++; - // - // Scan to find x"7f7f...." - // - if( cnt > 10 ){ - cnt = 0; - int j = 0 ; - for ( j = 0 ; j < DMASIZE ; ++j ) { - if ( ( ( data[ ( cur_pos + j ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ) ){ - evenum = data[ ( cur_pos + j + 2 ) % DMASIZE ]; - if( evenum > *evn ){ - *evn = evenum; - cur_pos = ( cur_pos + j - 1 + DMASIZE ) % DMASIZE; - size = data[ cur_pos ] ; - *ce = ( cur_pos + size ) % DMASIZE; - printf( "New Event number prev %d new %d pos %d size %d\n" , *evn , evenum, cur_pos, size ); - crc_calc_event( data, cur_pos ); - - }else{ - printf( "Old Event number prev %d new %d pos %d\n" , *evn , evenum, ( cur_pos + j - 1 + DMASIZE ) % DMASIZE ); - break; - } - }else{ - continue; - } - } - } - } - - return size ; - } int main (int argc ,char** argv) { // Stop trigger @@ -307,7 +257,6 @@ int crc_calc_event( unsigned int* data, int start_pos ){ unsigned int cur_eve = 0, next_eve = 0; int mod_pos = 0; - int while_cnt = 0; // if ( ( nEvt % 1000 == 1 ) && ( size != 0 ) ) printf( "Event number %d\n", nEvt ) ; // @@ -333,31 +282,9 @@ int crc_calc_event( unsigned int* data, int start_pos ){ // while( 1 ){ while( 1 ){ - if( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) == 0x7f7f0000 ) - && ( data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] == 0x7fff0006 ) - // && ( ( data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ] & 0x0000ffff ) - // == ( data[ ( cur_pos + 3 ) % DMASIZE ] & 0x0000ffff ) ) - ){ - if( while_cnt % 1000 == 0 ){ - // printf("GOT %.8x %.8x %.8x %.8x\n", - // data[ ( cur_pos + 1 ) % DMASIZE ], - // data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ], - // data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ], - // data[ ( cur_pos + 3 ) % DMASIZE ] - // ); - } - while_cnt++; + if( !( ( ( ( magic = data[ ( cur_pos + 1 ) % DMASIZE ] ) & 0xffff0000 ) != 0x7f7f0000 ) + || data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ) ){ break; - }else{ - if( ( data[ ( cur_pos + 1 ) % DMASIZE ] & 0xffff0000 ) == 0x7f7f0000 ){ - // printf("magic hdr %.8x trl %.8x eve hdr %.8x trl %8.x cnt %d\n", - // data[ ( cur_pos + 1 ) % DMASIZE ], - // data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ], - // data[ ( cur_pos + 3 ) % DMASIZE ], - // data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 4 + DMASIZE ) % DMASIZE ], - // eve_cnt - // ); - } } // printf("MAGIC %.8x\n", magic); @@ -367,9 +294,6 @@ int crc_calc_event( unsigned int* data, int start_pos ){ // Refresh DMA memory // res = pcie40_b2dmapointerread( 0 , &data ) ; - - - int wait_flag = 0; // // Scan to find x"7f7f...." @@ -377,9 +301,7 @@ int crc_calc_event( unsigned int* data, int start_pos ){ if( cnt > 100 ){ cnt = 0; int j = 0 ; - for ( j = 0 ; j < DMASIZE ; ++j ) { - #ifdef DEBUG printf("%.8x %d\n", data[ ( cur_pos + j + 1 ) % DMASIZE ], cur_pos + j ); #endif @@ -387,19 +309,21 @@ int crc_calc_event( unsigned int* data, int start_pos ){ next_eve = data[ ( cur_pos + j + 3 ) % DMASIZE ]; next_exp_run = data[ ( cur_pos + j + 2 ) % DMASIZE ] ; - // printf( "TRAILER %.8x %.8x %.8x\n",data[ ( cur_pos + j + data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ] ); + printf( "7f7f is found. TRAILER %.8x eve %.8x exprun %.8x pos %d\n", + data[ ( cur_pos + j + data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] - 1 + DMASIZE ) % DMASIZE ], + next_eve, next_exp_run, ( cur_pos + j + 1 ) % DMASIZE ); - if( next_eve > cur_eve || next_exp_run > cur_exp_run ){ + if( next_eve > cur_eve && next_exp_run >= cur_exp_run ){ /* if( data[ ( ( data[ ( cur_pos + j + DMASIZE ) % DMASIZE ] ) - 1 + DMASIZE ) % DMASIZE ] != 0x7fff0006 ){ */ /* usleep(1000); */ /* break; */ /* } */ cur_pos = ( cur_pos + j + DMASIZE ) % DMASIZE; size = data[ cur_pos ]; - // printf( "Detect new Event number prev %.8x new %.8x pos %.8x size %.8x cnt %d\n" , cur_eve , next_eve, cur_pos, size, eve_cnt ); + // printf( "Detect new Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size ); break; }else{ - // printf( "Detect Old Event number prev %.8x new %.8x pos %d cnt %d\n" , cur_eve , next_eve, ( cur_pos + j + DMASIZE ) % DMASIZE, eve_cnt ); + // printf( "Detect Old Event number prev %.8x new %.8x pos %d\n" , cur_eve , next_eve, ( cur_pos + j + DMASIZE ) % DMASIZE ); break; } }else{ @@ -407,7 +331,6 @@ int crc_calc_event( unsigned int* data, int start_pos ){ } } } - // printf("Scanning... cnt=%d\n", cnt ); cnt++; } size = data[ cur_pos ] ; @@ -423,20 +346,17 @@ int crc_calc_event( unsigned int* data, int start_pos ){ } eve_cnt++; ret = crc_calc_event( data, cur_pos ); - if( ret != 1 ){ crc_err_eve_cnt++; } - if(ret != 1 || eve_cnt % 1000 == 0 ){ - printf( "[INFO] Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size ); - fflush(stdout); + if(ret != 1 || eve_cnt % 100 == 0 ){ + printf( "Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size ); } cur_eve = next_eve; cur_exp_run = next_exp_run; - if(ret != 1 || eve_cnt % 1000 == 0 ){ - printf("[INFO] STATUS : tot eve %d read eve %d err_eve %d run %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run ); - fflush(stdout); + if(ret != 1 || eve_cnt % 100 == 0 ){ + printf("STATUS : tot eve %d read eve %d err_eve %d run %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run ); } mod_pos = ( cur_pos + size ) % 8; if( mod_pos != 0 ){