Skip to content
Snippets Groups Projects
Commit 1708da35 authored by qzhou's avatar qzhou
Browse files

Merge branch 'master' into monitoring

parents 07057ea7 5ed61b1e
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
#include <unistd.h>
#include <time.h>
#include "altera_dma_regs.h"
#include <sys/time.h>
extern "C" int ecs_open(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);
#define OLD_RUN 1
#define OLD_EVENT 2
#define NO_TRAILER 3
#define PRESCALE 1000
const int CRC16_XMODEM_TABLE[] = {
......@@ -54,6 +56,12 @@ const int CRC16_XMODEM_TABLE[] = {
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 ){
......@@ -115,12 +123,15 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b
printf("End\n");
#endif
int bad = 0;
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 ){
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
}
......@@ -153,30 +164,30 @@ int crc_calc_event( unsigned int* data, int start_pos, int *crc_good, int *crc_b
// Check of CRC
//
if( ( crc & 0xffff ) != ( data[ cur_pos % DMASIZE ] & 0xffff ) ){
printf("%.2d Bad ! 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 Bad ! calcd %.8x data %.4x offset %.4x size %.4x szlnk %.4x trl %.8x\n",
link_num, crc, data[ cur_pos % DMASIZE ], offset,
size, size_link, data[ (cur_pos+1) % DMASIZE ] );
bad = 1;
(*crc_bad)++;
}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 %.8x offset %.4x size %.4x szlnk %.4x trl %.8x\n",
// link_num, crc, data[ cur_pos % DMASIZE ], offset,
// size, size_link, data[ (cur_pos+1) % DMASIZE ] );
(*crc_good)++;
}
link_num++;
offset += size_link;
}
//if( bad ){
// for( i = 0 ; i < size ; i++){
// printf("%.8x ", data[ ( start_pos + i ) % DMASIZE ] );
// if( i % 8 == 7 ) printf("\n");
// }
// printf("\n");
// good_flag = -2;
// }
if( bad ){
for( i = 0 ; i < size ; i++){
printf("%.8x ", data[ ( start_pos + i ) % DMASIZE ] );
if( i % 8 == 7 ) printf("\n %.8x ", ( start_pos + i ) % DMASIZE );
}
printf("\n");
good_flag = -2;
}
return good_flag;
}
......@@ -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,
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;
int size = data[ cur_pos ] ;
......@@ -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",
// *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
*event_flag = OLD_RUN;
}else if( *next_eve <= cur_eve && cur_exp_run != 0 ){
// 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 );
}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", *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
// print_line( data, ( cur_pos + 1 ) % DMASIZE );
*event_flag = OLD_EVENT;
// }else if( trailer != 0x7fff0008 ){
}else if( ( trailer & 0xffff0000 ) != 0x7fbf0000 ){
// 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 );
// print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
}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",
// trailer, *next_exp_run , *next_eve, cur_exp_run, cur_eve, cur_pos, size );
// print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
*event_flag = NO_TRAILER;
}else{
// 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,
int main (int argc ,char** argv) {
printf("DMASIZE %.8x\n", DMASIZE );fflush(stdout);
int res = ecs_open( 0 , 0 ) ;
if ( -1 == res ) printf("ERROR: Could not open device (BAR 0)\n") ;
else printf("SUCCESS: Device opened for DMA\n");
......@@ -249,6 +261,8 @@ int main (int argc ,char** argv) {
ecs_write( 0 , 2 , 0x000501A0 , 0x1 ) ;
pcie40_b2dmabufferreset( 0 ) ;
double start_time = 0., time_diff = 0.;
start_time = getTimeSec();
int run = 0 ;
FILE* fp;
char * ptr ;
......@@ -319,7 +333,6 @@ int main (int argc ,char** argv) {
// Search 7f7f header magic word.
//
while( 1 ){
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){
break;
......@@ -335,23 +348,23 @@ int main (int argc ,char** argv) {
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",
total_err_cnt, old_run_cnt, old_eve_cnt, no_trl_cnt, crc_good, crc_bad );
size = data[cur_pos];
if( event_flag == OLD_RUN ){
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 );
print_line( data,cur_pos % DMASIZE );
}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",
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data,cur_pos % DMASIZE );
}else if( event_flag == NO_TRAILER ){
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 );
print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
}
// if( event_flag == OLD_RUN ){
// 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 );
// print_line( data,cur_pos % DMASIZE );
// }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",
// next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
// print_line( data,cur_pos % DMASIZE );
// }else if( event_flag == NO_TRAILER ){
// 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 );
// print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
// }
}
}
......@@ -388,10 +401,10 @@ int main (int argc ,char** argv) {
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",
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 ){
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 );
......@@ -401,7 +414,7 @@ int main (int argc ,char** argv) {
next_exp_run , next_eve, cur_exp_run, cur_eve, cur_pos, size );
print_line( data,cur_pos % DMASIZE );
}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 );
print_line( data, ( cur_pos + size + DMASIZE - 1 ) % DMASIZE );
}
......@@ -427,8 +440,7 @@ int main (int argc ,char** argv) {
data[ ( cur_pos + data[ cur_pos % DMASIZE ] - 2 + DMASIZE ) % DMASIZE ] );
}
#endif
size = data[ cur_pos ] ;
size = data[cur_pos] & 0xffffff;
next_eve = data[ ( cur_pos + 3 ) % DMASIZE ];
next_exp_run = data[ ( cur_pos + 2 ) % DMASIZE ];
......@@ -446,15 +458,16 @@ int main (int argc ,char** argv) {
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 );
}
cur_eve = next_eve;
cur_exp_run = next_exp_run;
if( eve_cnt % 100 == 0 ){
if( eve_cnt % PRESCALE == 0 ){
// if( ret != 1 ){
// 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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment