pit_comm.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <sstream>
00004 #include "pit_comm.h"
00005 #include "pit_comm_exception.h"
00006 
00007 
00008 using namespace std;
00009 
00010 #define MAX_PHYSMEM (1024*1024*8)
00011 
00012 pit_comm::pit_comm(void)
00013 {
00014     logCom = &(log4cpp::Category::getInstance("pitLog.comm")); 
00015     logCom->info("(pit_comm::pit_comm()): Starting communication layer");
00016 
00017     // Initializing data members
00018     rorcStatus = R_NOT_OPEN_ERR;
00019     DDLLinkStatus = FAILURE;
00020     controlFPGAAnswers = FAILURE;
00021     
00022     // Registering DIM service
00023     const string serviceCommunicationStatusName("COMMUNICATION_STATUS");
00024     serviceCommunicationStatus = new DimService(serviceCommunicationStatusName.c_str(), controlFPGAAnswers);
00025          
00026     rorc = get_channel(RORC_REVISION, RORC_SERIAL, RORC_CHANNEL);
00027     
00028     // if rorc handler is valid, reset siu and check access to the hardware
00029     if(rorc->status == R_OPEN) {
00030         rorcStatus = R_OPEN;
00031         logCom->info("(pit_comm::PITCheckCommStatus()): RORC handler valid");
00032         PITCheckCommStatus();
00033     } 
00034     else { 
00035         rorcStatus = rorc->err; 
00036         logCom->error("(pit_comm::pit_comm()): Could not open rorc device : minor=%i channel=%i err=%i", rorc->minor, rorc->channel, rorc->err);
00037     }/* end if */
00038 
00039 }/* end pit_comm */
00040 
00041 
00042 pit_comm::~pit_comm(void)
00043 {
00044         // reset and close the fec2rorc channel if opened
00045          if(rorc->status == R_OPEN) {
00046                 PITrorcReset();
00047                 release_channel(rorc);
00048          } 
00049 }/* end ~pit_comm */
00050 
00051 
00052 
00053 /* let me see some more 
00054  function to check the comunication status */
00055 bool pit_comm::PITCheckCommStatus()
00056 {
00057         
00058         
00059         if (rorcStatus == R_OPEN) {
00060                 PITrorcReset(); // resetting comm layer
00061                 logCom->info("(pit_comm::PITCheckCommStatus()): Checking communication to PIT hardware");
00062                 
00063                 try{
00064                         int output;
00065                         
00066                         output = ddl_statusReadout(rorc, PIT_GET_VERSION); // try access the pit hardware by asking control firmware version
00067                         
00068                         if (output< 0) { // negative return value means some problem, analyze return value to help determining the problem
00069                             PITDecodeRORCError(output, "(PITCheckCommStatus) : ");
00070                         }/*end if */
00071                             
00072                         DDLLinkStatus = SUCCESS;
00073                         controlFPGAAnswers = true;
00074                         serviceCommunicationStatus->updateService();
00075                         
00076                         logCom->info("(pit_comm::PITCheckCommStatus()): Communication OK, RORC-SIU link OK, control FPGA answered with version number: %i", output);
00077                         return true;
00078                 }
00079             catch(...){
00080                 DDLLinkStatus = FAILURE;
00081                 controlFPGAAnswers = FAILURE;
00082                 serviceCommunicationStatus->updateService();
00083                 logCom->error("(pit_comm::PITCheckCommStatus()): Communication to PIT failed. Check hardware and optical links" );
00084                 return false;
00085             }
00086         }
00087         else {
00088                         DDLLinkStatus = FAILURE;
00089                         controlFPGAAnswers = FAILURE;
00090                         serviceCommunicationStatus->updateService();
00091                         logCom->error("(pit_comm::PITCheckCommStatus()): Can not access SIU and RORC, invalid RORC handler");
00092                         return false;           
00093                 }
00094    
00095 
00096 }// end PITCheckCommStatus;
00097 
00098 
00099 
00100 // resets the rorc channel
00101 int pit_comm::PITrorcReset(){
00102         
00103         if (rorcStatus == R_OPEN) {
00104                 rorc_pci_dev_t * device = &rorc->rorc;
00105 
00106                 // resets siu and the rorc
00107                 rorcReset(device, RORC_RESET_SIU | RORC_RESET_RORC);
00108         
00109                 this->logCom->info("(pit_comm::PITrorcReset()): Resetting SIU and RORC");
00110                 return 0;
00111         }
00112         else {
00113                 this->logCom->error("(pit_comm::PITrorcReset()): Can not reset SIU and RORC, invalid RORC handler");
00114                 return -1;              
00115         }
00116 
00117         // this piece of code was build looking at the siu_reset.c, looks like it is easier in the rorcReset funtionality
00118                 // number of trials to try to reset
00119 //      int trials = 3;
00120 //      int print = 1; // it will print the status to screen
00121 //      long long int time = DDL_RESPONSE_TIME * device->loop_per_usec;
00122         
00123 //      output =ddlResetSiu( device, print,trials,time  );
00124 //      if (output < 0 ){
00125 //              // error condition here cannot be the decode error can create a infinte loop
00126 //              // another error condition as to be defined  
00127 //              //PITDecodeComError(output, "(PITrorcReset)dllResetSiu : ");
00128 //      }
00129 }
00130 
00131  
00137 void pit_comm::PITDecodeRORCError(int rorcError, const char *extraMsg) {
00138  
00139         string srcMsg(extraMsg);
00140         logCom->error(srcMsg); // log an error message containing the name of the failing function that called this one
00141 
00142         
00143         stringstream errorMsgStream;
00144         errorMsgStream  << "(pit_comm::PITDecodeRORCError) Communication problem, RORC returned DDL error number " 
00145                                     <<  rorcError << " : ";
00146         
00147         string errorMsg(errorMsgStream.str());
00148                 
00149  switch ( rorcError ) {
00150 
00151   case RORC_LINK_NOT_ON :
00152     DDLLinkStatus = FAILURE;
00153     controlFPGAAnswers = FAILURE;
00154     errorMsg+="RORC-SIU Link DOWN. Check pit hardware powering and clocking.";
00155     break;
00156 
00157   case RORC_TIMEOUT : 
00158     DDLLinkStatus = SUCCESS;
00159     controlFPGAAnswers = FAILURE;
00160     errorMsg+="RORC timeout error, could not TRANSMIT command before timeout.";        
00161     break;
00162 
00163   case  RORC_TOO_MANY_REPLY : 
00164     DDLLinkStatus = SUCCESS;
00165     controlFPGAAnswers = FAILURE;
00166     errorMsg+="too many replies error. Check control FPGA configuration.";        
00167     break;
00168 
00169   case  RORC_NOT_ENOUGH_REPLY : 
00170     DDLLinkStatus = SUCCESS;
00171     controlFPGAAnswers = FAILURE;
00172     errorMsg+="not enough replies in timeout interval. Check control FPGA configuration.";
00173     break;
00174 
00175   default : 
00176     DDLLinkStatus = FAILURE;
00177     controlFPGAAnswers = FAILURE;
00178     errorMsg+="unknown error code. Ask DDL-RORC-SIU maintainers.";        
00179  }      
00180  
00181  logCom->error(errorMsg);       // log error message containing the number of the error and the decoding
00182  
00183  //PITrorcReset();                      // reset RORC and SIU                   
00184  
00185  throw pit_comm_exception( errorMsg);
00186  
00187 }// end of PITDecodeRORCError
00188 
00189 
00190 void pit_comm::PITDecodeComError(int comError, const char * extraMsg){
00191         string errorMsg(extraMsg);
00192         switch(comError){
00193                 case ERROR_PROTOCOL_DATALENGTH:
00194                         errorMsg+="writeBlock: bad length comparison";
00195                         break;
00196                 case ERROR_BAD_REGISTER_WRITE:
00197                         errorMsg+= "Bad register Write";
00198                         break;
00199                 case ERROR_PARITY_CHECK:
00200                         errorMsg+= "parity error";
00201                         break;
00202                 case ERROR_GENERIC_BUS_STATUS:
00203                         errorMsg+= "generic bus status error";
00204                         break;
00205                 default:
00206                         stringstream str;
00207                         str << "Unknow pit_comm error code: " << comError; 
00208                         errorMsg+=str.str();
00209         }
00210         
00211         logCom->error(errorMsg);
00212         throw pit_comm_exception(errorMsg);
00213 }
00214 
00215 /******************************************************************************
00216 * Name : PITGetRdA                                                            *
00217 * Function : get read address from register                                   *
00218 * Output : read address if >=0 else negative output on rorc error             *
00219 * Revisions:                                                                                                                              *
00220 *  DATE     AUTHOR            NOTES                                           *
00221 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00222 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00223 ******************************************************************************/
00224 
00225 int pit_comm::PITGetRdA()
00226 {
00227 unsigned int rd_a_lsb;
00228 unsigned int rd_a_msb;
00229 int output;
00230 
00231     output = ddl_statusReadout(rorc,  PIT_GET_RDA_LSB);
00232     if (output < 0){
00233         PITDecodeRORCError(output, "(PITGetRdA) PIT_GET_RDA_LSB :" );
00234         return output;
00235     }
00236     
00237     rd_a_lsb = output & 0x7ffff;           // rd_a[18..0]
00238     output = ddl_statusReadout(rorc,  PIT_GET_RDA_MSB);
00239     
00240     if (output< 0){
00241         PITDecodeRORCError(output, "(PITGetRdA) PIT_GET_RDA_MSB :" );
00242         return output;
00243     }
00244     
00245     rd_a_msb = output & 0x1ff;         // rd_a[27..19] 
00246     output = (rd_a_msb << 19) | rd_a_lsb;      // rd_a
00247     
00248     return(output);
00249 }/* PITGetRdA */
00250 
00251 
00252 /******************************************************************************
00253 * Name : PITGetWrA                                                            *
00254 * Function : get write address from register                                  *
00255 * Output : write address if >=0 else negative output on rorc error            *
00256 * Revisions:                                                                  *
00257 *  DATE     AUTHOR            NOTES                                           *
00258 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00259 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00260 ******************************************************************************/
00261 int pit_comm::PITGetWrA()
00262 {
00263 unsigned int wr_a_lsb;
00264 unsigned int wr_a_msb;
00265 int output;
00266 
00267     output = ddl_statusReadout(rorc, PIT_GET_WRA_LSB);
00268     if (output< 0){
00269         PITDecodeRORCError(output, "(PITGetWrA) PIT_GET_WRA_LSB :");
00270         return output;
00271     }
00272    
00273     wr_a_lsb = output & 0x7ffff;           // wr_a[18..0]
00274     output = ddl_statusReadout(rorc, PIT_GET_WRA_MSB);
00275     if (output< 0){
00276         PITDecodeRORCError(output,"(PITGetWrA) PIT_GET_WRA_MSB :");
00277         return output;
00278     }
00279     wr_a_msb = output & 0x1ff;         // wr_a[27..19] 
00280     output = (wr_a_msb << 19) | wr_a_lsb;      // wd_a
00281 
00282     return(output);
00283 }/* end PITGetWrA */
00284 
00285 
00286 /******************************************************************************
00287 * Name : PITGetLen                                                            *
00288 * Function : get length from register                                         *
00289 * Output : length if >=0 else negative output on rorc error                   *
00290 * Revisions:                                                                  *
00291 *  DATE     AUTHOR            NOTES                                           *
00292 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00293 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00294 ******************************************************************************/
00295 int pit_comm::PITGetLen()
00296 {
00297 int output;
00298 
00299     output = ddl_statusReadout(rorc, PIT_GET_LEN);
00300     if(output >= 0) output = output & 0x7ffff;    // len_[18..0] 
00301     else PITDecodeRORCError(output, "(PITGetLen):");
00302     return(output);
00303 }/* end PITGetLen */
00304 
00305 
00306 /******************************************************************************
00307 * Name : PITGetRdLen                                                          *
00308 * Function : get read length from register                                    *
00309 * Output : read length if >=0 else negative output on rorc error              *
00310 * Revisions:                                                                  *
00311 *  DATE     AUTHOR            NOTES                                           *
00312 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00313 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00314 ******************************************************************************/
00315 int pit_comm::PITGetRdLen()
00316 {
00317 int output;
00318 
00319     output = ddl_statusReadout(rorc, PIT_GET_RD_LEN);
00320     if(output >=0) output = output & 0x7ffff;
00321     else PITDecodeRORCError(output, "(PITGetRdLen)");
00322     return(output);
00323 }/* end PITGetRdLen */
00324 
00325 
00326 /******************************************************************************
00327 * Name : PITGetWrLen                                                          *
00328 * Function : get write length from register                                   *
00329 * Output : write length if >=0 else negative output on rorc error             *
00330 * Revisions:                                                                  *
00331 *  DATE     AUTHOR            NOTES                                           *
00332 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00333 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00334 ******************************************************************************/
00335 int pit_comm::PITGetWrLen()
00336 {
00337 int output;
00338 
00339     output = ddl_statusReadout(rorc, PIT_GET_WR_LEN);
00340     if(output >= 0) output = output & 0x7ffff;
00341     else PITDecodeRORCError(output, "(PITGetWrLen) : "); 
00342     return(output);
00343 }/* end PITGetWrLen */
00344 
00345 
00346 /******************************************************************************
00347 * Name : PITGetControl0                                                       *
00348 * Function : get control0 value from register                                 *
00349 * Output : control0 value if >=0 else negative output on rorc error           *
00350 * Revisions:                                                                  *
00351 *  DATE     AUTHOR            NOTES                                           *
00352 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00353 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00354 ******************************************************************************/
00355 int pit_comm::PITGetControl0()
00356 {
00357 int output;
00358 
00359     output = ddl_statusReadout(rorc, PIT_GET_CONTROL0);
00360     if(output >= 0) output = output & 0xff;
00361     else PITDecodeRORCError(output, "(PITGetControl0) : "); 
00362     return(output);
00363 }/* end PITGetControl0 */
00364 
00365 
00366 /******************************************************************************
00367 * Name : PITGetControl1                                                       *
00368 * Function : get control1 value from register                                 *
00369 * Output : control1 value if >=0 else negative output on rorc error           *
00370 * Revisions:                                                                  *
00371 *  DATE     AUTHOR            NOTES                                           *
00372 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00373 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00374 ******************************************************************************/
00375 int pit_comm::PITGetControl1()
00376 {
00377 int output;
00378 
00379     output = ddl_statusReadout(rorc, PIT_GET_CONTROL1);
00380     if(output >=0) output = output & 0xff;
00381     else PITDecodeRORCError(output,  "(PITGetControl1) : "); 
00382     return(output);
00383 }/* end PITGetControl1 */
00384 
00385 
00386 /******************************************************************************
00387 * Name : PITGetVersion                                                        *
00388 * Function : get firmware version  from register                              *
00389 * Output : firmware version if >=0 else negative output on rorc error         *
00390 * Revisions:                                                                  *
00391 *  DATE     AUTHOR            NOTES                                           *
00392 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00393 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00394 ******************************************************************************/
00395 int pit_comm::PITGetVersion()
00396 {
00397 int output;
00398 
00399     output = ddl_statusReadout(rorc, PIT_GET_VERSION);
00400     if(output >= 0) output = output & 0x3ffff;
00401         else PITDecodeRORCError(output, "(in pit_comm::PITGetVersion): "); 
00402     return(output);
00403 }/* end PITGetVersion */
00404 
00405 
00406 /******************************************************************************
00407 * Name : PITGetBusStatus                                                      *
00408 * Function : get bus status from register                                     *
00409 * Output : bust status if >=0 else negative output on rorc error              *
00410 * Revisions:                                                                  *
00411 *  DATE     AUTHOR            NOTES                                           *
00412 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00413 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00414 ******************************************************************************/
00415 int pit_comm::PITGetBusStatus()
00416 {
00417 int output;
00418 
00419     output = ddl_statusReadout(rorc, PIT_GET_BUS_STATUS);
00420     if(output >=0) output = output & 0xfff;
00421     else PITDecodeRORCError(output, "(PITGetBusStatus) : "); 
00422     return(output);
00423 }/* end PITGetBusStatus */
00424 
00425 
00426 /******************************************************************************
00427 * Name : PITSetRdA                                                            *
00428 * Functin : set read address to register                                      *
00429 * Input : address : full address                                              *
00430 * Output : 0 if read address was successfully written else                    *
00431 *          -negative output on rorc error                                     *
00432 *          -ERROR_BAD_REGISTER_WRITE                                          *
00433 * Revisions:                                                                  *
00434 *  DATE     AUTHOR            NOTES                                           *
00435 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00436 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00437 ******************************************************************************/
00438 int pit_comm::PITSetRdA(UInt28 address)
00439 {
00440 unsigned int argument;
00441 unsigned int addr_extract;
00442 int output;
00443 unsigned int rd_a_msb;
00444 
00445       // call the DDL library function for FECTRL with proper parameter to set the rd a[27:19] register bits 
00446     addr_extract = (address >> 19) & 0x1ff;  // extract of 9 msb of address
00447     argument = addr_extract | (0x3ff << 9);  // combining with address rd_a msb
00448     output = ddl_sendCommand(rorc, argument);
00449         // here it checks if it is different than zero instead of smaller than 
00450     if (output){
00451         PITDecodeRORCError(output, "(PITSetRdA) write rd [27:19] : ");
00452         return output;
00453     }
00454   
00455           // call the DDL library function for FESTRD with proper parameter to read back the rd a[27:19] value
00456     output = ddl_statusReadout(rorc, PIT_GET_RDA_MSB);
00457     
00458     if (output<0){
00459         PITDecodeRORCError(output, "(PITSetRdA) read rd [27:19] : ");
00460         return output;
00461     }
00462       // compare the value read back and flag possible error
00463     rd_a_msb = (output /*>> 12*/) & 0x1ff;             // rd_a[27..19]
00464     if(rd_a_msb == !addr_extract){ 
00465         output = ERROR_BAD_REGISTER_WRITE; 
00466         this->PITDecodeComError(output, "(PITSetRdA) read write comparison :");
00467         return output;
00468     }
00469     
00470    
00471   
00472     return(0);
00473 }/* end PITSetRdA */
00474 
00475 
00476 /******************************************************************************
00477 * Name : PITSetWrA                                                            *
00478 * Use : set write address to register                                         *
00479 * Input : address : full address                                              *
00480 * Output : 0 if write address was successfully written else                   *
00481 *          -negative output on rorc error                                     *
00482 *          -ERROR_BAD_REGISTER_WRITE                                          *
00483 * Revisions:                                                                  *
00484 *  DATE     AUTHOR            NOTES                                           *
00485 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00486 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00487 ******************************************************************************/
00488 int pit_comm::PITSetWrA(UInt28 address)
00489 {
00490 unsigned int argument;
00491 unsigned int addr_extract;
00492 int output;
00493 unsigned int wr_a_msb;
00494 
00495       // call the DDL library function for FECTRL with proper parameter to set the wr a[27:19] register bits
00496     addr_extract = (address >> 19) & 0x1ff;  // extract of 9 msb of address
00497     argument = addr_extract | (0x3fe << 9);  // combining with address rd_a msb
00498     output = ddl_sendCommand(rorc, argument);
00499     if (output< 0){
00500         PITDecodeRORCError(output, "(PITSetWrA)  setting the wr a[27:19] : ");
00501         return output;
00502     }
00503        
00504     
00505       // call the DDL library function for FESTRD with proper parameter to read back the wr a[27:19] value
00506     output = ddl_statusReadout(rorc, PIT_GET_WRA_MSB);
00507     if (output< 0){
00508         PITDecodeRORCError(output,  "(PITSetWrA)  reading the wr a[27:19] : ");
00509         return output;
00510     }
00511       
00512 
00513       // compare the value read back and flag possible error
00514     wr_a_msb = (output /*>> 12*/) & 0x1ff;             // wa_a[27..19]
00515     if(wr_a_msb != addr_extract){ 
00516         output = ERROR_BAD_REGISTER_WRITE; 
00517         PITDecodeComError(output, "(PITSetWrA)read write comparison : ");
00518         return output;
00519     }
00520 
00521     return(0); 
00522 }/* end PITSetWrA */
00523 
00524 /******************************************************************************
00525 * Name : PITSetLen                                                            *
00526 * Use : set length to register                                                *
00527 * Input : length  : full length                                               *
00528 * Output : 0 if length was successfully written else                          *
00529 *          -negative output on rorc error                                     *
00530 *          -ERROR_BAD_REGISTER_WRITE                                          *
00531 * Revisions:                                                                  *
00532 *  DATE     AUTHOR            NOTES                                           *
00533 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00534 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00535 ******************************************************************************/
00536 int pit_comm::PITSetLen(UInt19 length)
00537 {
00538 unsigned int argument;
00539 int output;
00540 unsigned int len;
00541 
00542       // call the DDL library function for FECTRL with proper parameters to set the len[18:9] register bits
00543     argument = ((length & 0x7fe00) >> 9) | (0x1fc << 10); 
00544     output = ddl_sendCommand(rorc, argument);
00545     if (output < 0){
00546         PITDecodeRORCError(output,"(PITSetLen) setting len [18:9] : ");
00547         return output;
00548     }
00549       // call the the DDL library function for FECTRL with proper parameter to set the len[8:0] bits of the len register
00550     argument = (length & 0x1ff) | (0x3fb << 9); 
00551     output = ddl_sendCommand(rorc, argument);
00552     if (output<0){
00553         PITDecodeRORCError(output, "(PITSetLen) setting len [8:0] : ");
00554         return output;
00555     }
00556     
00557       // call the DDL library function for FESTRD with proper parameter to read back the len[18:0] value
00558     output = ddl_statusReadout(rorc, PIT_GET_LEN);
00559     if (output<0){
00560         PITDecodeRORCError(output, "(PITSetLen) reading len[18:0] : ");
00561         return output;
00562      }
00563       // compare the value read back and flag possible error
00564     len = (output/* >> 12*/) & 0x7ffff;             // wa_a[27..19]
00565     if(len != length){ 
00566         output = ERROR_BAD_REGISTER_WRITE; 
00567         PITDecodeComError(output, "(PITSetLen) read write comparison : ");
00568         return output;
00569     }
00570     
00571     return(0); 
00572 }/* end PITSetLen */
00573 
00574 /******************************************************************************
00575 * Name : PITSetControl0                                                       *
00576 * Use : set control0 register                                                 *
00577 * Input : value  : value to put to register                                   *
00578 * Output : 0 if value  was successfully written else                          *
00579 *          -negative output on rorc error                                     *
00580 *          -ERROR_BAD_REGISTER_WRITE                                          *
00581 * Revisions:                                                                  *
00582 *  DATE     AUTHOR            NOTES                                           *
00583 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00584 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00585 ******************************************************************************/
00586 int pit_comm::PITSetControl0(UInt8 value)
00587 {
00588 unsigned int argument;
00589 unsigned int control0;
00590 int output;
00591 
00592       // call the DDL library function for FECTRL with proper parameters to set the control[7:0] register bits
00593     argument = value & 0xff; 
00594     output = ddl_sendCommand(rorc, argument);
00595     if(output){
00596         PITDecodeRORCError(output, "(PITSetControl0) setting register : ");
00597         return output;
00598     }
00599 
00600       // call the DDL library function for FESTRD with proper parameter to read back the control0[7:0] value
00601     output = ddl_statusReadout(rorc, PIT_GET_CONTROL0);
00602       // compare the value read back and flag possible error
00603     if(output < 0) {
00604         PITDecodeRORCError(output, "(PITSetControl0) reading register : ");
00605         return output;
00606     }
00607     control0 = (output /* >> 12*/) & 0xff;             // control0[7..0]
00608     if(control0 != value) { 
00609         output = ERROR_BAD_REGISTER_WRITE; 
00610         PITDecodeComError(output, "(PITSetControl0) read write comparison : ");
00611         return output;
00612     }
00613         
00614  
00615     return(0);
00616 }/* end PITSetControl0 */
00617 
00618 /******************************************************************************
00619 * Name : PITSetControl1                                                       *
00620 * Use : set control1 register                                                 *
00621 * Input : value  : value to put to register                                   *
00622 * Output : 0 if value  was successfully written else                          *
00623 *          -negative output on rorc error                                     *
00624 *          -ERROR_BAD_REGISTER_WRITE                                          *
00625 * Revisions:                                                                  *
00626 *  DATE     AUTHOR            NOTES                                           *
00627 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00628 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00629 ******************************************************************************/
00630 int pit_comm::PITSetControl1(UInt8 value)
00631 {
00632 unsigned int argument;
00633 unsigned int control1;
00634 int output;
00635 
00636       // call the DDL library function for FECTRL with proper parameters to set the control[7:0] register bits
00637     argument = (value & 0xff) | 0x100; 
00638     output = ddl_sendCommand(rorc, argument);
00639     if (output){
00640         PITDecodeRORCError(output, "(PITSetControl1) writting register : ");
00641         return output;
00642     }
00643   
00644           // call the DDL library function for FESTRD with proper parameter to read back the control0[7:0] value
00645     output = ddl_statusReadout(rorc, PIT_GET_CONTROL1);
00646     if(output < 0){
00647         PITDecodeRORCError(output, "(PITSetControl1) reading register : ");
00648         return output;
00649     }
00650     
00651 
00652       // compare the value read back and flag possible error
00653     control1 = (output /* >> 12*/) & 0xff;             // control1[7..0]
00654     if(control1 != value) { 
00655         output = ERROR_BAD_REGISTER_WRITE; 
00656         PITDecodeComError(output, "(PITSetControl1) read write comparison : ");
00657         return output;
00658     }
00659     
00660     return(0);
00661 }/* end PITSetControl1 */
00662 
00663 
00664 
00665 
00666 /******************************************************************************
00667 * Name : PITReadBlock                                                         *
00668 * Use : read a block within FEE                                               *
00669 * Input : address : base address (full) in FEE from which data is read        *
00670 *         dalalength : number of data words to read                           *
00671 * Output : data : output buffer where data are stored                         *
00672 *          PITReadBlock: 0 if read operation was successfull else             *
00673 *          -negative output from PITSetLen                                    *
00674 *          -negative output from PITSetRdA                                    *
00675 *          -negative output from rorc_receive                                 *
00676 *          -ERROR_BAD_LENGTH_COMPARISON (<0)                                  *
00677 * Revisions:                                                                  *
00678 *  DATE     AUTHOR            NOTES                                           *
00679 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00680 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00681 ******************************************************************************/
00682 int pit_comm::PITReadBlock(UInt28 address, UInt19 datalength, UInt32* data)
00683 {
00684 int rd_len;
00685 int output;
00686 
00687       //call the PITSetLen function to set the requested data block length
00688     output = PITSetLen(datalength);
00689     
00690     if(output){
00691         
00692         PITDecodeRORCError(output, "(pit_comm::PITReadBlock): Problem encountered while setting length register");
00693         return output;
00694     }
00695           // call the PITSetRdA passing address to properly set the rd a[27:19] register bits
00696     output = PITSetRdA(address);
00697     if(output){
00698         PITDecodeRORCError(output, "(pit_comm::PITReadBlock): Problem encountered while setting the base address register");
00699         return output;
00700     }
00701           // call the DDL library function for STBRD with proper parameters (including address lower bits) to read back the data block and store it to data
00702     output = ddl_readBlock(rorc,0x7ffff & address, (u_long*)data, datalength);
00703     if(output<0){
00704         PITDecodeRORCError(output, "(pit_comm::PITReadBlock) Problem encountered while reading data");
00705         return output;
00706     }
00707       // call PITGetRdLen to verify the number of words actually read from the DDL and return
00708     rd_len = PITGetRdLen();
00709     if( rd_len != (int)datalength){
00710         output = ERROR_BAD_LENGTH_COMPARISON; 
00711         PITDecodeComError(output, "(pit_comm::PITReadBlock) Actual block read length mismatches requested block length");
00712         return output;
00713     }
00714     
00715     int statusReg = PITGetBusStatus();
00716         //checks the parity bit
00717     if (extractFromUInt32(0,1,statusReg) ){
00718         output= ERROR_PARITY_CHECK;
00719         PITDecodeComError(output, "(pit_comm::PITReadBlock)");
00720         return output;
00721         
00722     }
00723     if (statusReg){
00724         output= ERROR_GENERIC_BUS_STATUS;
00725         PITDecodeComError(output, "(pit_comm::PITReadBlock) ");
00726         return output;
00727     }
00728     
00729     
00730     return(0);
00731 }/* end PITReadBlock */
00732 
00733 
00734 /******************************************************************************
00735 * Name : PITWriteBlock                                                        *
00736 * Use : write a block within FEE                                              *
00737 * Input : address : base address (full) in FEE from which data is read        *
00738 *         dalalength : number of data words to read                           *
00739 * Output : data : output buffer where data are stored                         *
00740 *          PITReadBlock: 0 if read operation was successfull else             *
00741 *          -negative output from PITSetWrA                                    *
00742 *          -negative output from rorc_send                                    *
00743 *          -ERROR_BAD_LENGTH_COMPARISON (<0)                                  *
00744 * Revisions:                                                                  *
00745 *  DATE     AUTHOR            NOTES                                           *
00746 * 20070802  Fabrice Pancher   function output more detailled if errors        *
00747 * 20071109  Fabrice Pancher   use fec2rorc library                            *
00748 ******************************************************************************/
00749 int pit_comm::PITWriteBlock(UInt28 address, UInt19 datalength, UInt32* data)
00750 {
00751 unsigned int wr_len;
00752 int output;
00753 
00754       // call the PITSetWrA function to set the wr a[27:19] bits
00755     output = PITSetWrA(address);
00756     
00757       // call the DDL library function for STBWR with proper parameters to write the data block from memory location *data with length datalength and starting writing at the location given by address
00758     if(output< 0) {
00759         PITDecodeRORCError(output, "(PITWriteBlock) setting address :");
00760         return output;
00761     }
00762         
00763     output = ddl_writeBlock(rorc, (u_long*)data, datalength, address & 0x7ffff);
00764     if(output<0) {
00765         PITDecodeRORCError(output,  "(PITWriteBlock) sending data :");
00766         return output;
00767     }
00768       // call PITGetWrLen to check the number of words actually written to memory
00769     wr_len = PITGetWrLen();
00770     if(wr_len != datalength){ 
00771         output = ERROR_BAD_LENGTH_COMPARISON; 
00772         PITDecodeComError(output, "(PITWriteBlock) length check : ");
00773         return output;
00774     }
00775 
00776     return(0);
00777 }/* end PITWriteBlock */
00778 
00779 
00780 // this is a sinple call of the PITWriteBlock with a size of one
00781 int pit_comm::PITWriteWord(UInt28 address, const UInt32 & data){
00782         UInt32 dataOut = data;
00783         
00784         logCom->log(log4cpp::Priority::DEBUG, "(pit_comm::PITWriteWord): writing to address 0x%x value 0x%x", address, data);
00785         return PITWriteBlock(address,1,&dataOut);
00786         }
00787 
00788 // this is a sinple call of the PITReadBlock with a size of one
00789 int pit_comm::PITReadWord(UInt28 address, UInt32 *data){
00790         int return_value = PITReadBlock(address, 1 ,data);
00791         
00792         logCom->log(log4cpp::Priority::DEBUG, "(pit_comm::PITReadWord): read word from address 0x%x, value 0x%x", address, *data);
00793                 
00794         return return_value;
00795         }

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