ProbeCrate.cxx

00001 /************************************************************************/
00002 /*  ProbeCrate: based on                                                */
00003 /*      scanvme: A program by M. Joos CERN,EP/ESS/OS            */
00004 /*                                  */
00005 /*  A much cut down version of scanvme that uses some heuristics        */
00006 /*  to guess which slots contain RODs and TIMs                          */
00007 /*                                  */
00008 /*  The main purpose of scanvme is to scan the whole 4 GBytes       */
00009 /*  of VME address space for slaves present. This is done by trying     */
00010 /*  to read a char, short or int. Hence, only slaves with readable  */
00011 /*  registers can be found.                     */
00012 /*                                  */
00013 /*  8.06.94   MAJO  created                     */
00014 /* 07.03.02   MAJO  Ported to VME_RCC driver for CCT SBCs       */
00015 /*****C 2002 - A nickel program worth a dime*****************************/
00016 
00017 #include <list>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include "rcc_error/rcc_error.h"
00021 #include "vme_rcc/vme_rcc.h"
00022 #include "vme_rcc/universe.h"
00023 
00024 #define PCIMEM   0xa0000000
00025 
00026 //prototypes
00027 static int open_universe();
00028 static int close_universe();
00029 static int init_universe();
00030 
00031 //globals
00032 volatile universe_regs_t *uni;
00033 static unsigned int vme_address, lsi0ctl, lsi1ctl, lsi2ctl, lsi3ctl, lsi3bs, lsi3bd, lsi3to;
00034 static unsigned int lsi4ctl, lsi5ctl, lsi6ctl, lsi7ctl;
00035 
00036 
00037 /*****************/
00038 int open_universe()
00039 /*****************/
00040 { 
00041   unsigned int ret;
00042   
00043   ret = VME_Open();
00044   if (ret != VME_SUCCESS)
00045   {
00046     VME_ErrorPrint(ret);
00047     exit(-1);
00048   }
00049   
00050   ret = VME_UniverseMap(&vme_address);
00051   if (ret != VME_SUCCESS)
00052   {
00053     VME_ErrorPrint(ret);
00054     exit(-1);
00055   }
00056   
00057   uni = (universe_regs_t *)vme_address; 
00058   return(0);
00059 }
00060 
00061 
00062 
00063 /*****************/
00064 int init_universe()
00065 /*****************/
00066 {
00067   //disable lsi0,1,2,4,5,6,7
00068   lsi0ctl = uni->lsi0_ctl;
00069   lsi1ctl = uni->lsi1_ctl;
00070   lsi2ctl = uni->lsi2_ctl;
00071   lsi4ctl = uni->lsi4_ctl;
00072   lsi5ctl = uni->lsi5_ctl;
00073   lsi6ctl = uni->lsi6_ctl;
00074   lsi7ctl = uni->lsi7_ctl;
00075   uni->lsi0_ctl = 0;
00076   uni->lsi1_ctl = 0;
00077   uni->lsi2_ctl = 0;
00078   uni->lsi4_ctl = 0;
00079   uni->lsi5_ctl = 0;
00080   uni->lsi6_ctl = 0;
00081   uni->lsi7_ctl = 0;
00082 
00083   //save lsi3
00084   lsi3ctl = uni->lsi3_ctl;
00085   lsi3bs = uni->lsi3_bs;
00086   lsi3bd = uni->lsi3_bd;  
00087   lsi3to = uni->lsi3_to;
00088   return(0);
00089 }
00090 
00091 
00092 /******************/
00093 int close_universe()
00094 /******************/
00095 {
00096   //restore lsi0,1,2,3,4,5,6,7
00097   uni->lsi0_ctl = lsi0ctl;
00098   uni->lsi1_ctl = lsi1ctl;
00099   uni->lsi2_ctl = lsi2ctl;
00100   uni->lsi4_ctl = lsi4ctl;
00101   uni->lsi5_ctl = lsi5ctl;
00102   uni->lsi6_ctl = lsi6ctl;
00103   uni->lsi7_ctl = lsi7ctl;
00104 
00105   uni->lsi3_ctl = lsi3ctl;
00106   uni->lsi3_bs = lsi3bs;
00107   uni->lsi3_bd = lsi3bd;
00108   uni->lsi3_to = lsi3to;
00109 
00110   unsigned int ret = VME_UniverseUnmap(vme_address);
00111   if (ret != VME_SUCCESS)
00112     VME_ErrorPrint(ret);
00113 
00114   // Update the driver
00115   unsigned int dummy[8];
00116   dummy[0] = 0; //IRQ modes are not valid
00117 
00118   ret = VME_Update(dummy);
00119   if (ret)
00120   {
00121     VME_ErrorPrint(ret);
00122     exit(-1);
00123   }  
00124     
00125   ret = VME_Close();
00126   if (ret != VME_SUCCESS)
00127     VME_ErrorPrint(ret);
00128   return(0);
00129 }
00130 
00131 
00132 /**************************/
00133 int main(int argc, char *argv[])
00134 /**************************/
00135 {
00136   open_universe();
00137   init_universe();
00138 
00139   // This is the range checked by eg LedTest input
00140   for(int loop = 1; loop <= 21; loop++)
00141   {
00142     int step = 0x100000;
00143 
00144     // Generate a mapping in the Universe
00145     uni->lsi3_ctl = 0x80820000;
00146     uni->lsi3_bs = 0xa0000000;
00147     uni->lsi3_bd = 0xa1000000;
00148     uni->lsi3_to = 0x60000000 + (loop << 24);
00149 
00150     // Update the driver
00151     unsigned int dummy[8];
00152     dummy[0] = 0; //IRQ modes are not valid
00153 
00154     unsigned int ret = VME_Update(dummy);
00155     if (ret)
00156     {
00157       VME_ErrorPrint(ret);
00158       exit(-1);
00159     }  
00160 
00161     // Attach process to the mapping
00162     VME_MasterMap_t master_map;
00163 
00164     master_map.vmebus_address  = loop << 24;
00165     master_map.window_size = 0x01000000;
00166     master_map.address_modifier = VME_A32;
00167     master_map.options = 0;
00168 
00169     int handle;
00170     ret = VME_MasterMap(&master_map, &handle);
00171     if (ret)
00172     {
00173       VME_ErrorPrint(ret);
00174       exit(-1);
00175     }  
00176 
00177     int found = 0;
00178   
00179     // TIM gets only one response
00180     //  0x0d000000
00181 
00182     std::list<int> foundList;
00183 
00184     for (int ii = 0; ii < 0x1000000; ii += step)
00185     {
00186       unsigned int idata;
00187       ret = VME_ReadSafeUInt(handle, ii, &idata);
00188 
00189       if (!ret) {
00190         if(loop == 13) {
00191           if(ii > 0) {
00192             printf("Multiple (or incorrect) addresses in TIM slot\n");
00193           } else {
00194             printf("Found TIM in slot 0xd\n");
00195           }
00196         } else {
00197           found += 1;
00198           foundList.push_back(ii);
00199         }
00200       }
00201     }
00202 
00203     // ROD gets 5 responses
00204     //  0x0f000000
00205     //  0x0f200000
00206     //  0x0f400000
00207     //  0x0f600000
00208     //  0x0f800000   // Rev E also gets this one
00209     //  0x0fc00000
00210     if(loop != 13) {
00211       if(found == 5 || found == 6) {
00212         printf("Found ROD in slot 0x%x\n", loop);
00213       } else if(found) {
00214         printf("Something un ROD-like in slot 0x%x!\n", loop);
00215         for(std::list<int>::const_iterator iter = foundList.begin();
00216             iter != foundList.end(); iter++) {
00217           printf(" %x", *iter); 
00218         }
00219         printf("\n");
00220       }
00221     }
00222 
00223     ret = VME_MasterUnmap(handle);
00224     if (ret)
00225       VME_ErrorPrint(ret);
00226   }
00227 
00228   close_universe();
00229 }

Generated on Mon Feb 6 14:01:25 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6