Generic hardware access library
/home/cschwick/hal/generic/src/common/VME64xFunction.cc
Go to the documentation of this file.
00001 #include "hal/VME64xFunction.hh"
00002 #include <string>
00003 #include <sstream>
00004 
00005 HAL::VME64xFunction::VME64xFunction( uint32_t slotId,
00006                                      uint32_t baseAddress,
00007                                      uint32_t addressRank ) 
00008 : slotId_(slotId) {
00009   functionId_ = 0;
00010   vmeConfigurationSpaceHandlerRef_ = (HAL::VMEConfigurationSpaceHandler*)0;
00011   HAL::VME64xMappedWindow* vmeWindow;
00012   vmeWindow = new HAL::VME64xMappedWindow( slotId_,
00013                                            baseAddress,
00014                                            addressRank);
00015   mappedWindowPtrList_.push_back( vmeWindow );
00016 }
00017 
00018 HAL::VME64xFunction::VME64xFunction( uint32_t slotId,
00019                                      uint32_t functionId,
00020                                      HAL::VMEConfigurationSpaceHandler* vmeAccess ) 
00021   throw( HAL::UnsupportedException, 
00022          HAL::IllegalValueException )
00023   : slotId_(slotId),
00024         functionId_(functionId),
00025         vmeConfigurationSpaceHandlerRef_(vmeAccess) {
00026   
00027   uint32_t mappedWindowId = functionId;
00028   // see if function is implemented: This is done by trying to make the first mapped Window
00029   HAL::VME64xMappedWindow *nextWindow = 
00030     new HAL::VME64xMappedWindow( slotId, functionId, mappedWindowId, vmeConfigurationSpaceHandlerRef_);
00031   if ( ! nextWindow->isImplemented() ) {
00032     return;
00033   }
00034   mappedWindowPtrList_.push_back( nextWindow );
00035   uint32_t oldAddressRank;
00036   while ( nextWindow->hasAnotherWindow() ) {
00037     oldAddressRank = nextWindow->getAddressRank();
00038     mappedWindowId++;
00039     nextWindow = 
00040       new HAL::VME64xMappedWindow( slotId, functionId, mappedWindowId, vmeConfigurationSpaceHandlerRef_);
00041     if ( ! nextWindow->isImplemented() ) {
00042       // error in configuration space
00043       std::stringstream text;
00044       text << "Error in configuration space of module in slot" << slotId
00045            << ". \nWindow " << mappedWindowId << "is not implemented but previous window "
00046            << " demands another window for the same function\n"
00047            << "    (HAL::VME64xFunction::VME64xFunction)" << std::ends;
00048       throw( HAL::IllegalValueException( text.str(), __FILE__, __LINE__, __FUNCTION__ ) );
00049     }
00050     if ( oldAddressRank != nextWindow->getAddressRank() ) {
00051       // error: all mapped windows should demand the same address space in this software
00052       std::stringstream text;
00053       text << "Error in configuration space of module in slot" << slotId
00054            << ".\nFunction " << functionId_ << "has more than one mapped Window, "
00055            << "but they have different sized decoders (ADEM bits),\n"
00056            << "which is not supported by this software" << std::ends;
00057       throw( HAL::UnsupportedException( text.str(), __FILE__, __LINE__, __FUNCTION__ ) );
00058     }
00059     mappedWindowPtrList_.push_back( nextWindow );
00060   }
00061 }
00062 
00063 HAL::VME64xFunction::~VME64xFunction() {
00064   std::list< HAL::VME64xMappedWindow * >::iterator it;
00065   for ( it = mappedWindowPtrList_.begin(); it != mappedWindowPtrList_.end(); it++ ) {
00066     delete *it;
00067   }
00068 }
00069 
00070 uint32_t HAL::VME64xFunction::getNumberOfMappedWindows() const {
00071   return mappedWindowPtrList_.size();
00072 }
00073 
00074 bool HAL::VME64xFunction::isImplemented() const {
00075   return (mappedWindowPtrList_.size() > 0);
00076 }
00077 
00078 uint32_t HAL::VME64xFunction::getAddressRank() const {
00079   // The constructor made sure that all windows have the same Address rank.
00080   // Therefore we can just take the first element of the list to determine
00081   // the rank.
00082   if ( mappedWindowPtrList_.size() > 0 ) {
00083     return mappedWindowPtrList_.front()->getAddressRank();
00084   } else {
00085     return 0;
00086   }
00087 }
00088 
00089 //uint32_t HAL::VME64xFunction::getFunctionId() const {
00090 //  return functionId_;
00091 //}
00092 
00093 std::list< HAL::VME64xMappedWindow* > HAL::VME64xFunction::getMappedWindowPtrList() const {
00094   return mappedWindowPtrList_;
00095 }