Skip to content
Snippets Groups Projects
Commit a4a0f900 authored by Satoru Yamada's avatar Satoru Yamada
Browse files

Updated a data-check program.

parent a591ff2f
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include "altera_dma_regs.h" #include "altera_dma_regs.h"
#include <sys/time.h>
extern "C" int ecs_open(int dev, int bar); extern "C" int ecs_open(int dev, int bar);
extern "C" void ecs_close(int dev, int bar); extern "C" void ecs_close(int dev, int bar);
...@@ -17,6 +18,7 @@ extern "C" int ecs_write(int dev, int bar, unsigned add, int val); ...@@ -17,6 +18,7 @@ extern "C" int ecs_write(int dev, int bar, unsigned add, int val);
#define OLD_RUN 1 #define OLD_RUN 1
#define OLD_EVENT 2 #define OLD_EVENT 2
#define NO_TRAILER 3 #define NO_TRAILER 3
#define PRESCALE 1000
const int CRC16_XMODEM_TABLE[] = { const int CRC16_XMODEM_TABLE[] = {
...@@ -54,6 +56,12 @@ const int CRC16_XMODEM_TABLE[] = { ...@@ -54,6 +56,12 @@ const int CRC16_XMODEM_TABLE[] = {
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
} ; } ;
double getTimeSec()
{
struct timeval t;
gettimeofday(&t, NULL);
return (t.tv_sec + t.tv_usec * 1.e-6);
}
int crc_calc( int * crc, unsigned int * data ){ int crc_calc( int * crc, unsigned int * data ){
...@@ -115,12 +123,15 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b ...@@ -115,12 +123,15 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b
printf("End\n"); printf("End\n");
#endif #endif
int bad = 0; int bad = 0;
while( offset + 4 < size ){ // 4 = ROB trailer size while( offset + 4 < size ){ // 4 = ROB trailer size
cur_pos = start_pos + offset; cur_pos = start_pos + offset;
int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ; int size_link = data[ cur_pos % DMASIZE ] & 0x000ffff ;
if ( 0 >= size_link || size_link > 10000000 ){ if ( 0 >= size_link || size_link > 10000000 ){
printf("[ERROR] Invalid size per link (%.8x words): link num %d\n", size_link, link_num); 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 return -1 ; // it could be that the memory was read
} }
...@@ -153,30 +164,30 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b ...@@ -153,30 +164,30 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b
// Check of CRC // Check of CRC
// //
if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){ if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){
printf("%.2d Bad ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", printf("%.2d Bad ! calcd %.8x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n",
link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, link_num, crc, data[ cur_pos % DMASIZE ], offset,
size, size_link, data[ (cur_pos+1) % DMASIZE ] ); size, size_link, data[ (cur_pos+1) % DMASIZE ] );
bad = 1; bad = 1;
(*crc_bad)++; (*crc_bad)++;
}else{ }else{
good_flag = 1; good_flag = 1;
// printf("%.2d Good ! calcd %.4x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n", // printf("%.2d Good ! calcd %.4x data %.8x offset %.4x size %.4x szlnk %.4x trl %.8x\n",
// link_num, crc, data[ cur_pos % DMASIZE ] & 0xffff, offset, // link_num, crc, data[ cur_pos % DMASIZE ], offset,
// size, size_link, data[ (cur_pos+1) % DMASIZE ] ); // size, size_link, data[ (cur_pos+1) % DMASIZE ] );
(*crc_good)++; (*crc_good)++;
} }
link_num++; link_num++;
offset += size_link; offset += size_link;
} }
//if( bad ){ if( bad ){
// for( i = 0 ; i < size ; i++){ for( i = 0 ; i < size ; i++){
// printf("%.8x ", data[ ( start_pos + i ) % DMASIZE ] ); printf("%.8x ", data[ ( start_pos + i ) % DMASIZE ] );
// if( i % 8 == 7 ) printf("\n"); if( i % 8 == 7 ) printf("\n");
// } }
// printf("\n"); printf("\n");
// good_flag = -2; good_flag = -2;
// } }
return good_flag; return good_flag;
} }
...@@ -194,7 +205,8 @@ int print_line(unsigned int *data, int cur_pos ){ ...@@ -194,7 +205,8 @@ int print_line(unsigned int *data, int cur_pos ){
} }
int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag, int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag,
unsigned int cur_exp_run, unsigned int cur_eve, unsigned int *next_exp_run, unsigned int *next_eve ){ unsigned int cur_exp_run, unsigned int cur_eve,
unsigned int *next_exp_run, unsigned int *next_eve ){
unsigned int trailer = 0; unsigned int trailer = 0;
int size = data[ cur_pos ] ; int size = data[ cur_pos ] ;
...@@ -210,15 +222,15 @@ int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag, ...@@ -210,15 +222,15 @@ int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag,
// printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
// *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size ); // *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
*event_flag = OLD_RUN; *event_flag = OLD_RUN;
}else if( *next_eve <= cur_eve && cur_exp_run != 0 ){ }else if( ( *next_eve <= cur_eve && cur_exp_run != 0 ) && *next_exp_run <= cur_exp_run){
// printf( "OLD or same event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "OLD or same event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
// *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size ); // print_line( data, ( cur_pos + 1 ) % DMASIZE );
*event_flag = OLD_EVENT; *event_flag = OLD_EVENT;
// }else if( trailer != 0x7fff0008 ){ // }else if( trailer != 0x7fff0008 ){
}else if( ( trailer & 0xffff0000 ) != 0x7fbf0000 ){ }else if( ( trailer & 0xffff0000 ) != 0x7fbf0000 && ( trailer & 0xffff0000 ) != 0x7fcf0000 ){
// printf( "No trailer [%.8x] : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( ".No trailer [%.8x] : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
// trailer, *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size ); // trailer, *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
// print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE ); // print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
*event_flag = NO_TRAILER; *event_flag = NO_TRAILER;
}else{ }else{
// printf( "New event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "New event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
...@@ -240,7 +252,7 @@ int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag, ...@@ -240,7 +252,7 @@ int check_hdr_trl( unsigned int *data, int cur_pos, int *event_flag,
int main (int argc ,char** argv) { int main (int argc ,char** argv) {
printf("DMASIZE %.8x\n", DMASIZE );fflush(stdout);
int res = ecs_open( 0 , 0 ) ; int res = ecs_open( 0 , 0 ) ;
if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ; if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
else printf("SUCCESS: Device opened for DMA\n"); else printf("SUCCESS: Device opened for DMA\n");
...@@ -249,6 +261,8 @@ int main (int argc ,char** argv) { ...@@ -249,6 +261,8 @@ int main (int argc ,char** argv) {
ecs_write( 0 , 2 , 0x000501A0 , 0x1 ) ; ecs_write( 0 , 2 , 0x000501A0 , 0x1 ) ;
pcie40_b2dmabufferreset( 0 ) ; pcie40_b2dmabufferreset( 0 ) ;
double start_time = 0., time_diff = 0.;
start_time = getTimeSec();
int run = 0 ; int run = 0 ;
FILE* fp; FILE* fp;
char * ptr ; char * ptr ;
...@@ -319,7 +333,6 @@ int main (int argc ,char** argv) { ...@@ -319,7 +333,6 @@ int main (int argc ,char** argv) {
// Search 7f7f header magic word. // Search 7f7f header magic word.
// //
while( 1 ){ while( 1 ){
ret = check_hdr_trl( data, cur_pos, &event_flag, cur_exp_run, cur_eve, &next_exp_run, &next_eve ); ret = check_hdr_trl( data, cur_pos, &event_flag, cur_exp_run, cur_eve, &next_exp_run, &next_eve );
if( ret == 1 && event_flag == 0){ if( ret == 1 && event_flag == 0){
break; break;
...@@ -335,23 +348,23 @@ int main (int argc ,char** argv) { ...@@ -335,23 +348,23 @@ int main (int argc ,char** argv) {
no_trl_cnt++; no_trl_cnt++;
} }
if(total_err_cnt % 100 == 1 && event_flag != 0 ){ if(total_err_cnt % PRESCALE == 1 && event_flag != 0 ){
printf("total %d oldrun %d old/same event %d no_trl %d goodlink %d badlink %d\n", printf("total %d oldrun %d old/same event %d no_trl %d goodlink %d badlink %d\n",
total_err_cnt, old_run_cnt, old_eve_cnt, no_trl_cnt, crc_good, crc_bad ); total_err_cnt, old_run_cnt, old_eve_cnt, no_trl_cnt, crc_good, crc_bad );
size = data[cur_pos]; size = data[cur_pos];
if( event_flag == OLD_RUN ){ // if( event_flag == OLD_RUN ){
printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size ); // next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data,cur_pos % DMASIZE ); // print_line( data,cur_pos % DMASIZE );
}else if( event_flag == OLD_EVENT ){ // }else if( event_flag == OLD_EVENT ){
printf( "OLD or same event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "OLD or same event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size ); // next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data,cur_pos % DMASIZE ); // print_line( data,cur_pos % DMASIZE );
}else if( event_flag == NO_TRAILER ){ // }else if( event_flag == NO_TRAILER ){
printf( "No trailer [%.8x] : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", // printf( "No trailer [%.8x] : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
next_exp_run, next_eve, cur_exp_run, cur_eve, cur_pos, size ); // next_exp_run, next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE ); // print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
} // }
} }
} }
...@@ -388,10 +401,10 @@ int main (int argc ,char** argv) { ...@@ -388,10 +401,10 @@ int main (int argc ,char** argv) {
no_trl_cnt++; no_trl_cnt++;
} }
if(total_err_cnt % 100 == 1 && event_flag != 0 ){ if(total_err_cnt % PRESCALE == 1 && event_flag != 0 ){
printf("total %d oldrun %d old/same event %d no_trl %d goodlink %d badlink %d\n", printf("total %d oldrun %d old/same event %d no_trl %d goodlink %d badlink %d\n",
total_err_cnt, old_run_cnt, old_eve_cnt, no_trl_cnt, crc_good, crc_bad ); total_err_cnt, old_run_cnt, old_eve_cnt, no_trl_cnt, crc_good, crc_bad );
size = data[cur_pos]; size = data[cur_pos] & 0xffffff;
if( event_flag == OLD_RUN ){ if( event_flag == OLD_RUN ){
printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", printf( "OLD-run's event : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size ); next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
...@@ -401,7 +414,7 @@ int main (int argc ,char** argv) { ...@@ -401,7 +414,7 @@ int main (int argc ,char** argv) {
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size ); next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data,cur_pos % DMASIZE ); print_line( data,cur_pos % DMASIZE );
}else if( event_flag == NO_TRAILER ){ }else if( event_flag == NO_TRAILER ){
printf( "No trailer [%.8x] : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n", printf( "No trailer : run %.8x eve %.8x ( cur run %.8x eve %.8x) : pos %.8x size %d\n",
next_exp_run, next_eve, cur_exp_run, cur_eve, cur_pos, size ); next_exp_run, next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE ); print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
} }
...@@ -427,8 +440,7 @@ int main (int argc ,char** argv) { ...@@ -427,8 +440,7 @@ int main (int argc ,char** argv) {
data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 2 + DMASIZE ) % DMASIZE ] ); data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 2 + DMASIZE ) % DMASIZE ] );
} }
#endif #endif
size = data[cur_pos] & 0xffffff;
size = data[ cur_pos ] ;
next_eve = data[ ( cur_pos + 3 ) % DMASIZE ]; next_eve = data[ ( cur_pos + 3 ) % DMASIZE ];
next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ]; next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ];
...@@ -446,15 +458,16 @@ int main (int argc ,char** argv) { ...@@ -446,15 +458,16 @@ int main (int argc ,char** argv) {
crc_err_eve_cnt++; crc_err_eve_cnt++;
} }
if(ret != 1 || eve_cnt % 100 == 0 ){ if(ret != 1 || eve_cnt % PRESCALE == 0 ){
printf( "Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size ); printf( "Event number prev %.8x new %.8x pos %.8x size %.8x\n" , cur_eve , next_eve, cur_pos, size );
} }
cur_eve = next_eve; cur_eve = next_eve;
cur_exp_run = next_exp_run; cur_exp_run = next_exp_run;
if( eve_cnt % 100 == 0 ){ if( eve_cnt % PRESCALE == 0 ){
// if( ret != 1 ){ // if( ret != 1 ){
// if(ret != 1 || eve_cnt % 100 == 0 ){ // if(ret != 1 || eve_cnt % 100 == 0 ){
printf("STATUS : tot eve %d read eve %d err_eve %d run %.8x crcgood %d crcbad %d\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run, crc_good, crc_bad); fflush(stdout); time_diff = getTimeSec() - start_time;
printf("STATUS : tot eve %d read eve %d err_eve %d run %.8x crcgood %d crcbad %d time %.1lf\n", next_eve - first_eve, eve_cnt, crc_err_eve_cnt, cur_exp_run, crc_good, crc_bad, time_diff); fflush(stdout);
} }
mod_pos = ( cur_pos + size ) % 8; mod_pos = ( cur_pos + size ) % 8;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment