00001 #include <iostream> 00002 #include <string> 00003 #include <sstream> 00004 00005 #include "utility.h" 00006 #include "ConfigurationUtility.h" 00007 #include "primParams.h" 00008 00009 #include "SctApiException.h" 00010 00011 using namespace std; 00012 00013 namespace SctApi { 00014 namespace Utility { 00015 void printMemoryBlock(ostream &os, unsigned long *mem, unsigned long words, int wordsPerLine, int level) 00016 { 00017 unsigned int lines = words/wordsPerLine; 00018 int skipping = 0; 00019 00020 os.fill('0'); 00021 00022 os << hex; 00023 for(unsigned int i=0; i<lines; i++) { 00024 int val = 0; 00025 for(int j=0; j<wordsPerLine; j++) { 00026 val+=mem[i*wordsPerLine+j]; 00027 } 00028 if(val == 0) { 00029 if(!skipping) 00030 os << string(" ", 0, level) << "."; 00031 skipping++; 00032 } else { 00033 if(skipping) os << " Skipped " << dec << skipping << hex << " blank lines\n"; 00034 skipping = 0; 00035 00036 os << string(" ", 0, level); 00037 for(int j=0; j<wordsPerLine; j++) { 00038 os.fill('0'); 00039 os.width(8); 00040 os << mem[i*wordsPerLine+j] << " "; 00041 } 00042 os << endl; 00043 } 00044 } 00045 if(skipping) os << " Skipped " << dec << skipping << hex << " blank lines\n"; 00046 if(lines*wordsPerLine < words) { 00047 os << string(" ", 0, level); 00048 for(unsigned int i=lines*wordsPerLine; i<words; i++) { 00049 os.fill('0'); 00050 os.width(8); 00051 os << mem[i] << " "; 00052 } 00053 os << endl; 00054 } 00055 os.fill(' '); 00056 00057 os << dec; 00058 } 00059 00060 UINT32 translateConfigTypeBitset(UINT32 api_bits, bool verbose){ 00061 if (verbose) std::cout << "Translate " << ConfigUtility::apiBitFieldToString(api_bits) << std::endl; 00062 UINT32 dsp_bits=0; 00063 for (int bit=1; bit<=SCTAPI_CONFIG_ALL; ++bit){ 00064 if ( 1<<bit & api_bits ) { 00065 dsp_bits |= translateConfigType(ConfigType(bit)); 00066 if (verbose) { 00067 std::cout << " API bit " << bit << " set ==> or with 0x" 00068 << hex << translateConfigType(ConfigType(bit)) 00069 << " to get 0x" << dsp_bits << dec << std::endl; 00070 } 00071 } 00072 } 00073 return dsp_bits; 00074 } 00075 00076 UINT32 getSetableConfigType(UINT32 bits, bool verbose){ 00077 switch (bits){ 00078 case CONFIG_MODULE_CFG: 00079 case CONFIG_MODULE_CALDATA: 00080 case CONFIG_MODULE_BASIC: 00081 case CONFIG_MODULE_TRIM: 00082 case CONFIG_MODULE_ALL: 00083 return bits; 00084 default: 00085 if (bits<64){ 00086 std::cout << "Sending whole config instead of 0x" << hex << bits << dec << std::endl; 00087 return CONFIG_MODULE_ALL; 00088 }else{ 00089 std::cerr << "WARNING - unknown cfg type bits 0x" 00090 << std::hex << bits << std::dec << std::endl; 00091 return CONFIG_MODULE_ALL; 00092 } 00093 } 00094 } 00095 00096 unsigned translateConfigTypeForSendPrimitive(ConfigType cfg){ 00097 unsigned realConfig=CONFIG_MODULE_ALL; 00098 switch (cfg){ 00099 case SCTAPI_CONFIG_TRIM: 00100 realConfig = CONFIG_MODULE_TRIM; break; 00101 case SCTAPI_CONFIG_BASIC: 00102 case SCTAPI_CONFIG_CFG: 00103 realConfig = CONFIG_MODULE_BASIC; break; 00104 default: 00105 realConfig = CONFIG_MODULE_ALL; break; 00106 } 00107 return realConfig; 00108 } 00109 00110 00111 unsigned translateConfigType(ConfigType cfg){ 00112 unsigned realtype; 00113 switch (cfg){ 00114 case SCTAPI_CONFIG_NONE: { 00115 #ifndef CONFIG_MODULE_CFG 00116 std::ostringstream oss; 00117 oss << "Invalid config specification : " << (int)cfg; 00118 throw SctApiException(oss.str()); 00119 #endif 00120 realtype=0; 00121 break; 00122 } 00123 case SCTAPI_CONFIG_CFG: 00124 realtype=CONFIG_MODULE_CFG; 00125 break; 00126 case SCTAPI_CONFIG_BASIC: 00127 realtype=CONFIG_MODULE_BASIC; 00128 break; 00129 case SCTAPI_CONFIG_TRIM: 00130 realtype=CONFIG_MODULE_TRIM; 00131 break; 00132 case SCTAPI_CONFIG_MASK: 00133 case SCTAPI_CONFIG_OTHER: 00134 case SCTAPI_CONFIG_ALL: 00135 realtype=CONFIG_MODULE_ALL; 00136 break; 00137 default: 00138 std::cout << "translateConfigType: Invalid type specification " << cfg << endl; 00139 throw SctApiException("Invalid config specification"); 00140 break; 00141 } 00142 return realtype; 00143 } 00144 00145 UINT32 translateApiBanksToRodCfgBitSet(std::list<BankType> banks){ 00146 UINT32 bits=0; 00147 for (std::list<BankType>::const_iterator i = banks.begin(); i!=banks.end(); ++i){ 00148 bits |= 1<< translateBank(*i); 00149 } 00150 return bits; 00151 } 00152 00153 unsigned translateChip(unsigned chip) { 00154 if (chip<6) { 00155 return chip; 00156 } else if (chip<12) { 00157 return chip+2; 00158 } else{ 00159 return ALL_CHIPS; 00160 } 00161 } 00162 00163 int translateBank(BankType bank) { 00164 int realBank; 00165 switch(bank) { 00166 case SCTAPI_BANK_PHYSICS: 00167 realBank = PHYSICS_CONFIG_SET; 00168 break; 00169 case SCTAPI_BANK_SCAN: 00170 realBank = SCAN_CONFIG_SET; 00171 break; 00172 case SCTAPI_BANK_CALIBRATION: 00173 realBank = SPARE_CONFIG_SET; 00174 break; 00175 default: 00176 std::cout << "translateBank: Invalid bank specification " << bank << endl; 00177 throw SctApiException("Invalid bank specification"); 00178 } 00179 return realBank; 00180 } 00181 } 00182 }