pit_driver_procFpga.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <iostream>
00004 #include <fstream>
00005 #include <sstream>
00006 #include <exception>
00007 #include <stdexcept>
00008 
00009 #include "pit_driver_procFpga.h"
00010 //_________________________________________________________________________________
00011 pit_driver_procFpga::pit_driver_procFpga( pit_comm *comm_engine){
00012 
00013         // for the moment gets the same logger as the reat of the driver
00014         logProcFpga = &(log4cpp::Category::getInstance("pitLog.driver"));
00015         // assignes the comunication engine
00016         commFEE = comm_engine;
00017 
00018 
00019 }
00020 
00021 //_________________________________________________________________________________
00022 pit_driver_procFpga::~pit_driver_procFpga(){
00023 
00024 }
00025 
00026 //_________________________________________________________________________________
00027 UInt32 pit_driver_procFpga::readReg(UInt28 offset ){
00028         UInt32 reg;
00029 
00030         if (offset > PROC_FPGA_ADDRESS_SPACE){
00031                 logProcFpga->error("(procFpga::readReg) address 0x%x is out of the processing fpga address space", offset);
00032                 throw out_of_range("(procFpga::readReg) error: address out of the processing fpga address space");
00033         }
00034         commFEE->PITReadWord( PROC_FPGA_BASE_ADRESS + offset ,&reg);
00035 
00036         //logProcFpga->info("(procFpga::readReg) register 0x%x read value 0x%x", PROC_FPGA_BASE_ADRESS + offset, reg);
00037         return reg;
00038 }
00039 
00040 //_________________________________________________________________________________
00041 // writes one register in the address space of the processing fpga
00042 void pit_driver_procFpga::writeReg(UInt28 offset, UInt32 value){
00043 
00044         if (offset > PROC_FPGA_ADDRESS_SPACE){
00045                 logProcFpga->error("(procFpga::writedReg) address 0x%x is out of the processing fpga address space", offset);
00046                 throw out_of_range("(procFpga::writeReg) error: address out of the processing fpga address space");
00047         }
00048 
00049         commFEE->PITWriteWord( PROC_FPGA_BASE_ADRESS + offset , value);
00050 
00051 }
00052 //_________________________________________________________________________________
00053 // sets the timer enabled
00054 void pit_driver_procFpga::setTimerEnable(bool value){
00055 
00056         // this will shift the bit value to the most significante value and or it with the current timer period 
00057         UInt32 newValue= (value << 31) | this->readTimerPeriod();
00058         writeReg(PROC_FPGA_TIMER_ENABLE_OFFSET, newValue);
00059 }
00060 //______________________________________________________________________________________________________________
00061 // checks if the timer is enabled
00062 bool pit_driver_procFpga::isTimerEnabled(){
00063 
00064         UInt32 registerValue = readReg(PROC_FPGA_TIMER_ENABLE_OFFSET);
00065         return (registerValue & 0x40000000) >> 31;
00066 
00067 }
00068 //______________________________________________________________________________________________________________
00069 //writes the timer period
00070 void pit_driver_procFpga::writeTimerPeriod(UInt32 period){
00071 
00072         //reads the old timer enable value
00073         UInt32 timerEnValue = readReg(PROC_FPGA_TIMER_ENABLE_OFFSET) & 0xC0000000;
00074 
00075         //like this is cleans also the input period
00076         UInt32 registerValue = timerEnValue | (period & 0x3fffffff);
00077         writeReg(PROC_FPGA_TIMER_ENABLE_OFFSET, registerValue);
00078 
00079 }
00080 //______________________________________________________________________________________________________________
00081 // reads one time stamp
00082 UInt32 pit_driver_procFpga::readTimeStamp(unsigned int channel,unsigned int timeStamp){
00083 
00084         UInt28 address = PROC_FPGA_TIME_STAMP_OFFSET + channel*PROC_FPGA_TIME_STAMP_REG_NUMBER + timeStamp;
00085 
00086         return readReg(address);
00087 }
00088 //______________________________________________________________________________________________________________
00089 //reads a generic counter
00090 UInt32 pit_driver_procFpga::readCounterInGroup(unsigned int group,unsigned int counter ){
00091 
00092         if ( (group >= NUMBER_OPTIN) || (counter >= PROC_FPGA_N_GEN_COUNTERS) ){
00093                 logProcFpga->error("(procFpga::readCounterInGroup) out of range: group and counter %d,%d have to be smaller than %d,%d", 
00094                                 group, counter, NUMBER_OPTIN, PROC_FPGA_N_GEN_COUNTERS);
00095                 throw out_of_range("(procFpga::readCounterInGroup) counter out of range");
00096         }
00097 
00098         UInt28 address = PROC_FPGA_COUNTER_GROUP_OFFSET+ group*PROC_FPGA_COUNTER_GROUP_REGISTERS + counter;
00099 
00100         return readReg(address);
00101 }
00102 //______________________________________________________________________________________________________________
00103 void pit_driver_procFpga::writeMaxCounter(unsigned int counter, UInt32 value){ 
00104         if (counter >= NUMBER_OPTIN){
00105                 logProcFpga->error("(procFpga::writeMaxCounter) out of range: max counter %d has to be smaller than %d", counter, NUMBER_OPTIN);
00106                 throw out_of_range("(procFpga::writeMaxCounter) counter out of range");
00107         }
00108         writeReg(PROC_FPGA_MAX_COUNTER_OFFSET+counter, value);
00109 }
00110 //______________________________________________________________________________________________________________
00111 //reads one status register
00112 UInt32 pit_driver_procFpga::readStatusRegister(unsigned int regNumber){
00113         if (regNumber >= NUMBER_OPTIN){
00114                 logProcFpga->error("(procFpga::readStatusRegister) out of range: status register  %d has to be smaller than %d", regNumber, NUMBER_OPTIN);
00115                 throw out_of_range("(procFpga::readStatusRegister) status register out of range");
00116         }
00117         return readReg( PROC_FPGA_STATUS_OFFSET+regNumber);
00118 }
00119 //______________________________________________________________________________________________________________
00120 //reads the settings register of one output
00121 UInt32 pit_driver_procFpga::readSettingRegister(unsigned int regNumber){
00122         if (regNumber >= NUMBER_OPTIN){
00123                 logProcFpga->error("(procFpga::readSettingRegister) out of range: settings register %d has to be smaller than %d", regNumber, NUMBER_OPTIN);
00124                 throw out_of_range("(procFpga::readSettingRegister) settings register out of range");
00125         }
00126         return readReg( PROC_FPGA_SETTING_OFFSET+regNumber);
00127 }
00128 //______________________________________________________________________________________________________________
00129 //writes the settings register of one output
00130 void pit_driver_procFpga::writeSettingRegister(unsigned int regNumber, UInt32 value){ 
00131         if (regNumber >= NUMBER_OPTIN){
00132                 logProcFpga->error("(procFpga::writeSettingRegister) out of range: settings register %d has to be smaller than %d", regNumber, NUMBER_OPTIN);
00133                 throw out_of_range("(procFpga::writeSettingRegister) settings register out of range");
00134         }
00135         writeReg(PROC_FPGA_SETTING_OFFSET+regNumber, value);    
00136 }
00137 //______________________________________________________________________________________________________________
00138 //writes the signature of one output
00139 void pit_driver_procFpga::writeSignature(unsigned int signature, UInt32 value){
00140         if (signature >= NUMBER_OPTIN){
00141                 logProcFpga->error("(procFpga::writeSignature) out of range: signature register %d has to be smaller than %d", signature, NUMBER_OPTIN);
00142                 throw out_of_range("(procFpga::writeSignature) signature register out of range");
00143         }
00144         writeReg(PROC_FPGA_SIGNATURE_OFFSET+signature, value);
00145 }
00146 //______________________________________________________________________________________________________________
00147 //reads one signature 
00148 UInt32 pit_driver_procFpga::readSignature(unsigned int signature){
00149 
00150         if (signature >= NUMBER_OPTIN){
00151                 logProcFpga->error("(procFpga::readSignature) out of range: signature register %d has to be smaller than %d", signature, NUMBER_OPTIN);
00152                 throw out_of_range("(procFpga::readSignature) signature register out of range");
00153         }
00154 
00155         return readReg(PROC_FPGA_SIGNATURE_OFFSET+signature);
00156 }
00157 //______________________________________________________________________________________________________________
00158 //writes the random perios set to one output
00159 void pit_driver_procFpga::writeRandomPeriod(unsigned int period, UInt32 value){
00160         if (period >= NUMBER_OPTIN){
00161                 logProcFpga->error("(procFpga::writeRandomPeriod) out of range: random period register %d has to be smaller than %d", period, NUMBER_OPTIN);
00162                 throw out_of_range("(procFpga::writeRandomPeriod) random period register out of range");
00163         }
00164 
00165         writeReg(PROC_FPGA_RANDOM_PERIOD_OFFSET+period, value);
00166 }
00167 //______________________________________________________________________________________________________________
00168 //reads the random period set for one output
00169 UInt32 pit_driver_procFpga::readRandomPeriod(unsigned int period){
00170         if (period >= NUMBER_OPTIN){
00171                 logProcFpga->error("(procFpga::readRandomPeriod) out of range: random period register %d has to be smaller than %d", period, NUMBER_OPTIN);
00172                 throw out_of_range("(procFpga::readRandomPeriod) random period register out of range");
00173         }
00174         
00175         return readReg(PROC_FPGA_RANDOM_PERIOD_OFFSET + period);
00176 }
00177 //______________________________________________________________________________________________________________
00178 //reads an output counter
00179 UInt32 pit_driver_procFpga::readCounter(unsigned int counter){
00180         if (counter >= NUMBER_OPTIN){
00181                 logProcFpga->error("(procFpga::readCounter) out of range: output counter register %d has to be smaller than %d", counter, NUMBER_OPTIN);
00182                 throw out_of_range("(procFpga::readCounter) output counter register register out of range");
00183         }
00184 
00185         return readReg(PROC_FPGA_COUNTER_OUTPUT_OFFSET + counter);
00186 }
00187 //______________________________________________________________________________________________________________
00188 // writes an output counter
00189 void pit_driver_procFpga::writeCounter(unsigned int counter, UInt32 value){
00190         if (counter >= NUMBER_OPTIN){
00191                 logProcFpga->error("(procFpga::writeCounter) out of range: output counter register %d has to be smaller than %d", counter, NUMBER_OPTIN);
00192                 throw out_of_range("(procFpga::writeCounter) output counter register register out of range");
00193         }
00194 
00195         writeReg(PROC_FPGA_COUNTER_OUTPUT_OFFSET+counter, value);
00196 }
00197 
00198 //______________________________________________________________________________________________________________
00199 // writes the minimum counter of one output
00200 void pit_driver_procFpga::writeMinCounter(unsigned int counter, UInt32 value){ 
00201         
00202         if (counter >= NUMBER_OPTIN){
00203                 logProcFpga->error("(procFpga::writeMinCounter) out of range: min counter register %d has to be smaller than %d", counter, NUMBER_OPTIN);
00204                 throw out_of_range("(procFpga::writeMinCounter) min counter register register out of range");
00205         }
00206         writeReg(PROC_FPGA_MIN_COUNTER_OFFSET+counter, value);
00207 }
00208 //______________________________________________________________________________________________________________
00209 //reads the minimum counter of one output
00210 UInt32 pit_driver_procFpga::readMinCountert(unsigned int counter){
00211         if (counter >= NUMBER_OPTIN){
00212                 logProcFpga->error("(procFpga::readMinCountert) out of range: min counter register %d has to be smaller than %d", counter, NUMBER_OPTIN);
00213                 throw out_of_range("(procFpga::readMinCountert) min counter register register out of range");
00214         }
00215         return readReg(PROC_FPGA_MIN_COUNTER_OFFSET + counter);
00216 }
00217 //______________________________________________________________________________________________________________
00218 //reads the max counter of one output
00219 UInt32 pit_driver_procFpga::readMaxCounter(unsigned int counter){
00220         if (counter >= NUMBER_OPTIN){
00221                 logProcFpga->error("(procFpga::readMaxCounter) out of range: max counter register %d has to be smaller than %d", counter, NUMBER_OPTIN);
00222                 throw out_of_range("(procFpga::readMaxCounter) max counter register register out of range");
00223         }
00224         return readReg(PROC_FPGA_MAX_COUNTER_OFFSET + counter);
00225 }
00226 //______________________________________________________________________________________________________________
00227 // reads the mode of one output
00228 pit_trigger_mode pit_driver_procFpga::readTriggerMode(unsigned int output){
00229         if (output >= NUMBER_FO_CHANNELS){
00230                 logProcFpga->error("(procFpga::readTriggerMode)error output index as to be smaller than 10");
00231                 throw out_of_range ("(procFpga::readTriggerMode)error output index as to be smaller than 10");
00232         }
00233         
00234                 // reads the modes register
00235         UInt32 modes= readReg(PROC_FPGA_OUTPUT_MODE_OFFSET);
00236                 // extracts the 2 bits of this mode
00237         pit_trigger_mode out= (pit_trigger_mode)extractFromUInt32(2*output,2,modes);
00238         return out;
00239 }
00240 //______________________________________________________________________________________________________________
00241 // writes the mode of one output
00242 void pit_driver_procFpga::writeTriggerMode(unsigned int output, pit_trigger_mode value){
00243         
00244         if (output >= NUMBER_FO_CHANNELS){
00245                 logProcFpga->error("(procFpga::writeTriggerMode)error output index as to be smaller than 10");
00246                 throw out_of_range ("(procFpga::writeTriggerMode)error output index as to be smaller than 10");
00247         }
00248                 // reads the modes register
00249         UInt32 modes= readReg(PROC_FPGA_OUTPUT_MODE_OFFSET);
00250                 // inserts the bits generating a new value
00251         UInt32 newValue=insertIntoUInt32( 2*output,2,value,modes);
00252         writeReg(PROC_FPGA_OUTPUT_MODE_OFFSET, newValue);
00253         
00254 }
00255 
00256 //______________________________________________________________________________________________________________
00257 // writes the mode of one output using a string as an input
00258 void pit_driver_procFpga::writeTriggerMode(unsigned int output, const string &mode){
00259         pit_trigger_mode outMode;
00260         
00261         if (mode=="normal")             outMode = Trigger_Normal;
00262         else if (mode=="toggle")        outMode = Trigger_Toggle;
00263         else if (mode=="signature") outMode = Trigger_Signature;
00264         else if (mode=="random")        outMode = Trigger_Random;
00265         else {
00266                 logProcFpga->error("(procFpga::writeTriggerMode)error: mode as to be normal, toggle, signature or random");
00267                 throw out_of_range("(procFpga::writeTriggerMode)error: mode as to be normal, toggle, signature or random");
00268         }
00269         
00270         writeTriggerMode(output, outMode);
00271 }
00272 //______________________________________________________________________________________________________________
00273 // reads the mode of one output
00274 std::string pit_driver_procFpga::readStrTriggerMode(unsigned int output){
00275         
00276                 // reads the modes register
00277         pit_trigger_mode mode = readTriggerMode(output);
00278 
00279         switch(mode){
00280         case Trigger_Normal: return "normal";
00281         case Trigger_Toggle: return "toggle";
00282         case Trigger_Signature: return "signature";
00283         case Trigger_Random: return "random";
00284                         
00285         }
00286         return "";
00287 }
00288 

Generated on Sat Mar 29 22:55:55 2008 for pixelTrigger by  doxygen 1.5.0