$treeview $search $mathjax $extrastylesheet
otsdaq_components
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /* 00002 * VIPICROCDefinitions.cc 00003 * 00004 * Created on: Jun 12, 2013 00005 * Author: Luigi Vigani 00006 */ 00007 00008 #include "otsdaq-components/DetectorHardware/VIPICROCDefinitions.h" 00009 #include "otsdaq-core/BitManipulator/BitManipulator.h" 00010 //#include "otsdaq-core/MessageFacility/MessageFacility.h" 00011 #include <cassert> 00012 #include <cstdlib> 00013 #include <iostream> 00014 #include "otsdaq-core/Macros/CoutMacros.h" 00015 00016 using namespace ots; 00017 00018 //======================================================================================================================== 00019 VIPICROCDefinitions::VIPICROCDefinitions() {} 00020 00021 //======================================================================================================================== 00022 VIPICROCDefinitions::~VIPICROCDefinitions(void) {} 00023 00024 //======================================================================================================================== 00025 unsigned int VIPICROCDefinitions::getDACRegisterAddress(const std::string& registerName) 00026 { 00027 if(registerName == "PulserData") 00028 return 1; 00029 else if(registerName == "PulserControl") 00030 return 2; 00031 else if(registerName == "IntegratorVbn") 00032 return 3; 00033 else if(registerName == "ShaperVbp2") 00034 return 4; 00035 else if(registerName == "ShaperVbp1") 00036 return 5; 00037 else if(registerName == "BLRestorer") 00038 return 6; 00039 else if(registerName == "VTn") 00040 return 7; 00041 else if(registerName == "VTp0") 00042 return 8; 00043 else if(registerName == "VTp1") 00044 return 9; 00045 else if(registerName == "VTp2") 00046 return 10; 00047 else if(registerName == "VTp3") 00048 return 11; 00049 else if(registerName == "VTp4") 00050 return 12; 00051 else if(registerName == "VTp5") 00052 return 13; 00053 else if(registerName == "VTp6") 00054 return 14; 00055 else if(registerName == "VTp7") 00056 return 15; 00057 else if(registerName == "ActiveLines") 00058 return 16; 00059 else if(registerName == "SendData") 00060 return 19; 00061 else if(registerName == "RejectHits") 00062 return 20; 00063 else if(registerName == "DigContrReg") 00064 return 27; 00065 else if(registerName == "AqBCO") 00066 return 30; 00067 // Kill and Inject are GENERAL names that will be used for all ROCs 00068 else if(registerName == "Kill") 00069 return 17; 00070 else if(registerName == "Inject") 00071 return 18; 00072 else 00073 { 00074 std::cout << __COUT_HDR_FL__ << " Register Name not recognized!" << std::endl; 00075 assert(0); 00076 } 00077 return 0; 00078 } 00079 00080 //======================================================================================================================== 00081 uint64_t VIPICROCDefinitions::makeDACWriteHeader(int chipId, 00082 const std::string& registerName) 00083 { 00084 return makeDACHeader(chipId, registerName, write); 00085 } 00086 00087 //======================================================================================================================== 00088 uint64_t VIPICROCDefinitions::makeDACSetHeader(int chipId, 00089 const std::string& registerName) 00090 { 00091 return makeDACHeader(chipId, registerName, set); 00092 } 00093 00094 //======================================================================================================================== 00095 uint64_t VIPICROCDefinitions::makeDACResetHeader(int chipId, 00096 const std::string& registerName) 00097 { 00098 return makeDACHeader(chipId, registerName, reset); 00099 } 00100 00101 //======================================================================================================================== 00102 uint64_t VIPICROCDefinitions::makeDACReadHeader(int chipId, 00103 const std::string& registerName) 00104 { 00105 return makeDACHeader(chipId, registerName, read); 00106 } 00107 00108 //======================================================================================================================== 00109 uint64_t VIPICROCDefinitions::makeDACHeader(int chipId, 00110 const std::string& registerName, 00111 unsigned int instruction) 00112 { 00113 /*Ryan 00114 uint64_t command = 0; 00115 //Insert Chip ID 00116 BitManipulator::insertBits(command,BitManipulator::reverseBits(chipId,0,5),0,5); 00117 //Insert Register Address 00118 BitManipulator::insertBits(command,BitManipulator::reverseBits(getDACRegisterAddress(registerName),0,5),5,5); 00119 //Insert instruction 00120 BitManipulator::insertBits(command,BitManipulator::reverseBits(instruction,0,3),10,3); 00121 */ 00122 uint32_t command = 0x80000000; 00123 uint32_t registerAddress = getDACRegisterAddress(registerName); 00124 // Insert Chip ID 00125 BitManipulator::insertBits(command, chipId, 0, 5); 00126 // Insert Register Address 00127 BitManipulator::insertBits(command, registerAddress, 5, 5); 00128 // Insert instruction 00129 BitManipulator::insertBits(command, instruction, 10, 3); 00130 00131 // Insert mask 00132 // BitManipulator::insertBits(command,0x1,16,8); 00133 unsigned int length = 3; 00134 if(registerAddress < 16 || registerAddress < 27 || registerAddress < 30) 00135 length = 3; 00136 else if(registerAddress == 17 || registerAddress == 18) 00137 length = 4; 00138 else if(registerAddress == 16) 00139 length = 2; 00140 else if(registerAddress == 19 || registerAddress == 20) 00141 length = 1; 00142 // Insert command length 00143 BitManipulator::insertBits(command, length, 24, 7); 00144 00145 return command; 00146 } 00147 00148 //======================================================================================================================== 00149 uint64_t VIPICROCDefinitions::makeDACWriteCommand(int chipId, 00150 const std::string& registerName, 00151 unsigned int valueToWrite) 00152 { 00153 std::cout << __COUT_HDR_FL__ << "Working on Register " << registerName 00154 << " Address: " << getDACRegisterAddress(registerName) 00155 << " Value: " << valueToWrite << std::endl; 00156 uint64_t command = 0; 00157 if(registerName != "SendData" && registerName != "RejectHits") 00158 { 00159 command = makeDACWriteHeader(chipId, registerName); 00160 BitManipulator::insertBits( 00161 command, BitManipulator::reverseBits(valueToWrite, 0, 8), 13, 8); 00162 } 00163 else if(valueToWrite == 1) 00164 command = makeDACSetHeader(chipId, registerName); 00165 else 00166 command = makeDACResetHeader(chipId, registerName); 00167 // BitManipulator::insertBits(command,0x0,13,8);It doesn't matter the value you put in 00168 // if is set or reset! 00169 00170 return command; 00171 } 00172 00173 //======================================================================================================================== 00174 uint64_t VIPICROCDefinitions::makeDACReadCommand(int chipId, 00175 const std::string& registerName) 00176 { 00177 return makeDACHeader(chipId, registerName, read); 00178 } 00179 00180 //======================================================================================================================== 00181 std::string VIPICROCDefinitions::makeMaskWriteCommand(int chipId, 00182 const std::string& registerName, 00183 std::string valueToWrite) 00184 { 00185 std::string command = "0000000000000000000"; 00186 00187 /*Ryan's 00188 //Insert Chip ID 00189 //BitManipulator::insertBits(command,BitManipulator::reverseBits(chipId,0,5),0,5); 00190 BitManipulator::insertBits(command,chipId,0,5); 00191 //Insert Register Address 00192 //BitManipulator::insertBits(command,BitManipulator::reverseBits(getDACRegisterAddress(registerName),0,5),5,5); 00193 BitManipulator::insertBits(command,getDACRegisterAddress(registerName),5,5); 00194 //Insert instruction 00195 //BitManipulator::insertBits(command,writeReversed,10,3); 00196 BitManipulator::insertBits(command,write,10,3); 00197 00198 UInt8 revField = (UInt8)0; 00199 for (unsigned int c=0; c<valueToWrite.length(); c++) 00200 { 00201 if(registerName == "Inject") 00202 revField = !(UInt8)valueToWrite.substr(c,1).data()[0]; 00203 else 00204 revField = (UInt8)valueToWrite.substr(c,1).data()[0]; 00205 //revField = 0x40; 00206 BitManipulator::insertBits(command,(uint64_t)revField,13+c,1); 00207 } 00208 00209 std::cout << __COUT_HDR_FL__ << " std::string made: " << std::endl; 00210 for (int i=0; i<19; i++) 00211 { 00212 std::cout << __COUT_HDR_FL__ << hex << (uint64_t)command.substr(i, 1).data()[0] << 00213 "-" << std::endl; 00214 } 00215 std::cout << __COUT_HDR_FL__ << "\n" << std::endl; 00216 */ 00217 return command; 00218 } 00219 00220 //======================================================================================================================== 00221 uint64_t VIPICROCDefinitions::makeMaskReadCommand(int chipId, 00222 const std::string& registerName) 00223 { 00224 return 0; 00225 } 00226 00227 //======================================================================================================================== 00228 uint64_t VIPICROCDefinitions::setSendData(int chipId) 00229 { 00230 return makeDACWriteCommand(chipId, "SendData", 1); 00231 } 00232 00233 //======================================================================================================================== 00234 uint64_t VIPICROCDefinitions::resetSendData(int chipId) 00235 { 00236 return makeDACWriteCommand(chipId, "SendData", 0); 00237 } 00238 00239 //======================================================================================================================== 00240 uint64_t VIPICROCDefinitions::setRejectHits(int chipId) 00241 { 00242 return makeDACWriteCommand(chipId, "RejectHits", 1); 00243 } 00244 00245 //======================================================================================================================== 00246 uint64_t VIPICROCDefinitions::resetRejectHits(int chipId) 00247 { 00248 return makeDACWriteCommand(chipId, "RejectHits", 0); 00249 }