Code Search for Developers
 
 
  

simpleAddressMap.h from GreenSocs at Krugle


Show simpleAddressMap.h syntax highlighted

/*
Copyright (c) 2006 : Technical University of Braunschweig, Germany

All rights reserved.

Authors: Robert Guenzel, Wolfgang Klingauf, TU Braunschweig, E.I.S.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.  Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.  Neither the name of
the Technical University of Braunschweig, Germany nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#ifndef __simpleAddressMap_h__
#define __simpleAddressMap_h__

#include "systemc.h"
#include "gstlm/protocol/generic.h"
#include "gstlm/gstlm/tlm.h"
#include "gstlm/gstlm/tlm_slave_if.h"
#include <map>

using namespace tlm;

//--------------------------------------------------------------------------
/**
 * Simple address map implementation.
 */
//--------------------------------------------------------------------------
template<typename ADD, class INITPORT, class TRANSACTION, class PHASE>
class SimpleAddressMap 
{

  typedef sc_export<payload_event_queue_if<tlm::unevenpair<boost::shared_ptr<TRANSACTION>,PHASE > > > * destinationPort;  
  typedef typename std::map<ADD, unsigned int>::iterator addressMapIterator;
  
public:
  SimpleAddressMap() {}

  //--------------------------------------------------------------------------
  /**
   * Generate an address map from the connected slaves
   */
  //--------------------------------------------------------------------------
  void generateMap(INITPORT* port)
  {
    if(port == NULL)
      SC_REPORT_ERROR("Address Map", "Null pointer passed to GenerateMap().");
    
    MAddr b,h;
    const char* target_name;
    
#ifdef VERBOSE
    cout<<"Generating address map:"<<endl<<endl
        <<"Number of connected slaves: "<<( ( *port ).connected_in_ports.size() )
        <<endl<<endl;
#endif
    
    for (unsigned int i=0; i<( *port ).connected_in_ports.size(); i++) {
      destinationPort destination= ( *port ).connected_in_ports[i];
      (dynamic_cast< tlm_slave_if<ADD>* >((*destination).get_parent()))->getAddress(b,h);
      target_name=(dynamic_cast<sc_object*>((*destination).get_parent()))->name();
      
#ifdef VERBOSE
      cout<<"Target ["<<target_name<<"] is connected to port number "
          <<i<<"   Baseaddress: "<<(unsigned int)b<<"   Highaddress: "
          <<(unsigned int)h<<endl;
#endif
      
      insert(b,h,i);    
      
    }
  }


  //--------------------------------------------------------------------------
  /**
   * Check for overlapping address ranges
   */
  //--------------------------------------------------------------------------
  void checkSanity() 
  {
    addressMapIterator pos;
    for (pos=m_addressMap.begin();pos!=m_addressMap.end();++pos){
      if(pos->second!=255)
        SC_REPORT_ERROR("Address Map","Overlapping Address Regions.");
      else
        ++pos;
      if(pos->second==255)
        SC_REPORT_ERROR("Address Map","Overlapping Address Regions.");
    }
#ifdef VERBOSE
      cout<<"Address sanity check successfull."<<endl<<flush;
#endif
  }


  //--------------------------------------------------------------------------
  /**
   * Print map 
   */
  //--------------------------------------------------------------------------
  void dumpMap()
  {
    cout<<"SimpleAddressMap: printing the sorted MAP:"<<endl<<flush;
    addressMapIterator pos;
    for (pos=m_addressMap.begin();pos!=m_addressMap.end();++pos){
      if(pos->second==255)
        printf("key: %x    value: %i \n", (unsigned int) ((pos->first+1)>>1)-1, pos->second);
      else
        printf("key: %x    value: %i \n", (unsigned int) (pos->first>>1)-1, pos->second);
    }
  }
  

  //--------------------------------------------------------------------------
  /**
   * Decode slave address.
   * @param address_ A slave address.
   * @return The decoded slave port number. On error, the value 255 is returned.
   */
  //--------------------------------------------------------------------------
  unsigned int decode(MAddr address_)
  {
    addressMapIterator lbound;
    
    if(address_>0xffffffff)
      SC_REPORT_ERROR("Address Decode", "Address must not exceed 32 bits in width.");
    
    lbound=m_addressMap.lower_bound(((ADD) address_+1)<<1);
    if(lbound->second == 255 | lbound==m_addressMap.end()){
      printf("Decode attempt for address %x failed:\n", (unsigned int)address_);
      SC_REPORT_ERROR("Address Decode", "Address does not match any registered address range.");
    }
    else{
      return lbound->second;
    }
    return 255;
  }


private:
  typedef std::map< ADD, unsigned int> mapType;

  //--------------------------------------------------------------------------
  /**
   * Insert a slave into the address map
   */
  //--------------------------------------------------------------------------
  void insert(MAddr baseAddress_, MAddr highAddress_, unsigned int portNumber_)
  {
    if(baseAddress_>highAddress_)
      SC_REPORT_ERROR("Address Map", "Base address must be lower than high address.");
    if(baseAddress_>0xffffffff | highAddress_>0xffffffff)
      SC_REPORT_ERROR("Address Map", "Addresses must not exceed 32 bits in width.");
    if(portNumber_>=255)
      SC_REPORT_ERROR("Address Map", "Only ;-) 255 targets can be handled.");
    m_addressMap.insert(typename mapType::value_type(((baseAddress_+1)<<1)-1,    255    ));
    m_addressMap.insert(typename mapType::value_type( (highAddress_+1)<<1   ,portNumber_));
  }

  /// the address map
  mapType m_addressMap;
};




#endif




See more files for this project here

GreenSocs

To develop SystemC infrustructure, basic IP, patches and add on library code for eventual standerdization.\r\nThe GreenSocs project is made up of a number of contributions (sub projects). Please visit www.greensocs.com for more information.

Project homepage: http://sourceforge.net/projects/greensocs
Programming language(s): C,C++,Java,Perl,XML
License: other

  PLB/
    PLBBusProtocol.h
    PLBBusProtocol.tpp
  SimpleBus/
    simpleBusProtocol.h
  simpleAddressMap.h