00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/bitstream/Spartan6Bitstream.hpp"
00017 #include <boost/crc.hpp>
00018 #include <stdio.h>
00019
00020 namespace torc {
00021 namespace bitstream {
00022
00023 void Spartan6Bitstream::readPackets(std::istream& inStream) {
00024 uint16_t bitstreamWordLength = mBitstreamByteLength >> 1;
00025 uint16_t cumulativeWordLength = 0;
00026 while(cumulativeWordLength < bitstreamWordLength) {
00027 push_back(Spartan6Packet::read(inStream));
00028 cumulativeWordLength += back().getWordSize();
00029 }
00030 }
00031
00032 void Spartan6Bitstream::writePackets(std::ostream& inStream) {
00033 const_iterator p = begin();
00034 const_iterator e = end();
00035 while(p < e) p++->write(inStream);
00036 }
00037
00038 void Spartan6Bitstream::preflightPackets(void) {
00039 return;
00040 uint32_t crc;
00041 uint32_t address = 0;
00042 const_iterator p = begin();
00043 const_iterator e = end();
00044 boost::crc_basic<32> crc32(0x1EDC6F41, 0, 0, false, false);
00045 while(p < e) {
00046
00047 const Spartan6Packet& packet = *p++;
00048 if(!packet.isWrite()) continue;
00049 address = packet.getAddress();
00050 uint32_t wordCount = packet.getWordCount();
00051 if(wordCount == 0) continue;
00052
00053 if(address == 0) {
00054 printf("\n\nExpected CRC: %X%X\n", packet[1],packet[2]);
00055 crc = crc32.checksum();
00056 printf("Calculated CRC: %X\n\n\n", crc);
00057 crc = 0;
00058 crc32.reset();
00059 }
00060
00061 else if(address == 5 && wordCount >= 1 && packet[1] == 7) {
00062 crc = 0;
00063 crc32.reset();
00064
00065 }
00066 else {
00067 for(uint32_t i = 1; i <= wordCount; i++) {
00068 uint16_t word = packet[i];
00069 printf("Address: %2.2X\n", address);
00070 printf("Word (%d): %4.4X\n", i, word);
00071 uint16_t j;
00072 uint16_t mask;
00073 for(j = 0, mask = 1; j < 16; j++, mask <<= 1) {
00074 crc32.process_bits((word & mask) ? 1 : 0, 1);
00075 printf("\t%8.8X\n", crc32.checksum());
00076 }
00077 for(j = 0, mask = 1; j < 6; j++, mask <<= 1) {
00078 crc32.process_bits((address & mask) ? 1 : 0, 1);
00079 printf("\t\t%8.8X\n", crc32.checksum());
00080 }
00081 printf("\t\t\t%8.8X\n", crc32.checksum());
00082 }
00083
00084 if (packet.isType2()){
00085 crc = crc32.checksum();
00086 printf("Calculated Auto CRC: %X\n", crc);
00087 crc = 0;
00088 crc32.reset();
00089 }
00090 }
00091 }
00092 }
00093
00094 void Spartan6Bitstream::updatePacketLength(void) {
00095 uint32_t totalWordCount = 0;
00096 iterator p = begin();
00097 iterator e = end();
00098 while(p < e) totalWordCount += (p++)->getWordSize();
00099 mBitstreamByteLength = totalWordCount << 1;
00100 }
00101
00102 }
00103 }