00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "torc/bitstream/Spartan3E.hpp"
00020 #include <iostream>
00021
00022
00023 #include "torc/architecture/DDB.hpp"
00024 #include "torc/architecture/XilinxDatabaseTypes.hpp"
00025 #include "torc/common/DirectoryTree.hpp"
00026 #include <fstream>
00027
00028 namespace torc {
00029 namespace bitstream {
00030
00031 const char* Spartan3E::sPacketTypeName[ePacketTypeCount] = {
00032 "[UNKNOWN TYPE 0]", "TYPE1", "TYPE2", "[UNKNOWN TYPE 3]", "[UNKNOWN TYPE 4]",
00033 "[UNKNOWN TYPE 5]", "[UNKNOWN TYPE 6]", "[UNKNOWN TYPE 7]"
00034 };
00035
00036 const char* Spartan3E::sOpcodeName[eOpcodeCount] = {
00037 "NOP", "READ", "WRITE", "RESERVED"
00038 };
00039
00040 const char* Spartan3E::sRegisterName[eRegisterCount] = {
00041 "CRC", "FAR", "FDRI", "FDRO", "CMD", "CTL", "MASK", "STAT", "LOUT", "COR", "MFWR", "FLR",
00042 "[UNKNOWN_REGISTER 12]", "[UNKNOWN_REGISTER 13]", "IDCODE"
00043 };
00044
00045 const char* Spartan3E::sCommandName[eCommandCount] = {
00046 "NULL", "WCFG", "MFWR", "LFRM", "RCFG", "START", "RCAP", "RCRC", "AGHIGH", "SWITCH",
00047 "GRESTORE", "SHUTDOWN", "GCAPTURE", "DESYNCH"
00048 };
00049
00050 #define VALUES (const char*[])
00051
00052
00053 const Bitstream::Subfield Spartan3E::sCOR[] = {
00054 {0x00000007, 0, "GWE_cycle", "GWE_CYCLE", 5,
00055
00056
00057 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00058 {0x00000038, 3, "GTS_cycle", "GTS_CYCLE", 4,
00059
00060
00061 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00062 {0x000001c0, 6, "LCK_cycle", "LOCK_CYCLE", 7,
00063
00064
00065 VALUES{"1", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "NoWait", 0}},
00066 {0x00000E00, 9, "Match_cycle", "MATCH_CYCLE", 7,
00067
00068
00069 VALUES{"1", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "NoWait", 0}},
00070 {0x00007000, 12, "DONE_cycle", "DONE_CYCLE", 3,
00071
00072
00073 VALUES{"[UNDEFINED 0]", "2", "3", "4", "5", "6", "[UNDEFINED 6]", "[UNDEFINED 7]", 0}},
00074 {0x00018000, 15, "StartupClk", "SSCLKSRC", 0,
00075
00076
00077 VALUES{"Cclk", "UserClk", "JtagClk", "JtagClk", 0}},
00078 {0x00780000, 19, "ConfigRate", "OSCFSEL", 0,
00079
00080
00081 VALUES{
00082 "[UNKNOWN 0]", "[UNKNOWN 1]", "[UNKNOWN 2]", "[UNKNOWN 3]",
00083 "[UNKNOWN 4]", "[UNKNOWN 5]", "[UNKNOWN 6]", "[UNKNOWN 7]",
00084 "[UNKNOWN 8]", "[UNKNOWN 9]", "[UNKNOWN 10]", "[UNKNOWN 11]",
00085 "[UNKNOWN 12]", "[UNKNOWN 13]", "[UNKNOWN 14]", "[UNKNOWN 15]",
00086 0}},
00087 {0x00800000, 23, "Capture", "SINGLE", 0,
00088
00089
00090 VALUES{"Continuous", "OneShot", 0}},
00091 {0x01000000, 24, "DriveDone", "DRIVE_DONE", 0,
00092
00093
00094 VALUES{"No", "Yes", 0}},
00095 {0x02000000, 25, "DonePipe", "DONE_PIPE", 0,
00096
00097
00098 VALUES{"No", "Yes", 0}},
00099 {0x20000000, 29, "CRC", "CRC_BYPASS", 0,
00100
00101
00102 VALUES{"Enable", "Disable", 0}},
00103 {0, 0, 0, 0, 0, 0}
00104 };
00105
00106
00107
00108 const Bitstream::Subfield Spartan3E::sSTAT[] = {
00109 {0x00000001, 0, "CRC_error", "CRC_ERROR", 0,
00110
00111
00112 VALUES{"No", "Yes", 0}},
00113 {0x00000004, 2, "DCM_locked", "DCM_LOCK", 0,
00114
00115
00116 VALUES{"No", "Yes", 0}},
00117 {0x00000008, 3, "DCI_matched", "DCI_MATCH", 0,
00118
00119
00120 VALUES{"No", "Yes", 0}},
00121 {0x00000010, 4, "IN_error", "IN_ERROR", 0,
00122
00123
00124 VALUES{"No", "Yes", 0}},
00125 {0x00000020, 5, "GTS_CFG", "GTS_CFG_B", 0,
00126
00127
00128 VALUES{"IoDisabled", "IoEnabled", 0}},
00129 {0x00000040, 6, "GWE", "GWE", 0,
00130
00131
00132
00133 VALUES{"WriteDisabled", "WriteEnabled", 0}},
00134 {0x00000080, 7, "GHIGH_B", "GHIGH_B", 0,
00135
00136
00137 VALUES{"InterconnectDisabled", "InterconnectEnabled", 0}},
00138 {0x00000700, 8, "Mode", "MODE", 0,
00139
00140
00141 VALUES{"MasterSerial", "SlaveSelectMap32", "[UNDEFINED 2]", "MasterSelectMap",
00142 "[UNDEFINED 3]", "JTAG", "SlaveSelectMap8", "[UNDEFINED 6]", "SlaveSerial", 0}},
00143 {0x00000800, 11, "INIT", "INIT", 0,
00144
00145
00146 VALUES{"Deasserted", "Asserted", 0}},
00147 {0x00001000, 12, "Done", "DONE", 0,
00148
00149
00150 VALUES{"Deasserted", "Asserted", 0}},
00151 {0x00002000, 13, "ID_error", "ID_ERROR", 0,
00152
00153
00154 VALUES{"No", "Yes", 0}},
00155 {0, 0, 0, 0, 0, 0}
00156 };
00157
00158
00159 const Bitstream::Subfield Spartan3E::sCTL[] = {
00160 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0,
00161
00162
00163 VALUES{"IoDisabled", "IoActive", 0}},
00164 {0x00000008, 3, "Persist", "PERSIST", 0,
00165
00166
00167 VALUES{"No", "Yes", 0}},
00168 {0x00000030, 4, "Security", "SBITS", 0,
00169
00170
00171
00172 VALUES{"None", "Level1", "Level2", "Level2", 0}},
00173 {0, 0, 0, 0, 0, 0}
00174 };
00175
00176
00177 const Bitstream::Subfield Spartan3E::sMASK[] = {
00178 {0x00000001, 0, "GTS_USER_B", "GTS_USER_B", 0, VALUES{"Protected", "Writable", 0}},
00179 {0x00000008, 3, "Persist", "PERSIST", 0, VALUES{"Protected", "Writable", 0}},
00180 {0x00000080, 4, "Security", "SBITS", 0,
00181 VALUES{"Protected", "[UNKNOWN 1]", "[UNKNOWN 2]", "Writable", 0}},
00182 {0, 0, 0, 0, 0, 0}
00183 };
00184
00185
00186 uint32_t Spartan3E::makeSubfield(ERegister inRegister, const std::string& inSubfield,
00187 const std::string& inSetting) {
00188 const Subfield* subfields;
00189 switch(inRegister) {
00190 case eRegisterCOR: subfields = sCOR; break;
00191 case eRegisterSTAT: subfields = sSTAT; break;
00192 case eRegisterCTL: subfields = sCTL; break;
00193 case eRegisterMASK: subfields = sMASK; break;
00194 default: return 0;
00195 }
00196 for(uint32_t field = 0; subfields[field].mMask != 0; field++) {
00197 const Subfield& subfield = subfields[field];
00198 if(inSubfield != subfield.mBitgenName && inSubfield != subfield.mConfigGuideName)
00199 continue;
00200 const char** ptr = subfield.mValues;
00201 for(uint32_t i = 0; *ptr != 0; i++, ptr++) {
00202 if(inSetting == *ptr) return (i << subfield.mShift) & subfield.mMask;
00203 }
00204 }
00205 return 0;
00206 }
00207
00208
00209
00210 #ifndef GENERATE_STATIC_DEVICE_INFO
00211
00212 extern DeviceInfo xc3s100e;
00213 extern DeviceInfo xc3s250e;
00214 extern DeviceInfo xc3s500e;
00215 extern DeviceInfo xc3s1200e;
00216 extern DeviceInfo xc3s1600e;
00217
00218 void Spartan3E::initializeDeviceInfo(const std::string& inDeviceName) {
00219 using namespace torc::common;
00220 switch(mDevice) {
00221 case eXC3S100E: setDeviceInfo(xc3s100e); break;
00222 case eXC3S250E: setDeviceInfo(xc3s250e); break;
00223 case eXC3S500E: setDeviceInfo(xc3s500e); break;
00224 case eXC3S1200E: setDeviceInfo(xc3s1200e); break;
00225 case eXC3S1600E: setDeviceInfo(xc3s1600e); break;
00226 default: break;
00227 }
00228 }
00229
00230 #else
00231
00232 void Spartan3E::initializeDeviceInfo(const std::string& inDeviceName) {
00233
00234 typedef torc::architecture::xilinx::TileCount TileCount;
00235 typedef torc::architecture::xilinx::TileRow TileRow;
00236 typedef torc::architecture::xilinx::TileCol TileCol;
00237 typedef torc::architecture::xilinx::TileTypeIndex TileTypeIndex;
00238 typedef torc::architecture::xilinx::TileTypeCount TileTypeCount;
00239
00240
00241 torc::architecture::DDB ddb(inDeviceName);
00242 const torc::architecture::Tiles& tiles = ddb.getTiles();
00243 uint32_t tileCount = tiles.getTileCount();
00244 uint16_t rowCount = tiles.getRowCount();
00245 uint16_t colCount = tiles.getColCount();
00246 ColumnTypeVector columnTypes;
00247
00248
00249 typedef std::map<TileTypeIndex, std::string> TileTypeIndexToName;
00250 typedef std::map<std::string, TileTypeIndex> TileTypeNameToIndex;
00251 TileTypeIndexToName tileTypeIndexToName;
00252 TileTypeNameToIndex tileTypeNameToIndex;
00253 TileTypeCount tileTypeCount = tiles.getTileTypeCount();
00254 for(TileTypeIndex tileTypeIndex(0); tileTypeIndex < tileTypeCount; tileTypeIndex++) {
00255 const std::string tileTypeName = tiles.getTileTypeName(tileTypeIndex);
00256 tileTypeIndexToName[tileTypeIndex] = tileTypeName;
00257 tileTypeNameToIndex[tileTypeName] = tileTypeIndex;
00258 TileTypeNameToColumnType::iterator ttwp = mTileTypeNameToColumnType.find(tileTypeName);
00259 TileTypeNameToColumnType::iterator ttwe = mTileTypeNameToColumnType.end();
00260 if(ttwp != ttwe) mTileTypeIndexToColumnType[tileTypeIndex] = EColumnType(ttwp->second);
00261 }
00262
00263
00264 columnTypes.resize(colCount);
00265 uint32_t frameCount = 0;
00266 for(uint32_t blockType = 0; blockType < Spartan3E::eFarBlockTypeCount; blockType++) {
00267 for(TileCol col; col < colCount; col++) {
00268 columnTypes[col] = eColumnTypeEmpty;
00269 TileTypeIndexToColumnType::iterator ttwe = mTileTypeIndexToColumnType.end();
00270 TileTypeIndexToColumnType::iterator ttwp = ttwe;
00271
00272 for(TileRow row(8); row < rowCount-6; row++) {
00273
00274 const torc::architecture::TileInfo& tileInfo
00275 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00276 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00277
00278 ttwp = mTileTypeIndexToColumnType.find(tileTypeIndex);
00279 if(ttwp != ttwe) {
00280 uint32_t width = mColumnDefs[ttwp->second][blockType];
00281 frameCount += width;
00282
00283
00284 columnTypes[col] = static_cast<EColumnType>(ttwp->second);
00285 break;
00286 }
00287 }
00288 }
00289
00290 if(blockType == 2) break;
00291 }
00292
00293 boost::filesystem::path workingPath = torc::common::DirectoryTree::getWorkingPath();
00294 boost::filesystem::path generatedMap = workingPath / (inDeviceName + ".map.csv");
00295 std::fstream tilemapStream(generatedMap.string().c_str(), std::ios::out);
00296 for(TileRow row; row < rowCount; row++) {
00297 for(TileCol col; col < colCount; col++) {
00298 const torc::architecture::TileInfo& tileInfo
00299 = tiles.getTileInfo(tiles.getTileIndex(row, col));
00300 TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
00301 tilemapStream << tiles.getTileTypeName(tileTypeIndex);
00302 if(col + 1 < colCount) tilemapStream << ",";
00303 }
00304 tilemapStream << std::endl;
00305 }
00306 tilemapStream.close();
00307
00308
00309 setDeviceInfo(DeviceInfo(tileCount, rowCount, colCount, columnTypes));
00310 }
00311 #endif
00312
00313 void Spartan3E::initializeFrameMaps(void) {
00314
00315 uint32_t frameCount = 0;
00316 uint32_t frameIndex = 0;
00317 bool clockColumn = true;
00318 uint32_t width;
00319 for(uint32_t i = 0; i < Spartan3E::eFarBlockTypeCount; i++) {
00320 Spartan3E::EFarBlockType blockType = Spartan3E::EFarBlockType(i);
00321
00322 uint32_t bitIndex = 0;
00323 uint32_t xdlIndex = 0;
00324 mBitColumnIndexes[i].push_back(bitIndex);
00325 mXdlColumnIndexes[i].push_back(xdlIndex);
00326
00327 uint32_t farMajor = 0;
00328 typedef torc::common::EncapsulatedInteger<uint16_t> ColumnIndex;
00329 if(clockColumn) {
00330 if(mDeviceInfo.getColCount() > 41)
00331 width = mColumnDefs[eColumnTypeClockLL][i];
00332 else
00333 width = mColumnDefs[eColumnTypeClock][i];
00334 clockColumn = false;
00335 for(uint32_t farMinor = 0; farMinor < width; farMinor++) {
00336 Spartan3E::FrameAddress far(blockType, farMajor, farMinor);
00337 mFrameIndexToAddress[frameIndex] = far;
00338 mFrameAddressToIndex[far] = frameIndex;
00339 frameIndex++;
00340 }
00341 if(width > 0) farMajor++;
00342 frameCount += width;
00343 }
00344 for(ColumnIndex col; col < mDeviceInfo.getColCount(); col++) {
00345 if(mDeviceInfo.getColumnTypes()[col] == eColumnTypeClock ||
00346 mDeviceInfo.getColumnTypes()[col] == eColumnTypeClockLL)
00347 continue;
00348 else
00349 {
00350 width = mColumnDefs[mDeviceInfo.getColumnTypes()[col]][i];
00351
00352 }
00353 for(uint32_t farMinor = 0; farMinor < width; farMinor++) {
00354 Spartan3E::FrameAddress far(blockType, farMajor, farMinor);
00355 mFrameIndexToAddress[frameIndex] = far;
00356 mFrameAddressToIndex[far] = frameIndex;
00357 frameIndex++;
00358 }
00359 if(width > 0) farMajor++;
00360 frameCount += width;
00361
00362
00363 if(mDeviceInfo.getColumnTypes()[col] != Spartan3E::eColumnTypeEmpty) {
00364 bitIndex += width;
00365 mBitColumnIndexes[i].push_back(bitIndex);
00366 }
00367
00368
00369 xdlIndex += width;
00370 mXdlColumnIndexes[i].push_back(xdlIndex);
00371 }
00372 }
00373
00374
00375 bool debug = false;
00376 if (debug) {
00377 for(uint32_t i = 0; i < Spartan3E::eFarBlockTypeCount; i++) {
00378 for(uint32_t j = 0; j < mBitColumnIndexes[i].size(); j++)
00379 std::cout << "Bit Value at index: (" << i << ", " << j << ") : " << mBitColumnIndexes[i][j] << std::endl;
00380 for(uint32_t k = 0; k < mXdlColumnIndexes[i].size(); k++)
00381 std::cout << "Xdl Value at index: (" << i << ", " << k << ") : " << mXdlColumnIndexes[i][k] << std::endl;
00382 }
00383 }
00384 }
00385
00386
00387
00388 }
00389 }