torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spartan6Bitstream.hpp
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 Header for the Spartan6Bitstream class.
18 
19 #ifndef TORC_BITSTREAM_SPARTAN6BITSTREAM_HPP
20 #define TORC_BITSTREAM_SPARTAN6BITSTREAM_HPP
21 
22 #include <boost/cstdint.hpp>
25 
26 namespace torc {
27 namespace bitstream {
28 
29 namespace bitstream { class Spartan6BitstreamUnitTest; }
30 
31  /// \brief Spartan-class bitstream.
32  class Spartan6Bitstream : virtual public Bitstream, public Spartan6PacketVector,
35  protected:
36  // typedefs
37  /// \brief Imported type name.
38  typedef boost::uint16_t uint16_t;
39  typedef boost::uint32_t uint32_t;
40  // inner classes
41  /// \brief CRC class for the Spartan6 architecture.
42  struct CRC {
43  /// \brief Length of the CRC calculation.
44  enum { eLen = 22 };
45  /// \brief CRC calculation bits.
47  /// \brief CRC calculation value.
49  /// \brief Default constructor.
50  CRC(void) { reset(); }
51  /// \brief Function to clear the CRC calculation.
52  void reset(void) { for(int32_t i = 0; i < eLen; i++) mBits[i] = 0; mValue = 0; }
53  /// \brief Update the CRC with new data.
54  void update(uint32_t inAddress, uint32_t inWord) {
55  uint8_t input[eLen];
56  uint8_t next[eLen];
57  // initialize the input with the current register address and data word
58  for(int32_t i = 21, mask = 0x20; i >= 16; i--, mask >>= 1)
59  input[i] = (inAddress & mask) ? 1 : 0;
60  for(int32_t i = 15, mask = 0x8000; i >= 0; i--, mask >>= 1)
61  input[i] = (inWord & mask) ? 1 : 0;
62  // update the CRC
63  for(int32_t i = 21; i >= 16; i--) next[i] = mBits[i - 1] ^ input[i];
64  next[15] = mBits[14] ^ input[15] ^ mBits[21];
65  for(int32_t i = 14; i >= 13; i--) next[i] = mBits[i - 1] ^ input[i];
66  next[12] = mBits[11] ^ input[12] ^ mBits[21];
67  for(int32_t i = 11; i >= 8; i--) next[i] = mBits[i - 1] ^ input[i];
68  next[7] = mBits[6] ^ input[7] ^ mBits[21];
69  for(int32_t i = 6; i >= 1; i--) next[i] = mBits[i - 1] ^ input[i];
70  next[0] = input[0] ^ mBits[21];
71  // copy the updated bits into place
72  mValue = 0;
73  for(int32_t i = 0, mask = 1; i < eLen; i++, mask <<= 1) {
74  mBits[i] = next[i];
75  mValue |= mBits[i] ? mask : 0;
76  }
77  }
78  /// \brief Index operator.
79  uint8_t& operator[] (int i) { return mBits[i]; }
80  /// \brief Cast operator to return the CRC as an integer.
81  operator uint32_t (void) const { return mValue; }
82  };
83  // members
84  public:
85  // constructors
86  /// \brief Basic constructor.
88  // functions
89  /// \brief Read bitstream packets from a stream.
90  /// \note This function should be called after the bitstream header has been read.
91  virtual void readPackets(std::istream& inStream);
92  /// \brief Write bitstream packets to a stream.
93  virtual void writePackets(std::ostream& inStream);
94  /// \brief Preflight the packets.
95  virtual void preflightPackets(void);
96  /// \brief Update the header packet length.
97  virtual void updatePacketLength(void);
98  };
99 
100 } // namespace bitstream
101 } // namespace torc
102 
103 #endif // TORC_BITSTREAM_SPARTAN6BITSTREAM_HPP
boost::uint16_t uint16_t
Imported type name.
virtual void preflightPackets(void)
Preflight the packets.
virtual void writePackets(std::ostream &inStream)
Write bitstream packets to a stream.
void reset(void)
Function to clear the CRC calculation.
void update(uint32_t inAddress, uint32_t inWord)
Update the CRC with new data.
Spartan6Bitstream(void)
Basic constructor.
virtual void updatePacketLength(void)
Update the header packet length.
friend class torc::bitstream::bitstream::Spartan6BitstreamUnitTest
boost::uint8_t uint8_t
Imported type name.
Bitstream packet constants for Spartan 16 bit class architectures.
boost::uint32_t uint32_t
Imported type name.
virtual void readPackets(std::istream &inStream)
Read bitstream packets from a stream.
std::vector< Spartan6Packet > Spartan6PacketVector
Vector of Spartan 16 bit packets.
Xilinx bitstream base class.
CRC class for the Spartan6 architecture.
Header for the Bitstream class.
Header for the Spartan6Packet class.
uint32_t mValue
CRC calculation value.
uint8_t & operator[](int i)
Index operator.
uint8_t mBits[eLen]
CRC calculation bits.