19 #include <boost/crc.hpp>
22 using namespace torc::common;
27 void SpartanBitstream::readPackets(std::istream& inStream) {
28 uint32_t bitstreamWordLength = mBitstreamByteLength >> 2;
30 while(cumulativeWordLength < bitstreamWordLength) {
31 push_back(SpartanPacket::read(inStream));
32 uint32_t wordSize = back().getWordSize();
33 cumulativeWordLength += wordSize;
35 if(wordSize <= getFrameLength())
continue;
37 inStream.read((
char*) &autoCrc,
sizeof(autoCrc));
38 autoCrc = ntohl(autoCrc);
40 cumulativeWordLength++;
44 void SpartanBitstream::writePackets(std::ostream& inStream) {
45 const_iterator p = begin();
46 const_iterator e = end();
47 while(p < e) p++->write(inStream);
50 void SpartanBitstream::preflightPackets(
void) {
63 cmdRegister = Spartan3E::eRegisterCMD; rcrcCommand = Spartan3E::eCommandRCRC;
64 fdriRegister = Spartan3E::eRegisterFDRI; crcRegister = Spartan3E::eRegisterCRC;
65 addressLength = 5; autoCrc =
true;
68 std::cerr <<
"Unsupported architecture in SpartanBitstream::preflightPackets()."
77 boost::crc_basic<16> crc16(0x8005, 0, 0,
false,
true);
85 if(wordCount == 0)
continue;
87 if(address == crcRegister) {
90 *(p-1) = SpartanPacket::makeType1Write(crcRegister, crc16.checksum());
93 }
else if(address == cmdRegister && wordCount >= 1 && packet[1] == rcrcCommand) {
99 for(
uint32_t i = 1; i <= wordCount; i++) {
103 for(j = 0, mask = 1; j < 32; j++, mask <<= 1) {
104 crc16.process_bit((word & mask) ? 1 : 0);
106 for(j = 0, mask = 1; j < addressLength; j++, mask <<= 1) {
107 crc16.process_bit((address & mask) ? 1 : 0);
111 if(autoCrc && address == fdriRegister) {
121 void SpartanBitstream::updatePacketLength(
void) {
123 iterator p = begin();
125 while(p < e) totalWordCount += (p++)->getWordSize();
126 mBitstreamByteLength = totalWordCount << 2;
Encapsulation of a device designator and its constituent elements.
const EFamily & getFamily(void) const
Returns the device family.
Header for the DeviceDesignator class.
boost::uint32_t uint32_t
Imported type name.
Header for the SpartanBitstream class.
Header for the Spartan3E class.
Bitstream packet for Spartan class architectures.
int getAddress(void) const
uint32_t getWordCount(void) const
Returns the number of payload words in the packet, excluding the header word.