00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/architecture/Sites.hpp $ 00003 // $Id: Sites.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Header for the Sites class. 00018 00019 #ifndef TORC_ARCHITECTURE_SITES_HPP 00020 #define TORC_ARCHITECTURE_SITES_HPP 00021 00022 #include "torc/architecture/XilinxDatabaseTypes.hpp" 00023 #include "torc/architecture/DigestStream.hpp" 00024 #include "torc/architecture/Array.hpp" 00025 #include "torc/architecture/Tilewire.hpp" 00026 #include "torc/architecture/Package.hpp" 00027 #include "torc/architecture/PrimitivePin.hpp" 00028 #include "torc/architecture/PrimitiveElementPin.hpp" 00029 #include "torc/architecture/PrimitiveElement.hpp" 00030 #include "torc/architecture/PrimitiveConn.hpp" 00031 #include "torc/architecture/PrimitiveDef.hpp" 00032 #include "torc/architecture/Site.hpp" 00033 #include <boost/cstdint.hpp> 00034 #include <map> 00035 #include <set> 00036 00037 namespace torc { 00038 namespace architecture { 00039 00040 /// \brief Site type and population data for the family and the device. 00041 /// \details Each device has a collection of logic sites. Those sites are instantiations of 00042 /// family defined site types, with each instance also including a mapping from site pin 00043 /// to Tilewire. 00044 class Sites { 00045 // friends 00046 /// \brief The database has access to our protected functions. 00047 friend class DDB; 00048 protected: 00049 // types 00050 typedef std::string string; ///< \brief Imported type name. 00051 typedef xilinx::TileIndex TileIndex; ///< \brief Imported type name. 00052 typedef xilinx::WireIndex WireIndex; ///< \brief Imported type name. 00053 typedef xilinx::PinFlags PinFlags; ///< \brief Imported type name. 00054 typedef xilinx::PinCount PinCount; ///< \brief Imported type name. 00055 typedef xilinx::SiteCount SiteCount; ///< \brief Imported type name. 00056 typedef xilinx::SiteIndex SiteIndex; ///< \brief Imported type name. 00057 typedef xilinx::SiteFlags SiteFlags; ///< \brief Imported type name. 00058 typedef xilinx::SiteTypeCount SiteTypeCount; ///< \brief Imported type name. 00059 typedef xilinx::SiteTypeIndex SiteTypeIndex; ///< \brief Imported type name. 00060 typedef xilinx::PackageCount PackageCount; ///< \brief Imported type name. 00061 typedef xilinx::PackageIndex PackageIndex; ///< \brief Imported type name. 00062 typedef xilinx::PadCount PadCount; ///< \brief Imported type name. 00063 typedef xilinx::PadIndex PadIndex; ///< \brief Imported type name. 00064 /// \brief Map from site name to site index. 00065 typedef std::map<string, SiteIndex> SiteNameToSiteIndexMap; 00066 /// \brief Map from package name to package index. 00067 typedef std::map<string, PackageIndex> PackageNameToPackageIndexMap; 00068 // members 00069 /// \brief The site types for this family. 00070 Array<const PrimitiveDef> mSiteTypes; 00071 /// \brief The site pin maps for this family. 00072 Array2D<const WireIndex> mPrimitivePinMaps; 00073 /// \brief The logic sites for this device. 00074 Array<const Site> mSites; 00075 /// \brief The mapping from site name to site index for this device. 00076 SiteNameToSiteIndexMap mSiteNameToSiteIndex; 00077 /// \brief The packages for this device 00078 Array<const Package> mPackages; 00079 /// \brief The mapping from package name to package index for this device. 00080 PackageNameToPackageIndexMap mPackageNameToPackageIndex; 00081 // functions 00082 /// \brief Read the primitive types for the family. 00083 size_t readPrimitiveTypes(DigestStream& inStream); 00084 /// \brief Read the site pin mappings for the family. 00085 size_t readPrimitivePinMaps(DigestStream& inStream); 00086 /// \brief Read the sites for the device. 00087 size_t readSites(DigestStream& inStream); 00088 /// \brief Read the packages for the device. 00089 size_t readPackages(DigestStream& inStream); 00090 /// \brief Activate the specified device package. 00091 void activatePackage(const string& inName) { 00092 activatePackage(findPackageIndex(inName)); 00093 } 00094 /// \brief Activate the specified device package. 00095 void activatePackage(PackageIndex inPackageIndex) { 00096 // look up the package 00097 if(inPackageIndex >= mPackages.getSize()) return; 00098 const Package& package = mPackages[inPackageIndex]; 00099 // iterate through the pads 00100 const Array<const Pad>& pads = package.getPads(); 00101 Array<const Pad>::const_iterator p = pads.begin(); 00102 Array<const Pad>::const_iterator e = pads.end(); 00103 while(p < e) { 00104 // update the site name and flags 00105 Site& site = const_cast<Site&>(mSites[p->mSiteIndex]); 00106 site.mName = p->mName; 00107 site.mFlags = p->mFlags; 00108 p++; 00109 } 00110 // update the name to index map 00111 mSiteNameToSiteIndex.clear(); 00112 for (SiteIndex i; i < getSiteCount(); i++) { 00113 Site& site = const_cast<Site&>(mSites[i]); 00114 mSiteNameToSiteIndex[site.mName] = i; 00115 } 00116 } 00117 public: 00118 // accessors 00119 /// \brief Returns the site count for this device. 00120 SiteCount getSiteCount(void) const { return SiteCount(mSites.getSize()); } 00121 /// \brief Returns the site type count for this family. 00122 SiteTypeCount getSiteTypeCount(void) const { return SiteTypeCount(mSiteTypes.getSize()); } 00123 /// \brief Returns the site types for this family. 00124 const Array<const PrimitiveDef>& getSiteTypes(void) const { return mSiteTypes; } 00125 /// \brief Returns the sites for this family. 00126 const Array<const Site>& getSites(void) const { return mSites; } 00127 /// \brief Returns the site for the specified index. 00128 const Site& getSite(SiteIndex inSiteIndex) const { return mSites[inSiteIndex]; } 00129 /// \brief Returns the packages for this family. 00130 const Array<const Package>& getPackages(void) const { return mPackages; } 00131 // functions 00132 /// \brief Returns the site index for the given site name. 00133 SiteIndex findSiteIndex(const string& inName) const { 00134 SiteNameToSiteIndexMap::const_iterator p = mSiteNameToSiteIndex.find(inName); 00135 return (p == mSiteNameToSiteIndex.end()) 00136 ? SiteIndex(SiteIndex::undefined()) : p->second; 00137 } 00138 /// \brief Returns the package index for the given package name. 00139 PackageIndex findPackageIndex(const string& inName) const { 00140 PackageNameToPackageIndexMap::const_iterator p 00141 = mPackageNameToPackageIndex.find(inName); 00142 return (p == mPackageNameToPackageIndex.end()) 00143 ? PackageIndex(PackageIndex::undefined()) : p->second; 00144 } 00145 }; 00146 00147 } // namespace architecture 00148 } // namespace torc 00149 00150 #endif // TORC_ARCHITECTURE_SITES_HPP