pit_driver_optinBoard.cpp

Go to the documentation of this file.
00001 #include "pit_driver_optinBoard.h"
00002 #include "pit_driver_opticalLink.h"
00003 #include <iostream>
00004 #include <fstream>
00005 #include <sstream>
00006 #include <exception>
00007 #include <stdexcept>
00008 //_________________________________________________________________________________
00009 pit_driver_optinBoard::pit_driver_optinBoard(unsigned int p_boardNumber, pit_comm *comm_engine)
00010 {
00011 unsigned int i;
00012 
00013     logDriverOptin = &(log4cpp::Category::getInstance("pitLog.driver")); 
00014     //logDriverOptin->info("(pit_driver_optinBoard::pit_driver_optinBoard()): constructor of optinBoard object number %d",p_boardNumber);
00015       // initialize boardNumber
00016     boardNumber = p_boardNumber;
00017       // intitialize baseAddress
00018     baseAddress = OPTIN_BOARDS_BASE_ADDRESS + boardNumber*OPTIN_BOARDS_OFFSET;
00019       // initialize pointer to communication engine
00020      commFEE = comm_engine;
00021       // check if optin board is plugged
00022     checkBoardPlugged();
00023 
00024         // create 12 instances of pit_driver_opticalLink to model the twelve links on the OPTIN board.
00025         // these ojects are like "child" object of the optinBoard instance
00026         for (i = 0; i < NUMBER_OPTICAL_LINKS; i++) {
00027             // instantiating child objects
00028            opticalLink[i] = new pit_driver_opticalLink( i, commFEE , this);  //[1]. passing pointer to this (parent) object
00029         }/* end for */
00030     
00031 }// end of pit_driver_optinBoard
00032 //_________________________________________________________________________________
00033 pit_driver_optinBoard::~pit_driver_optinBoard(void)
00034 {
00035 unsigned int i;
00036       // reminder: destructor must release momory allocated for instances created and belonging to this object
00037       // in other words it has to call destructors of child objects instantied at moment of construction. 
00038       // This should be done like stg like the following
00039  
00040     for (i=0; i < NUMBER_OPTICAL_LINKS; i++) {
00041           // calling destructors for all child objects and realeasing memory destructors of children are called and in their turn they call destructors of their children
00042         delete opticalLink[i];
00043     }/* end for */
00044    
00045 }// end of pit_driver_optinBoard
00046 //_________________________________________________________________________________
00047 /******************************************************************************
00048 * Name : checkBoardPlugged                                                    *
00049 * Function : check if optin board is plugged and update class data member :   *
00050 *            fpgaVersion                                                      *
00051 * Input : optinCard: optin card number <0;9>                                  *
00052 * Output : none                                                               *
00053 * Revisions:  cesar 22/01/2008  added the try catch block after changes           *
00054 * in the comm layer                                                                                               *
00055 *  DATE     AUTHOR            NOTES                                           *
00056 * 20071123  Gianluca Aglieri  creation                                        *
00057 ******************************************************************************/
00058 void pit_driver_optinBoard::checkBoardPlugged(void)// returns SUCCESS in case of an answer from a given OPTIN board, this is then 
00059 {
00060         
00061         UInt32 version;
00062         UInt28 address = baseAddress + OPTIN_BOARDS_FWVERSION_OFFSET;
00063                         
00064         try {
00065                                                 // it will read the optin board firmware version
00066                 commFEE->PITReadWord(address,&version);
00067                 logDriverOptin->info("(pit_driver_optinBoard::checkBoardPlugged()): Optin board %d, base address 0x%x, correctly answered with version %d", boardNumber, address, version);
00068                 fpgaVersion = version;
00069                 this->boardPlugged=true;
00070                 
00071         }
00072         
00073         catch(exception& except){
00074                 logDriverOptin->error("(pit_driver_optinBoard::checkBoardPlugged()): Failed to access optin board %d, base address 0x%x, board marked as not plugged", boardNumber, address);
00075                 fpgaVersion = -1;
00076                 this->boardPlugged= false;
00077                 
00078                 // calling method to reset and refresh communication status and services
00079                 commFEE->PITCheckCommStatus();
00080                                 
00081         }
00082 }
00083 //_________________________________________________________________________________
00084 // function to refresh all menbers and services of one optin board
00085 int pit_driver_optinBoard::refresh(){
00086         //this->checkBoardPlugged();
00087         this->refreshOptinStatus();
00088         this->refreshOptinSetting();
00089         this->refreshStatusServices();
00090         return 0;
00091 }
00092 
00093 //_________________________________________________________________________________
00099 pit_driver_opticalLink& pit_driver_optinBoard::getOpticalLink(unsigned int linkNum)  { 
00100   if (linkNum >= NUMBER_OPTICAL_LINKS ){
00101     logDriverOptin->error("(pit_driver_optinBoard::getOpticalLink): opticalLink %d out of range, board %d", linkNum, boardNumber);
00102     throw out_of_range("Exception from (pit_driver_optinBoard::getOpticalLink), linkNum out of range");
00103   }
00104   else{
00105     return *opticalLink[linkNum];
00106   }
00107 }
00108 //_________________________________________________________________________________
00109 UInt32 pit_driver_optinBoard::readOptinStatus()  {
00110   UInt32 status;
00111   UInt28 address= baseAddress + OPTIN_BOARDS_STATUS_OFFSET;
00112   commFEE->PITReadWord( address,&status);
00113   return status;
00114 }
00115 //_________________________________________________________________________________
00116 void pit_driver_optinBoard::refreshStatusServices(void) {
00117   // updates services
00118 }
00119 //_________________________________________________________________________________
00120 UInt32 pit_driver_optinBoard::readOptinSetting()  {
00121   UInt32 setting;
00122   UInt28 address = baseAddress + OPTIN_BOARDS_SETTING_OFFSET;
00123   commFEE->PITReadWord(address,&setting);
00124   return setting;
00125 }
00126 //_________________________________________________________________________________
00127 UInt32 pit_driver_optinBoard::writeOptinSetting(UInt32 p_optinSetting) {
00128   UInt28 address = baseAddress + OPTIN_BOARDS_SETTING_OFFSET;
00129   return commFEE->PITWriteWord(address,p_optinSetting);
00130 }
00131 //_________________________________________________________________________________
00132 UInt32 pit_driver_optinBoard::writeOptinCommand(UInt32 p_optinCommand) {
00133   UInt28 address = baseAddress + OPTIN_BOARDS_COMMAND_OFFSET;
00134   return commFEE->PITWriteWord(address,p_optinCommand);
00135 }
00136 //_________________________________________________________________________________
00137 // SHOULD THIS REALLY BE HERE???
00138 UInt12 pit_driver_optinBoard::refreshLinkStatus(void) {
00139   return 0;
00140 }
00141 //_________________________________________________________________________________
00142 inline unsigned int pit_driver_optinBoard::getOptinFirmwareVersion() {
00143   return fpgaVersion;
00144 }
00145 //_________________________________________________________________________________
00146 unsigned int pit_driver_optinBoard::readOptinFirmwareVersion() {
00147   UInt32 version;
00148   UInt28 address = baseAddress + OPTIN_BOARDS_FWVERSION_OFFSET;
00149   commFEE->PITReadWord(address,&version);
00150   return version;
00151 }
00152 //_________________________________________________________________________________
00153 UInt32 pit_driver_optinBoard::refreshOptinStatus(void) {
00154   UInt32 status = readOptinStatus();
00155   return status;
00156 }
00157 //_________________________________________________________________________________
00158 UInt32 pit_driver_optinBoard::refreshOptinSetting(void) {
00159   UInt32 setting = readOptinSetting();
00160   return setting;
00161 }
00162 //_________________________________________________________________________________
00163 UInt32 pit_driver_optinBoard::readTimeStamp(int p_timeStampNumber)  {
00164   if (p_timeStampNumber>2) {
00165     logDriverOptin->error("(pit_driver_optinBoard::readTimeStamp()) for OPTIN board number %i, readTimeStamp(%d) out of range", boardNumber, p_timeStampNumber);
00166     return 0;
00167   }
00168   else {
00169     UInt32 timeStamp;
00170     UInt28 address = baseAddress + OPTIN_BOARDS_TIMESTAMP_OFFSET + p_timeStampNumber;
00171     commFEE->PITReadWord(address,&timeStamp);
00172     return timeStamp;
00173   }
00174 }
00175 //_________________________________________________________________________________
00176 int pit_driver_optinBoard::readMinFastorCounts(int layer, int chip)  {
00177   if (layer<0 || layer>1 || chip<0 || chip>9) {
00178     logDriverOptin->error("(pit_driver_optinBoard::readMinFastorCounts(int layer, int chip)): for OPTIN board number %i, layer=%d chip=%d out of range", boardNumber, layer, chip);
00179     return 0;
00180   }
00181   else {
00182     UInt32 counts;
00183     UInt28 address = baseAddress + OPTIN_BOARDS_MINFOCOUNTS_OFFSET + layer*20 + chip;
00184     commFEE->PITReadWord(address,&counts);
00185     return counts;
00186   }
00187 }
00188 //_________________________________________________________________________________
00189 int pit_driver_optinBoard::writeMinFastorCounts(int layer, int chip, unsigned int minCounts)  {
00190   if (layer<0 || layer>1 || chip<0 || chip>9) {
00191     logDriverOptin->error("(pit_driver_optinBoard::writeMinFastorCounts(int layer, int chip, unsigned int minCounts)): for OPTIN board number %i, layer=%d, chip=%d out of range", boardNumber, layer, chip);
00192     return 0;
00193   }
00194   else {
00195     UInt28 address = baseAddress + OPTIN_BOARDS_MINFOCOUNTS_OFFSET + layer*20 + chip;
00196     return commFEE->PITWriteWord(address,minCounts);
00197   }
00198 }
00199 //_________________________________________________________________________________
00200 int pit_driver_optinBoard::readMaxFastorCounts(int layer, int chip)  {
00201   if (layer<0 || layer>1 || chip<0 || chip>9) {
00202     logDriverOptin->error("(pit_driver_optinBoard:readMaxFastorCounts(int layer, int chip)): for OPTIN board number %i, layer=%d, chip=%d out of range", boardNumber, layer, chip);
00203     return 0;
00204   }
00205   else {
00206     UInt32 counts;
00207     UInt28 address = baseAddress + OPTIN_BOARDS_MINFOCOUNTS_OFFSET + 10 + layer*20 + chip;
00208     commFEE->PITReadWord(address,&counts);
00209     return counts;
00210   }
00211 }
00212 //_________________________________________________________________________________
00213 int pit_driver_optinBoard::writeMaxFastorCounts(int layer, int chip, unsigned int maxCounts)  {
00214   if (layer<0 || layer>1 || chip<0 || chip>9) {
00215     logDriverOptin->error("(pit_driver_optinBoard::writeMaxFastorCounts(int layer, int chip, unsigned int maxCounts)): for OPTIN board number %i, layer=%d, chip=%d out of range", boardNumber, layer, chip);
00216     return 0;
00217   }
00218   else {
00219     UInt28 address = baseAddress + OPTIN_BOARDS_MINFOCOUNTS_OFFSET + 10 + layer*20 + chip;
00220     return commFEE->PITWriteWord(address,maxCounts);
00221   }
00222 }

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