diff --git a/Pcie40Applications/main_pcie40_dma.cpp b/Pcie40Applications/main_pcie40_dma.cpp index 8a8aaab888a7f55df296d0f95cb33ae3a3b36d2b..ba66d6dd4a0a93229777245adea2692846d0b0a0 100644 --- a/Pcie40Applications/main_pcie40_dma.cpp +++ b/Pcie40Applications/main_pcie40_dma.cpp @@ -73,7 +73,7 @@ int main (int argc ,char** argv) { unsigned int * data = pcie40_getSuperPagePointer( 0 , 0 , 0 ) ; printData( data ) ; - data = pcie40_getSuperPagePointer( 0 , 0 , 2 ) ; + data = pcie40_getSuperPagePointer( 0 , 0 , 1 ) ; printData( data ) ; //data = pcie40_getSuperPagePointer( 0 , 1 , 0 ) ; //printData( data ) ; diff --git a/Pcie40Applications/main_pcie40_dmahighrate.cpp b/Pcie40Applications/main_pcie40_dmahighrate.cpp index 8702693c405864e188a828c2e5a007a90630cc8f..c118d9594ce9143e579667cd47197c9ebbe286a1 100644 --- a/Pcie40Applications/main_pcie40_dmahighrate.cpp +++ b/Pcie40Applications/main_pcie40_dmahighrate.cpp @@ -1,3 +1,8 @@ +bool check_second_crc = false ; +bool exit_on_error = false ; +int nTot = 1000000 ; +int max_number_of_messages = 10 ; + #include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -7,6 +12,29 @@ #include <chrono> #include <vector> #include <set> +#include <map> +#include <cstring> + +std::map< int , int > n_messages = { + { 0 , 0 } , // no data + { 1 , 0 } , // bad header + { 2 , 0 } , // bad size + { 3 , 0 } , // Bad word size + { 4 , 0 } , // Bad belle2 header + { 5 , 0 } , // bad trailer size + { 6 , 0 } , // bad trailer + { 7 , 0 } , // bad 7ff code + { 8 , 0 } , // bad version + { 9 , 0 } , // bad runnber + { 10 , 0 } , // bad event numnber + { 11 , 0 } , // bad link number + { 12 , 0 } , // bad FFAA + { 13 , 0 } , // bad link size + { 14 , 0 } , // bad data size + { 15 , 0 } , // Bad CRC + { 16 , 0 } // missing links +}; + extern "C" int ecs_open(int dev, int bar); extern "C" void ecs_close(int dev, int bar); @@ -60,6 +88,7 @@ void crc_calc( unsigned int & crc, unsigned int & data ){ } unsigned int get_crc( std::vector< unsigned int > &data , unsigned int initial_value ) { + // return 0 ; unsigned int result = initial_value ; for( auto it = data.begin() ; it != data.end() ; ++it ) crc_calc( result , (*it) ) ; return result ; @@ -106,72 +135,109 @@ void printFullData( unsigned int * data ) { data[8*eventSize+3], data[8*eventSize+2], data[8*eventSize+1], data[8*eventSize] ) ; } -int analyzeEventData( unsigned int * data , int i , unsigned int &exprun , unsigned int &runnumber , unsigned int &evtnum , double & dsize , - std::set< int > vlinks ) { +int analyzeHeader( unsigned int * data , unsigned int & size , double & dsize , int & total_pages , int & index_pages ) +{ if ( data == 0 ) { - printf( "No data\n" ) ; + n_messages[ 0 ] = n_messages[ 0 ] + 1 ; + if ( n_messages[ 0 ] < max_number_of_messages ) + printf( "No data\n" ) ; return 1 ; } - unsigned int size ; size = data[ 0 ] & 0xFFFF ; dsize += size * 32 ; // in bytes if ( ( data[7] != 0 ) || ( data[6] != 0 ) || ( data[5] != 0 ) || ( data[3] != 0 ) ) { - printf( "Bad header\n" ) ; - printHeader( data ) ; + n_messages[ 1 ] = n_messages[ 1 ] + 1 ; + if ( n_messages[ 1 ] < max_number_of_messages ) { + printf( "Bad header\n" ) ; + printHeader( data ) ; + } return 1 ; } else if ( ( data[ 0 ] & 0xFFFF ) != size ) { - printf( "Bad size %d %d\n" , data[0] & 0xFFFF , size ) ; + n_messages[ 2 ] = n_messages[ 2 ] + 1 ; + if ( n_messages[ 2 ] < max_number_of_messages ) + printf( "Bad size %d %d\n" , data[0] & 0xFFFF , size ) ; return 1 ; } else if ( ( ( data[ 2 ] & 0xFFFF0000 ) >> 16 ) != ( size * 32 ) ) { - printf( "Bad word size %d %d\n" , ( data[ 2 ] & 0xFFFF0000 ) >> 16 , size * 32 ) ; + n_messages[ 3 ] = n_messages[ 3 ] + 1 ; + if ( n_messages[ 3 ] < max_number_of_messages ) + printf( "Bad word size %d %d\n" , ( data[ 2 ] & 0xFFFF0000 ) >> 16 , size * 32 ) ; return 1 ; } else if ( ( ( data[ 0 ] & 0xFFFF0000 ) != 0xEEEE0000 ) || ( data[ 1 ] != 0xAAAAEEEE ) || ( ( data[ 2 ] & 0xFFFF ) != 0xAAAA ) ) { - printf( "Bad header\n" ) ; - printHeader( data ) ; + n_messages[ 4 ] = n_messages[ 4 ] + 1 ; + if ( n_messages[ 4 ] < max_number_of_messages ) { + printf( "Bad header\n" ) ; + printHeader( data ) ; + } return 1 ; } // Check trailer if ( data[ 8*(size-1) ] != size ) { - printf( "Bad size in trailer %d %d\n" , data[8*(size-1)], size ) ; + n_messages[ 5 ] = n_messages[ 5 ] + 1 ; + if ( n_messages[ 5 ] < max_number_of_messages ) + printf( "Bad size in trailer %d %d\n" , data[8*(size-1)], size ) ; return 1 ; } else if ( ( data[ 8*(size-1)+1 ] != 0 ) || ( data[ 8*(size-1)+2 ] != 0 ) || ( data[ 8*(size-1)+3 ] != 0 ) || ( data[ 8*(size-1)+4 ] != 0 ) || ( data[ 8*(size-1)+5 ] != 0 ) || ( data[ 8*(size-1)+6 ] != 0 ) || ( data[ 8*(size-1)+7 ] != 0 ) ) { - printf( "Bad trailer\n" ) ; - printTrailer( &data[ 8*(size-1) ] ) ; + n_messages[ 6 ] = n_messages[ 6 ] + 1 ; + if ( n_messages[ 6 ] < max_number_of_messages ) { + printf( "Bad trailer\n" ) ; + printTrailer( &data[ 8*(size-1) ] ) ; + } return 1 ; } - unsigned int event_size = data[ 8 ] ; - if ( ( data[ 9 ] & 0xFFFF0000 ) != 0x7F7F0000 ) { - printf( "Bad code 7F7F\n" ) ; + total_pages = ( data[ 4 ] & 0xFFFF0000 ) >> 16 ; + index_pages = ( data[ 4 ] & 0xFFFF ) ; + + // Remove header and trailer from data + std::copy( data + 8 , data + 8*(size-1) , data ) ; + if ( total_pages != 1 ) return -1 ; + return 0 ; +} + +int analyzeEventData( unsigned int * data , int i , unsigned int size , unsigned int &exprun , unsigned int &runnumber , unsigned int &evtnum , + std::set< int > vlinks ) { + + // TO CHECK LATER unsigned int event_size = data[ 8 ] ; + if ( ( data[ 1 ] & 0xFFFF0000 ) != 0x7F7F0000 ) { + n_messages[ 7 ] = n_messages[ 7 ] + 1 ; + if ( n_messages[ 7 ] < max_number_of_messages ) + printf( "Bad code 7F7F\n" ) ; return 1 ; } - if ( ( data[ 9 ] & 0xFF00 ) >> 8 != 0 ) { - printf( "Bad version\n" ) ; + if ( ( data[ 1 ] & 0xFF00 ) >> 8 != 0 ) { + n_messages[ 8 ] = n_messages[ 8 ] + 1 ; + if ( n_messages[ 8 ] < max_number_of_messages ) + printf( "Bad version\n" ) ; return 1 ; } if ( 0 == runnumber ) - runnumber = (data[10]&0xFFFFFF00)>>8 ; + runnumber = (data[2]&0xFFFFFF00)>>8 ; else { - if ( runnumber != ((data[10]&0xFFFFFF00)>>8) ) { - printf( "Bad runnumber: %d\n", (data[10]&0xFFFFFF00)>>8 ) ; + if ( runnumber != ((data[2]&0xFFFFFF00)>>8) ) { + n_messages[ 9 ] = n_messages[ 9 ] + 1 ; + if ( n_messages[ 9 ] < max_number_of_messages ) + printf( "Bad runnumber: %d\n", (data[2]&0xFFFFFF00)>>8 ) ; return 1 ; } } - if ( evtnum == std::numeric_limits<unsigned int>::max() ) evtnum = data[11] ; - if ( ( evtnum + i ) != data[11] ) - printf( "Bad event number %d %d\n" , i+evtnum , data[11] ) ; - - unsigned int myevtnum = data[ 11 ] ; - unsigned int ctime = data[ 12 ] ; - unsigned int utime = data[ 13 ] ; - unsigned int exp_run = data[ 10 ] ; + if ( evtnum == std::numeric_limits<unsigned int>::max() ) evtnum = data[3] ; + if ( ( evtnum + i ) != data[3] ) { + n_messages[ 10 ] = n_messages[ 10 ] + 1 ; + if ( n_messages[ 10 ] < max_number_of_messages ) + printf( "Bad event number %d %d\n" , i+evtnum , data[3] ) ; + } + + unsigned int myevtnum = data[ 3 ] ; + unsigned int ctime = data[ 4 ] ; + unsigned int utime = data[ 5] ; + unsigned int exp_run = data[ 2 ] ; unsigned int crc_init = 0xFFFF ; std::vector< unsigned int > f_crc ; @@ -183,34 +249,49 @@ int analyzeEventData( unsigned int * data , int i , unsigned int &exprun , unsig // find number of links unsigned int numLinks = 0 ; - unsigned int linksize = data[ 16 ] & 0xFFFFFFFF ; // to be checked with Yamada-san if OK - unsigned int current_event_start = 16 ; + unsigned int linksize = data[ 8 ] & 0xFFFFFFFF ; // to be checked with Yamada-san if OK + unsigned int current_event_start = 8 ; + + bool first_crc_checked = false ; while ( true ) { unsigned int linknumber = ( data[ current_event_start + 1 ] & 0xFF00 ) >> 8 ; if ( vlinks.count( linknumber ) == 0 ) { - printf( "Bad link number %d\n" , linknumber ) ; + n_messages[ 11 ] = n_messages[ 11 ] + 1 ; + if ( n_messages[ 11 ] < max_number_of_messages ) + printf( "Bad link number %d\n" , linknumber ) ; return 1 ; } vlinks.erase( linknumber ) ; if ( ( data[ current_event_start + 1 ] & 0xFFFF0000 ) != 0xFFAA0000 ) { - printf( "Bad FFAA for linknumber %d\n" , linknumber ) ; + n_messages[ 12 ] = n_messages[ 12 ] + 1 ; + if ( n_messages[ 12 ] < max_number_of_messages ) + printf( "Bad FFAA for linknumber %d\n" , linknumber ) ; return 1 ; } if ( ( current_event_start + linksize ) > ( 8 * size ) ) { - printf( "Bad link size %d %d\n" , (current_event_start+linksize) , (8*size) ) ; + n_messages[ 13 ] = n_messages[ 13 ] + 1 ; + if ( n_messages[ 13 ] < max_number_of_messages ) + printf( "Bad link size %d %d\n" , (current_event_start+linksize) , (8*size) ) ; return 1 ; } if ( ( ( data[ current_event_start + linksize - 1 ] ) & 0xFFFF0000 ) != 0xFF550000 ) { - printf( "Bad size of data %X\n" , data[ current_event_start + linksize -1 ] ) ; + n_messages[ 14 ] = n_messages[ 14 ] + 1 ; + if ( n_messages[ 14 ] < max_number_of_messages ) + printf( "Bad size of data %X\n" , data[ current_event_start + linksize -1 ] ) ; return 1 ; } std::vector< unsigned int > data_crc( data + current_event_start + 2 , data + current_event_start + linksize - 2 ) ; unsigned int crc_calc = get_crc( data_crc , first_crc ) ; unsigned int crc_data = data[ current_event_start + linksize - 2 ] & 0xFFFF ; if ( crc_calc != crc_data ) { - printf( "CRC Error %X %X\n" , crc_calc , crc_data ) ; - return 1 ; + if ( ( check_second_crc ) ) { // || ( ! first_crc_checked ) ) { + n_messages[ 15 ] = n_messages[ 15 ] + 1 ; + if ( n_messages[ 15 ] < max_number_of_messages ) + printf( "CRC Error %X %X %d %d\n" , crc_calc , crc_data , first_crc_checked , check_second_crc ) ; + return 1 ; + } + first_crc_checked = true ; } numLinks++ ; if ( ( ( data[ current_event_start + linksize ] & 0xFFFF0000 ) == 0x7FFF0000 ) ) break ; @@ -219,7 +300,9 @@ int analyzeEventData( unsigned int * data , int i , unsigned int &exprun , unsig } if ( ! vlinks.empty() ) { - printf( "Some links are missing\n" ) ; + n_messages[ 16 ] = n_messages[ 16 ] + 1 ; + if ( n_messages[ 16 ] < max_number_of_messages ) + printf( "Some links are missing\n" ) ; return 1 ; } return 0 ; @@ -277,7 +360,8 @@ void analyzeEventGenerator( unsigned int * data , int i , unsigned int size ) { // 0 = data, 1 = generator int main (int argc ,char** argv) { - int nTot = 1000000 ; + std::vector< unsigned int > te ; + get_crc( te , 0 ) ; double triggerRate = 400 ; // kHz double data_size = 0. ; @@ -354,18 +438,24 @@ int main (int argc ,char** argv) { int rv ; unsigned int * data ; + unsigned int * combined_data; int i = 0 ; + int k = 0 ; unsigned int exprun = 0 ; unsigned int runnumber = 0; unsigned int evtnum = std::numeric_limits<unsigned int>::max() ; int errors = 0 ; + unsigned int esize = 0 ; + int total_pages = 0 ; + int index_pages = 0 ; + int previous_index = 0 ; auto t1 = std::chrono::high_resolution_clock::now(); - while ( i < nTot ) { + while ( k < nTot ) { // start DMA and wait for one or more super pages of data rv = pcie40_dmaStart( 0 ) ; - // printf( "Number of super page received: %d\n" , rv ) ; + //printf( "Number of super page received: %d\n" , rv ) ; + // #pragma omp parallel for for ( int j = 0 ; j < rv * S_PAGE_SLOT_NMB ; ++j ) { - // data = pcie40_getSuperPagePointer( 0 , ( i / S_PAGE_SLOT_NMB ) % S_PAGES , i % S_PAGE_SLOT_NMB ) ; data = pcie40_getSuperPageCopy( 0 , ( i / S_PAGE_SLOT_NMB ) % S_PAGES , i % S_PAGE_SLOT_NMB ) ; if ( ( i == 0 ) && ( j == 0 ) ) t1 = std::chrono::high_resolution_clock::now() ; @@ -373,24 +463,44 @@ int main (int argc ,char** argv) { // printf( "Event number %d\n" , getEventNumber( data ) ) ; if ( ! isData ) analyzeEventGenerator( data , i , size ) ; else { - if ( 0 != analyzeEventData( data , i , exprun , runnumber , evtnum , data_size , valid_links ) ) { - exit( 0 ) ; + int ret = analyzeHeader( data , esize , data_size , total_pages , index_pages ) ; + + if ( 0 != ret ) { + if ( -1 == ret ) { + if ( index_pages == 0 ) + combined_data = new unsigned int[ total_pages * S_PAGE_SLOT_SIZE/4 ] ; + std::copy( data , data + 8*(size-2) , combined_data + previous_index ) ; + previous_index = previous_index + 8*(size-2) ; + if ( index_pages != ( total_pages - 1 ) ) { + delete data ; + ++i ; + if ( ( i > 0 ) && ( ( i % S_PAGE_SLOT_NMB ) == 0 ) ) pcie40_freeSuperPage( 0 , 1 ) ; + continue ; + } + data = combined_data ; + } else { + if ( exit_on_error ) exit( 0 ) ; + errors++ ; + } + } else if ( 0 != analyzeEventData( data , i , esize , exprun , runnumber , evtnum , valid_links ) ) { + if ( exit_on_error ) exit( 0 ) ; errors++ ; } } - + previous_index = 0 ; delete data ; // if ( i != getEventNumber( data ) ) printf( "Mismatch event number %d %d\n" , i , getEventNumber( data ) ) ; ++i ; - if ( ( i % 1000 ) == 0 ) printf( "Event number %d\n" , i ) ; + ++k ; + if ( ( k % 1000 ) == 0 ) printf( "Event number %d\n" , k ) ; + if ( ( i > 0 ) && ( ( i % S_PAGE_SLOT_NMB ) == 0 ) ) pcie40_freeSuperPage( 0 , 1 ) ; } - if ( ( i > 0 ) && ( ( i % S_PAGE_SLOT_NMB ) == 0 ) ) pcie40_freeSuperPage( 0 , rv ) ; } auto t2 = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); double rate = 0. ; if ( duration > 0. ) rate = 1000. * nTot/( (double) duration ) ; // kHz - double exp_rate = 10416.666/( (double) t_rate + 1. ) ; + // double exp_rate = 10416.666/( (double) t_rate + 1. ) ; double bandwidth = 8. * data_size / ( (double) nTot ) * rate / 1000. ; // Mb/s printf( "Trigger rate = %.2f kHz\n" , rate ) ; printf( "Bandwidth = %.2f Mb/s\n" , bandwidth ) ; diff --git a/Pcie40Applications/main_pcie40_miniPod.c b/Pcie40Applications/main_pcie40_miniPod.c index 52ceab990e5c7e3b2a28ba3c460a75d5aa16b4e8..0d9edd3efb4fa1bfb0759577fa9c141b0445980d 100644 --- a/Pcie40Applications/main_pcie40_miniPod.c +++ b/Pcie40Applications/main_pcie40_miniPod.c @@ -422,7 +422,7 @@ int minipod; /***********************************************/ int main (int argc, char **argv) { -char * optstring = "m:c:l:d:v:b:fsh"; +const char * optstring = "m:c:l:d:v:b:fsh"; struct option longopts[] = { /* name has_arg flag val */ // { "init-speed", 0, (int*)&cmd, initSpeed }, diff --git a/Pcie40Applications/main_pcie40_readFPGAversion.cpp b/Pcie40Applications/main_pcie40_readFPGAversion.cpp index 69caa02aa68ec81f9d744d3ae6bf79c889ed1e02..240023dd45b111fab861a487e86650e62f324c6d 100644 --- a/Pcie40Applications/main_pcie40_readFPGAversion.cpp +++ b/Pcie40Applications/main_pcie40_readFPGAversion.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]){ int i; unsigned val; int reg = 0; - char contenuMemoireFPGA[SIZE_MEMO_FPGA + 1]; + char contenuMemoireFPGA[SIZE_MEMO_FPGA + 2]; ecs_openLli(board); for(i=0; i < SIZE_MEMO_FPGA; i++) diff --git a/Pcie40Applications/regconfig.cpp b/Pcie40Applications/regconfig.cpp index 0e7c35dda9f1bfa33f264bc6574e60bf28452cdc..3aa0930cc5e6575ec9d194cb2466d897b484e4b7 100644 --- a/Pcie40Applications/regconfig.cpp +++ b/Pcie40Applications/regconfig.cpp @@ -88,8 +88,8 @@ bool OP_FLAG = false; std::vector<std::string> splitpath(const std::string str, const char del) { - int first = 0; - int last = str.find_first_of(del); + unsigned int first = 0; + unsigned int last = str.find_first_of(del); std::vector<std::string> result; @@ -185,7 +185,7 @@ void argument(int argc, char **argv){ int hsreg(const char *name) { - static struct { char *name; int adrs; } regs[] = { + static struct { const char *name; int adrs; } regs[] = { { "link", PCIE40_LINK } , { "checkfee", PCIE40_CHECKFEE }, { "resetb2l", PCIE40_RESETB2L }, @@ -194,7 +194,7 @@ hsreg(const char *name) { "trghold", PCIE40_TRGOFF }, { "trigger", PCIE40_TRGON }, { "realtrg", PCIE40_TTTRG }, - { "simtrg" , PCIE40_DUMTRG }, + { "simtrg", PCIE40_DUMTRG }, { "simple", PCIE40_SUPMODE }, { "verbose", PCIE40_RAWMODE }, @@ -210,7 +210,7 @@ hsreg(const char *name) { "stat", PCIE40REGL_STAT }, }; - int i; + unsigned int i; if (isdigit(name[0])) { return strtoul(name, 0, 16); @@ -259,7 +259,6 @@ int pcie40_op(int dev, int ch, int op_addr, int addr, int data, pcie40reg_t pcie40) { int i; - const char *feetype; int cmd = 0; int cmd_cdc = 0; switch (op_addr) { @@ -347,7 +346,6 @@ int main(int argc, char** argv){ // open pcie40 device driver for current process ecs_open( dev_slot , SLC_BAR ); - pcie40reg_t pcie40; int result = -1; diff --git a/Pcie40Applications/rules.mk b/Pcie40Applications/rules.mk index f00fb47f0aa85d85a0430a7c2255b63fc0101601..f885ee24c59658690f7060d681d73739b0aec167 100644 --- a/Pcie40Applications/rules.mk +++ b/Pcie40Applications/rules.mk @@ -3,7 +3,7 @@ LIBDIR_SUFFIX ?=64 FLEX ?=flex LFLAGS ?= CFLAGS +=-Wall -g -O3 -CXXFLAGS +=-Wall -g -O3 +CXXFLAGS +=-Wall -g -O3 -fopenmp DOCRA ?=docra ASCIIDOCTOR ?=asciidoctor diff --git a/Pcie40Applications/statlink.cpp b/Pcie40Applications/statlink.cpp index 4c695122666bfc08d8b1084055ea7fbe2dded38d..5fdb1d64b33eae156127c410f84045487efd6c60 100644 --- a/Pcie40Applications/statlink.cpp +++ b/Pcie40Applications/statlink.cpp @@ -148,10 +148,6 @@ statpice40(pcie40reg_t pcie40reg) int getfee( pcie40reg_t *pcie40p) { - int i; - const char *feetype; - - int ret; int hwtype; int serial; int fwtype; @@ -180,7 +176,6 @@ int readregs(std::bitset<48> link_mask, pcie40reg_t pcie40reg[]) { int i; - int o_readonly = 1; int notfound = 1; for (i=0; i<48; i++) { @@ -301,6 +296,7 @@ statlink(std::bitset<48> link_mask, pcie40reg_t pcie40reg[]) if (quiet) { printf("no PCIE40 was found.\n"); } + return 0 ; } diff --git a/Pcie40Applications/timediff.cpp b/Pcie40Applications/timediff.cpp index 4b8b61dc40aa912f4dd31457e1a5b29beeabb7a1..5852861901200a156e9d051c202bb46347248344 100644 --- a/Pcie40Applications/timediff.cpp +++ b/Pcie40Applications/timediff.cpp @@ -68,7 +68,6 @@ int main(int argc, char **argv) { // // First arg: CLOCK_REALTIME, CLOCL_MONOTONIC, etc. int ret = clock_gettime(CLOCK_REALTIME, &ts); int result; - int valp; ecs_open( 0 , 2 ); for(int i=0; i<loops; i++){ if(HSLB_FLAG){ diff --git a/Pcie40DriverLibraries/Makefile b/Pcie40DriverLibraries/Makefile index aa2d399c1a9b6c86f5f4f5e2b3c99b0dd7827657..2bebcffe02f543497b228e5b3bf2cad943653868 100644 --- a/Pcie40DriverLibraries/Makefile +++ b/Pcie40DriverLibraries/Makefile @@ -1,8 +1,6 @@ HERE :=$(strip $(realpath $(dir $(lastword $(MAKEFILE_LIST))))) TOP :=$(realpath $(HERE)) -include $(TOP)/flags.mk - LIBPCIE40_ECS.A :=libpcie40driver_ecs.a LIBPCIE40_ECS.A_OBJS =pcie40_driverlib.o ecs_driverlib.o LIBPCIE40_ECS.A_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver diff --git a/Pcie40DriverLibraries/flags.mk b/Pcie40DriverLibraries/flags.mk deleted file mode 100755 index fe8e02c6efca79891fcfeb7aa48baf2696add452..0000000000000000000000000000000000000000 --- a/Pcie40DriverLibraries/flags.mk +++ /dev/null @@ -1,3 +0,0 @@ -export ENABLE_PCIE40 ?=true - -export PREFIX ?=/usr diff --git a/Pcie40Libraries/Makefile b/Pcie40Libraries/Makefile index 3ee003ecd87deb3338141040f4c3933bd2713535..3fd23d2c8152fb46f7f6f66aaf75cd337dc801f8 100644 --- a/Pcie40Libraries/Makefile +++ b/Pcie40Libraries/Makefile @@ -1,7 +1,8 @@ -CC=gcc -fPIC -g +CC=gcc -fPIC -g -O3 CFLAGS= -c -Wall LDFLAGS= -GPP = g++ -fPIC -std=c++0x +GPP = g++ -fPIC -std=c++0x -O3 + #defined global variables and programs to build include Makefile.conf @@ -29,8 +30,11 @@ LTC2990_SRC= LTC2990_OBJ=$(LTC2990_SRC:$(SRC_DIR)$(LTC2990_DIR)%.c=$(OBJ_DIR)%.o) # Belle II specific libraries (slow control, ECS, ...) -B2LIB_SRC= pcie40_b2slc.cpp pcie40_reg.cpp pcie40_b2ecs.c pcie40_b2dma.cpp pcie40_b2config.cpp -B2LIB_OBJ=$(B2LIB_SRC:%.c=$(OBJ_DIR)%.o) +B2LIB_SRC_C= pcie40_b2ecs.c +B2LIB_OBJ_C=$(B2LIB_SRC_C:%.c=$(OBJ_DIR)%.o) + +B2LIB_SRC_CPP= pcie40_b2slc.cpp pcie40_reg.cpp pcie40_b2dma.cpp pcie40_b2config.cpp +B2LIB_OBJ_CPP=$(B2LIB_SRC_CPP:%.cpp=$(OBJ_DIR)%.o) # static libraries ECS_LIB= libecs.a @@ -54,15 +58,20 @@ $(ECS_LIB) : $(ECS_OBJ) ar -q $(LIB_DIR)$(ECS_LIB) $(ECS_OBJ) @echo "" -$(B2LIB_OBJ): $(OBJ_DIR)%.o : %.c +$(B2LIB_OBJ_C): $(OBJ_DIR)%.o : %.c @echo "Construction of ecs objects $@ from $<" mkdir -p obj $(CC) $(CFLAGS) -I . -I $(PCIE40_INC_DIR) -I $(PCIE40_DRIVER_DIR) $< -o $@ -$(B2LIB_LIB) : $(B2LIB_OBJ) +$(B2LIB_OBJ_CPP): $(OBJ_DIR)%.o : %.cpp + @echo "Construction of ecs objects $@ from $<" + mkdir -p obj + $(GPP) $(CFLAGS) -I . -I $(PCIE40_INC_DIR) -I $(PCIE40_DRIVER_DIR) $< -o $@ + +$(B2LIB_LIB) : $(B2LIB_OBJ_C) $(B2LIB_OBJ_CPP) @echo "Construction of Belle II SLC Library" mkdir -p lib - ar -q $(LIB_DIR)$(B2LIB_LIB) $(B2LIB_OBJ) + ar -q $(LIB_DIR)$(B2LIB_LIB) $(B2LIB_OBJ_C) $(B2LIB_OBJ_CPP) @echo "" $(MINIPODS_OBJ): $(OBJ_DIR)%.o : $(SRC_DIR)%.c @@ -88,7 +97,7 @@ $(LTC2990_LIB) : $(LTC2990_OBJ) $(LLI_DYNLIB) : $(ECS_OBJ) $(MINIPODS_OBJ) @echo "Construction of dynamic LLI technical Library for V2" mkdir -p lib - $(GPP) -o $(LIB_DIR)$(LLI_DYNLIB) -shared $(ECS_OBJ) $(PLL_OBJ) $(MINIPODS_OBJ) $(B2LIB_OBJ) -L $(PCIE40_DYN_LIB) -lpcie40driver_ecs -I $(PCIE40_DRIVER_DIR) + $(GPP) -o $(LIB_DIR)$(LLI_DYNLIB) -shared $(ECS_OBJ) $(PLL_OBJ) $(MINIPODS_OBJ) $(B2LIB_OBJ_C) $(B2LIB_OBJ_CPP) -L $(PCIE40_DYN_LIB) -lpcie40driver_ecs -I $(PCIE40_DRIVER_DIR) @echo clean: mrproper diff --git a/Pcie40Libraries/pcie40_b2config.cpp b/Pcie40Libraries/pcie40_b2config.cpp index ad42d8946fc243e4afd59f97de75c6eaff5356f2..0b992aca6d52f97e89f1af54f88b7b16ebfba057 100644 --- a/Pcie40Libraries/pcie40_b2config.cpp +++ b/Pcie40Libraries/pcie40_b2config.cpp @@ -35,7 +35,6 @@ std::string pcie40_fpgaVersion( int dev ) { std::string content ; for ( int i = 0 ; i < SIZE_MEMO_FPGA ; ++i ) { ecs_iordLli( dev , reg , &val ) ; - char value = val ; content += val ; reg += 4 ; } @@ -200,7 +199,6 @@ int pcie40_pll::write_pagined_register( int register_address , unsigned int valu int status1 = i2c_readMem(dev, bus, add, page_register_address, ¤t_page ) ; int status2 ; current_page = current_page & 0xFFFFFFFF ; - int val ; if ( current_page != msbyte_register_address ) { status2 = i2c_writeMem(dev, bus, add, page_register_address, &msbyte_register_address ) ; } else { @@ -238,7 +236,8 @@ void pcie40_pll::programming( std::ifstream & file ) { while( std::getline( ss , s , ',' ) ) strings.push_back( s ) ; int current_regstr = std::strtol( strings[ 0 ].c_str() , NULL , 16 ) ; unsigned int current_valstr = std::strtoul( strings[ 1 ].c_str() , NULL , 16 ) ; - int status1 = write_pagined_register(current_regstr, current_valstr) ; + // int status1 = + write_pagined_register(current_regstr, current_valstr) ; } // **********************************2) wait 300ms ***************************************** sleep(0.3) ; @@ -257,7 +256,8 @@ void pcie40_pll::programming( std::ifstream & file ) { while( std::getline( ss , s , ',' ) ) strings.push_back( s ) ; int current_regstr = std::strtol( strings[ 0 ].c_str() , NULL , 16 ) ; unsigned int current_valstr = std::strtoul( strings[ 1 ].c_str() , NULL , 16 ) ; - int status1 = write_pagined_register(current_regstr, current_valstr) ; + // int status1 = + write_pagined_register(current_regstr, current_valstr) ; } // ********************4) Write the post-amble and SOFT_RST ******************************** @@ -275,7 +275,8 @@ void pcie40_pll::programming( std::ifstream & file ) { while( std::getline( ss , s , ',' ) ) strings.push_back( s ) ; int current_regstr = std::strtol( strings[ 0 ].c_str() , NULL , 16 ) ; unsigned int current_valstr = std::strtoul( strings[ 1 ].c_str() , NULL , 16 ) ; - int status1 = write_pagined_register(current_regstr, current_valstr) ; + //int status1 = + write_pagined_register(current_regstr, current_valstr) ; } } @@ -301,7 +302,8 @@ void pcie40_pll::clear_lol_flg_bit() { unsigned int value ; int status1 = read_pagined_register(register_address, value ) ; value = value & ~(1 << 1) ; - int status2 = write_pagined_register(register_address, value) ; + // int status2 = + write_pagined_register(register_address, value) ; status1 = read_pagined_register(register_address , value ) ; } @@ -310,7 +312,8 @@ bool pcie40_pll::read_loss_of_lock() { int bit_position = 1 ; bool loss_of_lock = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + // int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) loss_of_lock = true ; return loss_of_lock ; } @@ -320,7 +323,8 @@ bool pcie40_pll::read_loss_of_lock_flg() { int bit_position = 1 ; bool loss_of_lock_flg = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + // int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) loss_of_lock_flg = true ; return loss_of_lock_flg ; } @@ -334,7 +338,8 @@ bool pcie40_pll::read_loss_of_signal( int ch ) { int bit_position = ch ; bool loss_of_signal = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + // int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) loss_of_signal = true ; return loss_of_signal ; } @@ -348,7 +353,8 @@ bool pcie40_pll::read_loss_of_signal_flg( int ch ) { int bit_position = ch ; bool loss_of_signal_flg = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + // int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) loss_of_signal_flg = true ; return loss_of_signal_flg ; } @@ -362,7 +368,8 @@ bool pcie40_pll::read_out_of_frequency( int ch ) { int bit_position = 4 + ch ; bool out_of_frequency = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + // int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) out_of_frequency = true ; return out_of_frequency ; } @@ -376,7 +383,8 @@ bool pcie40_pll::read_out_of_frequency_flg( int ch ) { int bit_position = 4 + ch ; bool out_of_frequency_flg = false ; unsigned int value ; - int status = read_pagined_register(register_address, value) ; + //int status = + read_pagined_register(register_address, value) ; if ( (value >> bit_position) & 1 ) out_of_frequency_flg = true ; return out_of_frequency_flg ; } @@ -388,7 +396,7 @@ int pcie40_configurePLLs( int dev ) { pcie40_pll pll3( dev , 3 , 0x68 ) ; // 1. reset the PLLs ( pll_si5345_1, pll_si5345_2, pll_si5344 ) - int status = 0 ; + // int status = 0 ; pll1.hardReset() ; pll2.hardReset() ; pll3.hardReset() ; diff --git a/Pcie40Libraries/pcie40_b2dma.cpp b/Pcie40Libraries/pcie40_b2dma.cpp index 61432fbcafa6e4f6ae131d77a670232025deffbe..2e64771e8a44815a53e76beee156c81ced7a3536 100644 --- a/Pcie40Libraries/pcie40_b2dma.cpp +++ b/Pcie40Libraries/pcie40_b2dma.cpp @@ -33,7 +33,7 @@ int dma_open( int fd ) { // map spage addresses for ( int i=0 ; i<LINK_NUMBER ; i++ ) for ( int j=0 ; j<S_PAGES ; j++ ) { - + //set spage for mapping; unsigned act_spage = ( i << 8 ) | j ; G_dma_cmd.cmd = ALTERA_CMD_ACTSPAGE ; @@ -227,7 +227,6 @@ int pcie40_disableExternalTrigger(int fd) { // Set Busy level (not sure it is used) // ************************************************************************** int pcie40_setBusyLevel( int fd , unsigned int level ) { - int ret = 0 ; return ecs_write( fd , LLI_BAR , DMA_BUSY_LEVEL , level ) ; } diff --git a/Pcie40Libraries/pcie40_b2slc.cpp b/Pcie40Libraries/pcie40_b2slc.cpp index 50793a175d3b666748304af488783fcb1832ca14..541e1744515f416d748494e6d02569ecd4efcfa6 100644 --- a/Pcie40Libraries/pcie40_b2slc.cpp +++ b/Pcie40Libraries/pcie40_b2slc.cpp @@ -157,7 +157,8 @@ int pcie40_writeToFifo( int dev , int ch , std::vector< int > & data ) { } int pcie40_startEmit( int dev , int ch , int expected ) { - unsigned ret = 0 ; + int ret = 0 ; + if ( expected != -1 ) { // check that FIFO is written ret = pcie40_writeFifoFillLevel( dev , ch ) ; @@ -188,7 +189,7 @@ int pcie40_startEmit( int dev , int ch , int expected ) { return ret ; } -int pcie40_waitRead( int dev , int ch , int length ) { +int pcie40_waitRead( int dev , int ch , unsigned int length ) { unsigned ret = 0 ; int i ; for ( i=0 ; i<100 ; i++ ) { diff --git a/Pcie40Libraries/pcie40_ecs.c b/Pcie40Libraries/pcie40_ecs.c index ffa175c6905a1138c29f63bc9ebf8d47e874e2f4..2b0b4fc01a0841209b69c45d911a1b7c507ce7ba 100644 --- a/Pcie40Libraries/pcie40_ecs.c +++ b/Pcie40Libraries/pcie40_ecs.c @@ -123,16 +123,16 @@ int dma_launch(int dev , unsigned int ** pDmaUser ) { } unsigned ecs_read(int dev, int bar, unsigned add){ - uint32_t val; - if (add%4 != 0) - return(-1); - if (bar==2){ - val = p40_ecs_r32(ecs_bar2_mm[dev],add); - } - else if (bar==0){ - val = p40_ecs_r32(ecs_bar1_mm[dev],add); - } - return val; + uint32_t val=0; + if (add%4 != 0) + return(-1); + if (bar==2){ + val = p40_ecs_r32(ecs_bar2_mm[dev],add); + } + else if (bar==0){ + val = p40_ecs_r32(ecs_bar1_mm[dev],add); + } + return val; } int ecs_iowrBar(int dev, int bar, unsigned add, unsigned *val){ diff --git a/Pcie40Libraries/pcie40_reg.cpp b/Pcie40Libraries/pcie40_reg.cpp index e2730ee88e9ad0ed57234becdf6d19423f13cbed..f3c74205094e935686317a875a10a286dbbad943 100644 --- a/Pcie40Libraries/pcie40_reg.cpp +++ b/Pcie40Libraries/pcie40_reg.cpp @@ -37,7 +37,7 @@ const char* pcie40_fwver(int dev){ int board = 0; unsigned val; int reg = 0; - char contenuMemoireFPGA[SIZE_MEMO_FPGA + 1]; + char contenuMemoireFPGA[SIZE_MEMO_FPGA + 2]; for(int i=0; i < SIZE_MEMO_FPGA; i++){ if (ecs_iordLli(board, reg, &val)!=0){ @@ -51,8 +51,8 @@ const char* pcie40_fwver(int dev){ std::string memo_str = contenuMemoireFPGA; char delims = '"'; - int first = 0; - int last = memo_str.find_first_of(delims); + unsigned int first = 0; + unsigned int last = memo_str.find_first_of(delims); std::vector<std::string> memo;