torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spartan6BitstreamUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit test for the SpartanBitstream class.
18 
19 #include <boost/test/unit_test.hpp>
28 #include <fstream>
29 #include <iostream>
30 
31 namespace torc {
32 namespace bitstream {
33 
34 BOOST_AUTO_TEST_SUITE(bitstream)
35 
36 /// \brief Unit test for the SpartanBitstream class.
37 BOOST_AUTO_TEST_CASE(Spartan6BitstreamCrcUnitTest) {
38  // check the CRC generation
40  / "torc" / "bitstream" / "Spartan6UnitTest.reference.bit";
41  BOOST_CHECK(checkCRC<Spartan6>(regressionPath, true));
42 }
43 
44 /// \brief Unit test for the Spartan6Bitstream class.
45 BOOST_AUTO_TEST_CASE(Spartan6BistreamUnitTest) {
46 
47  // build the file paths
49  / "torc" / "bitstream" / "Spartan6UnitTest.reference.bit";
51  / "regression" / "Spartan6BistreamUnitTest.generated.bit";
52 
53  // read the reference bitstream
54  std::fstream fileStream1(referencePath.string().c_str(), std::ios::binary | std::ios::in);
55  BOOST_REQUIRE(fileStream1.good());
56  Spartan6 bitstream1;
57  bitstream1.read(fileStream1, false);
58  // find the type 2 write packet
59  Spartan6Packet frameContents;
60  Spartan6::const_iterator p = bitstream1.begin();
61  Spartan6::const_iterator e = bitstream1.end();
62  while(p < e) {
63  if(p->isType2() && !p->isSyncWord1() && p->isWrite()) { frameContents = *p; break; }
64  p++;
65  }
66 
67  // declare a bitstream of unspecified architectures
68  Spartan6Bitstream bitstream;
69  // prepare the bitstream header
70  bitstream.setDesignName("Spartan6UnitTest.reference.ncd;UserID=0xFFFFFFFF");
71  bitstream.setDeviceName("6slx25csg324");
72  bitstream.setDesignDate("2011/02/09");
73  bitstream.setDesignTime("13:28:37");
74 
75  // construct and add packets to the bitstream
78  0, 0));
79  // dummy words
80  bitstream.insert(bitstream.end(), 8, dummy);
81  // sync
82  bitstream.push_back(Spartan6Packet(Spartan6::eSynchronizationSync0));
83  bitstream.push_back(Spartan6Packet(Spartan6::eSynchronizationSync1));
84  // reset CRC command
86  // nop command
87  bitstream.push_back(nop);
88  // FLR command
89  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterFLR, 0x0488));
90  // configuration options register 1
92  Spartan6::makeSubfield(Spartan6::eRegisterCOR1, "Drive_Awake", "0") |
96  Spartan6::makeSubfield(Spartan6::eRegisterCOR1, "StartupClk", "Cclk") |
97  0x3d00)); // No documentation for this Value
98  // configuration options register 2
100  Spartan6::makeSubfield(Spartan6::eRegisterCOR2, "Reset_on_err", "Disable") |
101  Spartan6::makeSubfield(Spartan6::eRegisterCOR2, "DONE_cycle", "5") |
102  Spartan6::makeSubfield(Spartan6::eRegisterCOR2, "LCK_cycle", "NoWait") |
104  Spartan6::makeSubfield(Spartan6::eRegisterCOR2, "GWE_cycle", "[UNDEFINED 6]") |
105  0));
106  // write the ID code
107  bitstream.push_back(Spartan6Packet::makeType1Write32(Spartan6::eRegisterIDCODE, 0x04004093));
108  // control register mask
110  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "DEC", "Writable") |
111  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "Security", "Protected") |
112  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "Persist", "Writable") |
113  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "USE_EFUSE_KEY", "Writable") |
114  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "CRC_EXTSTAT_DISABLE", "Writable") |
115  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "RESERVED", "Writable") |
116  0x80)); // No documentation for this Value
117  // control register
120  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "Security", "None") |
122  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "USE_EFUSE_KEY", "0") |
123  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "CRC_EXTSTAT_DISABLE", "0") |
124  0x0081)); // No documentation for this Value
125  bitstream.insert(bitstream.end(), 17, nop);
126  // SEU_OPT register
128  Spartan6::makeSubfield(Spartan6::eRegisterSEU_OPT, "SEU_FREQ", "0x01be") |
129  Spartan6::makeSubfield(Spartan6::eRegisterSEU_OPT, "SEU_RUN_ON_ERR", "Run") |
130  Spartan6::makeSubfield(Spartan6::eRegisterSEU_OPT, "GLUT_MASK", "Unmask") |
131  Spartan6::makeSubfield(Spartan6::eRegisterSEU_OPT, "SEU_ENABLE", "DISABLE") |
132  0x3cc0)); // No documentation for this Value
133  // PWRDN_REG register
140  0x0880)); // No documentation for this Value
141  // CBC write command
143  // HC_OPT_REG register
146  0x1f)); // No documentation for this Value
147  // CWDT write command
148  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterCWDT, 0xffff));
149  // PU_GTS write command
150  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterPU_GTS, 0x0005));
151  // MFWR write command
152  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterMFWR, 0x0004));
153  // PU_GWE write command
154  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterPU_GWE, 0x0100));
155  // GENERAL2 write command
156  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterGENERAL2, 0x0000));
157  // GENERAL3 write command
158  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterGENERAL3, 0x0000));
159  // GENERAL4 write command
160  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterGENERAL4, 0x0000));
161  // GENERAL5 write command
162  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterGENERAL5, 0x0000));
163  // MODE_REG register
168  Spartan6::makeSubfield(Spartan6::eRegisterMODE_REG, "BOOTVSEL", "[READ ONLY]") |
169  0));
170  // EXP_SIGN write command
171  bitstream.push_back(Spartan6Packet::makeType1Write(Spartan6::eRegisterEXP_SIGN, 0x1be2));
172  // EXP_SIGN write command
173  bitstream.push_back(Spartan6Packet::makeType1Write32(Spartan6::eRegisterRDBK_SIGN, 0x00000000));
174  // nop command
175  bitstream.push_back(nop);
176  bitstream.push_back(nop);
177  // frame address register
178  bitstream.push_back(Spartan6Packet::makeType1Write32(Spartan6::eRegisterFARMAJ, 0x00000000));
179  // enable configuration write command
181  // write 0 bytes to FDRI (in preparation for type 2 write packet)
182  //bitstream.push_back(Spartan6Packet::makeNullType2Write(Spartan6::eRegisterFDRI));
183  // note that we do not release the buffer as it will be taken over by the packet
184  //size_t length = 0x00061cca;
185  //uint16_t* buffer = new uint16_t[length];
186  //uint16_t* ptr = buffer + length - 1;
187  //while(ptr >= buffer) *ptr-- = 0;
188  //*(buffer + 0) = 0xabcd;
189  //*(buffer + length - 1) = 0x0123;
190  //bitstream.push_back(Spartan6Packet::makeType2Write(0x00061cca, Spartan6::eRegisterFDRI, buffer));
191  bitstream.push_back(frameContents);
192  // CRC Word?
193  uint16_t crcEndWord = 0x0015;
194  bitstream.push_back(Spartan6Packet(crcEndWord));
195  // CWDT write command
196  size_t length = 15;
197  uint16_t* buffer = new uint16_t[length];
198  uint16_t* ptr = buffer + length - 1;
199  while(ptr >= buffer) *ptr-- = 0x2000;
200  bitstream.push_back(Spartan6Packet::makeType1Write(length, Spartan6::eRegisterCWDT, buffer));
201  // 9 NOPs
202  bitstream.insert(bitstream.end(), 9, nop);
203  // restore command
206  // last frame command
209  // 4 NOPs
210  bitstream.insert(bitstream.end(), 4, nop);
211  // restore command
214  // start command
217  // control register mask
219  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "DEC", "Writable") |
220  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "Security", "Writable") |
221  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "Persist", "Writable") |
222  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "USE_EFUSE_KEY", "Writable") |
223  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "CRC_EXTSTAT_DISABLE", "Writable") |
224  Spartan6::makeSubfield(Spartan6::eRegisterMASK, "RESERVED", "Writable") |
225  0x80)); // No documentation for this Value
226  // control register
229  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "Security", "None") |
231  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "USE_EFUSE_KEY", "0") |
232  Spartan6::makeSubfield(Spartan6::eRegisterCTL, "CRC_EXTSTAT_DISABLE", "0") |
233  0x81)); // No documentation for this Value
234  // write the CRC value
235  bitstream.push_back(Spartan6Packet::makeType1Write32(Spartan6::eRegisterCRC, 0x0002109d));
236  // desync command
239  bitstream.insert(bitstream.end(), 14, nop);
240 
241  // write the bitstream back out
242  std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
243  BOOST_REQUIRE(outputStream.good());
244  bitstream.write(outputStream);
245  outputStream.flush();
246 
247  // read the bitstream
248  std::fstream fileStream2(generatedPath.string().c_str(), std::ios::binary | std::ios::in);
249  BOOST_REQUIRE(fileStream2.good());
250  Spartan6 bitstream2;
251  bitstream2.read(fileStream2, false);
252  // write the bitstream digest to the console
253  std::cout << bitstream2 << std::endl;
254  std::cerr << "TYPEOF BITSTREAM: " << typeid(bitstream2).name() << std::endl;
255 
256  // compare the reference and generated XDL
257  //BOOST_CHECK(fileContentsAreEqual(generatedPath, referencePath));
258 
259 }
260 
261 BOOST_AUTO_TEST_SUITE_END()
262 
263 } // namespace bitstream
264 } // namespace torc
265 
void setDesignTime(const string &inDesignTime)
Set the design time.
Header for torc::bitstream output stream helpers.
Header for the Spartan6Bitstream class.
Header for the DirectoryTree class.
Bitstream packet for Spartan 16 bit class architectures.
Header for the DeviceDesignator class.
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
static Spartan6Packet makeType1Write(uint16_t inAddress, uint16_t inWord)
Construct a type 1 write packet.
Header for Boost.Test helper functions.
Header for Boost.Test helper functions.
Header for the Spartan6 class.
void setDesignName(const string &inDesignName)
Set the design name.
void setDesignDate(const string &inDesignDate)
Set the design date.
static uint16_t makeSubfield(ERegister inRegister, const std::string &inSubfield, const std::string &inSetting)
Return the masked value for a subfield of the specified register.
Definition: Spartan6.cpp:329
static Spartan6Packet makeType1Write32(uint16_t inAddress, uint32_t inWord)
Construct a type 1 write packet for two words.
boost::filesystem::path path
Header for the Spartan6Packet class.
Spartan6 bitstream.
Definition: Spartan6.hpp:31
void write(std::ostream &inStream, uint8_t inVal)
Write a uint8_t to the stream.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
virtual void read(std::istream &inStream, bool inCleanDateAndTime=true)
Read the bitstream header and packets from a stream.
void setDeviceName(const string &inDeviceName)
Set the device name.
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.