torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::bitstream::Spartan6Packet Class Reference

Bitstream packet for Spartan 16 bit class architectures. More...

#include <Spartan6Packet.hpp>

+ Inheritance diagram for torc::bitstream::Spartan6Packet:
+ Collaboration diagram for torc::bitstream::Spartan6Packet:

Public Types

enum  EPacketType { ePacketType1 = 1, ePacketType2, ePacketTypeCount = 8 }
 Packet type enumeration. More...
 
enum  EOpcode {
  eOpcodeNOP = 0, eOpcodeRead, eOpcodeWrite, eOpcodeReserved,
  eOpcodeCount
}
 Packet opcode enumeration. More...
 
enum  EPacket {
  ePacketMaskType = 0xe000, ePacketShiftType = 13, ePacketMaskOpcode = 0x1800, ePacketShiftOpcode = 11,
  ePacketMaskTypeAddress = 0x07e0, ePacketShiftTypeAddress = 5, ePacketMaskType1Count = 0x001f, ePacketShiftType1Count = 0,
  ePacketMaskType2Count0 = 0xffff, ePacketShiftType2Count0 = 0, ePacketMaskType2Count1 = 0xffff, ePacketShiftType2Count1 = 0
}
 Packet subfields. More...
 
enum  ESynchronization {
  eSynchronizationDummy = 0xffff, eSynchronizationSync0 = 0xaa99, eSynchronizationSync1 = 0x5566, eSynchronizationBusWidthSync0 = 0x0000,
  eSynchronizationBusWidthSync1 = 0x00bb, eSynchronizationBusWidthDetect0 = 0x1122, eSynchronizationBusWidthDetect1 = 0x0044
}
 Synchronization words. More...
 

Public Member Functions

 Spartan6Packet (void)
 Null constructor. More...
 
 Spartan6Packet (uint16_t inHeader, uint32_t inCount, uint16_t inWord, uint16_t *inWords)
 Full constructor. More...
 
 Spartan6Packet (uint16_t inHeader, uint16_t inWord)
 Header plus single word constructor. More...
 
 Spartan6Packet (uint16_t inHeader)
 Header only constructor. More...
 
 Spartan6Packet (const Spartan6Packet &rhs)
 Copy constructor. More...
 
void write (std::ostream &inStream) const
 Write a packet. More...
 
uint16_t operator[] (size_t inIndex) const
 
EPacketType getType (void) const
 
EOpcode getOpcode (void) const
 
int getAddress (void) const
 
uint16_t getHeader (void) const
 
uint32_t getWordCount (void) const
 Returns the number of payload words in the packet, excluding the header word. More...
 
uint32_t getWordSize (void) const
 Returns the total number of words in the packet, including the header word. In the case of Type 2 packets, we also include the two implicity length words. More...
 
const WordSharedArray getWords (void) const
 brief Returns the raw packet words, including the header word. More...
 
bool isType1 (void) const
 
bool isType2 (void) const
 
bool isNop (void) const
 
bool isReserved (void) const
 
bool isRead (void) const
 
bool isWrite (void) const
 
bool isDummyWord (void) const
 
bool isSyncWord0 (void) const
 
bool isSyncWord1 (void) const
 
bool isBusWidthSyncWord0 (void) const
 
bool isBusWidthSyncWord1 (void) const
 
bool isBusWidthDetectWord0 (void) const
 
bool isBusWidthDetectWord1 (void) const
 

Static Public Member Functions

static Spartan6Packet read (std::istream &inStream)
 Read a packet. More...
 
static Spartan6Packet makeType1Write (uint16_t inAddress, uint16_t inWord)
 Construct a type 1 write packet. More...
 
static Spartan6Packet makeType1Write32 (uint16_t inAddress, uint32_t inWord)
 Construct a type 1 write packet for two words. More...
 
static Spartan6Packet makeType1Write (uint16_t inAddress, uint16_t inWord1, uint16_t inWord2)
 Construct a type 1 write packet for two words. More...
 
static Spartan6Packet makeType1Write (uint32_t inCount, uint16_t inAddress, uint16_t *inWords)
 Construct a type 1 write packet for multiple words. More...
 
static Spartan6Packet makeType2Write (uint32_t inCount, uint16_t inAddress, uint16_t *inWords)
 Construct a type 2 write packet. More...
 
static uint16_t makeHeader (EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
 Construct a packet header. More...
 

Data Fields

uint16_t mHeader
 
uint32_t mCount
 
uint16_t mWord
 
WordSharedArray mWords
 
EPacketType mType
 
EOpcode mOpcode
 
int mAddress
 

Static Public Attributes

static const char * sPacketTypeName [ePacketTypeCount]
 Packet type names. More...
 
static const char * sOpcodeName [eOpcodeCount]
 Packet opcode names. More...
 

Protected Types

typedef boost::uint16_t uint16_t
 Imported type name. More...
 
typedef boost::uint32_t uint32_t
 
typedef boost::shared_array
< uint16_t
WordSharedArray
 Word shared array type. More...
 

Protected Member Functions

void initialize (void)
 

Friends

class torc::bitstream::bitstream::Spartan6PacketUnitTest
 

Detailed Description

Bitstream packet for Spartan 16 bit class architectures.

Definition at line 75 of file Spartan6Packet.hpp.

Member Typedef Documentation

typedef boost::uint16_t torc::bitstream::Spartan6Packet::uint16_t
protected

Imported type name.

Definition at line 80 of file Spartan6Packet.hpp.

typedef boost::uint32_t torc::bitstream::Spartan6Packet::uint32_t
protected

Definition at line 81 of file Spartan6Packet.hpp.

typedef boost::shared_array<uint16_t> torc::bitstream::Spartan6Packet::WordSharedArray
protected

Word shared array type.

Definition at line 83 of file Spartan6Packet.hpp.

Member Enumeration Documentation

Packet subfields.

See Also
type 1 packet format: UG380, v2.2, July 30, 2010, Table 5-24
type 2 packet format: UG380, v2.2, July 30, 2010, Table 5-26
type 2 packet format: UG380, v2.2, July 30, 2010, Table 5-27
Enumerator
ePacketMaskType 
ePacketShiftType 
ePacketMaskOpcode 
ePacketShiftOpcode 
ePacketMaskTypeAddress 
ePacketShiftTypeAddress 
ePacketMaskType1Count 
ePacketShiftType1Count 
ePacketMaskType2Count0 
ePacketShiftType2Count0 
ePacketMaskType2Count1 
ePacketShiftType2Count1 

Definition at line 49 of file Spartan6Packet.hpp.

49  {
50  // generic packet subfields
51  ePacketMaskType = 0xe000, ePacketShiftType = 13,
54  // type 1 packet subfields
56  // type 2 packet subfields
59  };

Packet type enumeration.

See Also
packet type: UG380, v2.2, July 30, 2010, Table 5-24, 5-26
Enumerator
ePacketType1 
ePacketType2 
ePacketTypeCount 

Definition at line 40 of file Spartan6Packet.hpp.

Constructor & Destructor Documentation

torc::bitstream::Spartan6Packet::Spartan6Packet ( void  )
inline
torc::bitstream::Spartan6Packet::Spartan6Packet ( uint16_t  inHeader,
uint32_t  inCount,
uint16_t  inWord,
uint16_t inWords 
)
inline

Full constructor.

Definition at line 110 of file Spartan6Packet.hpp.

+ Here is the call graph for this function:

torc::bitstream::Spartan6Packet::Spartan6Packet ( uint16_t  inHeader,
uint16_t  inWord 
)
inline

Header plus single word constructor.

Definition at line 116 of file Spartan6Packet.hpp.

+ Here is the call graph for this function:

torc::bitstream::Spartan6Packet::Spartan6Packet ( uint16_t  inHeader)
inline
torc::bitstream::Spartan6Packet::Spartan6Packet ( const Spartan6Packet rhs)
inline

Copy constructor.

Definition at line 126 of file Spartan6Packet.hpp.

+ Here is the call graph for this function:

Member Function Documentation

int torc::bitstream::Spartan6Packet::getAddress ( void  ) const
inline

Definition at line 282 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

uint16_t torc::bitstream::Spartan6Packet::getHeader ( void  ) const
inline

Definition at line 283 of file Spartan6Packet.hpp.

283 { return mHeader; }

+ Here is the caller graph for this function:

EOpcode torc::bitstream::Spartan6Packet::getOpcode ( void  ) const
inline

Definition at line 281 of file Spartan6Packet.hpp.

281 { return mOpcode; }

+ Here is the caller graph for this function:

EPacketType torc::bitstream::Spartan6Packet::getType ( void  ) const
inline

Definition at line 280 of file Spartan6Packet.hpp.

280 { return mType; }

+ Here is the caller graph for this function:

uint32_t torc::bitstream::Spartan6Packet::getWordCount ( void  ) const
inline

Returns the number of payload words in the packet, excluding the header word.

Definition at line 285 of file Spartan6Packet.hpp.

285 { return mCount; }

+ Here is the caller graph for this function:

const WordSharedArray torc::bitstream::Spartan6Packet::getWords ( void  ) const
inline

brief Returns the raw packet words, including the header word.

Definition at line 293 of file Spartan6Packet.hpp.

293 { return mWords; }

+ Here is the caller graph for this function:

uint32_t torc::bitstream::Spartan6Packet::getWordSize ( void  ) const
inline

Returns the total number of words in the packet, including the header word. In the case of Type 2 packets, we also include the two implicity length words.

Definition at line 288 of file Spartan6Packet.hpp.

288  {
289  if(isType2() && !isSyncWord1()) return mCount + 1 + 2;
290  return mCount + 1;
291  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void torc::bitstream::Spartan6Packet::initialize ( void  )
inlineprotected

Definition at line 85 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isBusWidthDetectWord0 ( void  ) const
inline
bool torc::bitstream::Spartan6Packet::isBusWidthDetectWord1 ( void  ) const
inline
bool torc::bitstream::Spartan6Packet::isBusWidthSyncWord0 ( void  ) const
inline
bool torc::bitstream::Spartan6Packet::isBusWidthSyncWord1 ( void  ) const
inline
bool torc::bitstream::Spartan6Packet::isDummyWord ( void  ) const
inline

Definition at line 301 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isNop ( void  ) const
inline

Definition at line 297 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isRead ( void  ) const
inline

Definition at line 299 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isReserved ( void  ) const
inline

Definition at line 298 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isSyncWord0 ( void  ) const
inline

Definition at line 302 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isSyncWord1 ( void  ) const
inline

Definition at line 303 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isType1 ( void  ) const
inline
bool torc::bitstream::Spartan6Packet::isType2 ( void  ) const
inline

Definition at line 296 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

bool torc::bitstream::Spartan6Packet::isWrite ( void  ) const
inline

Definition at line 300 of file Spartan6Packet.hpp.

+ Here is the caller graph for this function:

static uint16_t torc::bitstream::Spartan6Packet::makeHeader ( EPacketType  inType,
EOpcode  inOpcode,
uint16_t  inAddress,
uint32_t  inCount 
)
inlinestatic

Construct a packet header.

Todo:
Generate an error or throw an exception on invalid packet types?

Definition at line 254 of file Spartan6Packet.hpp.

255  {
256  // type 1 packets
257  if(inType == ePacketType1) return
258  ((inType << ePacketShiftType) & ePacketMaskType) |
259  ((inOpcode << ePacketShiftOpcode) & ePacketMaskOpcode) |
262  // type 2 packets
263  else if(inType == ePacketType2) return
264  ((inType << ePacketShiftType) & ePacketMaskType) |
265  ((inOpcode << ePacketShiftOpcode) & ePacketMaskOpcode) |
267  // undefined packet types
268  else
269  /// \todo Generate an error or throw an exception on invalid packet types?
270  return 0;
271  }

+ Here is the caller graph for this function:

static Spartan6Packet torc::bitstream::Spartan6Packet::makeType1Write ( uint16_t  inAddress,
uint16_t  inWord 
)
inlinestatic

Construct a type 1 write packet.

Definition at line 218 of file Spartan6Packet.hpp.

218  {
219  return Spartan6Packet(makeHeader(ePacketType1, eOpcodeWrite, inAddress, 1), 1, inWord,
220  0);
221  }
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Spartan6Packet torc::bitstream::Spartan6Packet::makeType1Write ( uint16_t  inAddress,
uint16_t  inWord1,
uint16_t  inWord2 
)
inlinestatic

Construct a type 1 write packet for two words.

Definition at line 232 of file Spartan6Packet.hpp.

233  {
234  // used to send two packets after header for packets like IDCODE, FARMAJ, and CRC
235  uint16_t* words = new uint16_t[2];
236  words[0] = inWord1;
237  words[1] = inWord2;
238  return Spartan6Packet(makeHeader(ePacketType1, eOpcodeWrite, inAddress, 2), 2, 0,
239  words);
240  }
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
boost::uint16_t uint16_t
Imported type name.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

static Spartan6Packet torc::bitstream::Spartan6Packet::makeType1Write ( uint32_t  inCount,
uint16_t  inAddress,
uint16_t inWords 
)
inlinestatic

Construct a type 1 write packet for multiple words.

Definition at line 242 of file Spartan6Packet.hpp.

243  {
244  return Spartan6Packet(makeHeader(ePacketType1, eOpcodeWrite, inAddress, inCount),
245  inCount, 0, inWords);
246  }
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

static Spartan6Packet torc::bitstream::Spartan6Packet::makeType1Write32 ( uint16_t  inAddress,
uint32_t  inWord 
)
inlinestatic

Construct a type 1 write packet for two words.

Definition at line 223 of file Spartan6Packet.hpp.

223  {
224  // used to send two packets after header for packets like IDCODE, FARMAJ, and CRC
225  uint16_t* words = new uint16_t[2];
226  words[0] = inWord >> 16;
227  words[1] = inWord & 0x0000ffff;
228  return Spartan6Packet(makeHeader(ePacketType1, eOpcodeWrite, inAddress, 2), 2, 0,
229  words);
230  }
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
boost::uint16_t uint16_t
Imported type name.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Spartan6Packet torc::bitstream::Spartan6Packet::makeType2Write ( uint32_t  inCount,
uint16_t  inAddress,
uint16_t inWords 
)
inlinestatic

Construct a type 2 write packet.

Definition at line 248 of file Spartan6Packet.hpp.

249  {
250  return Spartan6Packet(makeHeader(ePacketType2, eOpcodeWrite, inAddress, 0), inCount, 0,
251  inWords);
252  }
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

uint16_t torc::bitstream::Spartan6Packet::operator[] ( size_t  inIndex) const
inline

Definition at line 273 of file Spartan6Packet.hpp.

273  {
274  if(inIndex == 0) return mHeader;
275  if(inIndex == 1 && mCount == 1) return mWord;
276  if(inIndex <= mCount) return mWords[inIndex-1];
277  return 0;
278  }
static Spartan6Packet torc::bitstream::Spartan6Packet::read ( std::istream &  inStream)
inlinestatic

Read a packet.

Todo:
we should throw an exception on invalid packet types

Definition at line 132 of file Spartan6Packet.hpp.

132  {
133  uint32_t count = 0;
134  uint16_t count1 = 0;
135  uint16_t count2 = 0;
136  uint16_t header = 0;
137  uint16_t word = 0;
138  uint16_t* raw_words = 0;
139  // read the header
140  inStream.read((char*) &header, sizeof(header));
141  header = ntohs(header);
142  // process synchronization packets
143  if(header == eSynchronizationDummy || header == eSynchronizationSync0
144  || header == eSynchronizationSync1 || header == eSynchronizationBusWidthSync0
146  || header == eSynchronizationBusWidthDetect1) {
147  return Spartan6Packet(header, 0, 0, 0);
148  }
149  // determine the payload length
151  switch(type) {
152  case ePacketType1:
153  count = (header & ePacketMaskType1Count) >> ePacketShiftType1Count;
154  break;
155  case ePacketType2:
156  inStream.read((char*) &count2, sizeof(count2));
157  inStream.read((char*) &count1, sizeof(count1));
158  count2 = ntohs(count2);
159  count1 = ntohs(count1);
160  count = (count2 << 16) | count1;
161  break;
162  default:
163  /// \todo we should throw an exception on invalid packet types
164  count = 0;
165  count1 = 0;
166  count2 = 0;
167  break;
168  }
169  // read the packet payload
170  // Type1 Packet
171  if(type == ePacketType1) {
172  if(count == 1) {
173  inStream.read((char*) &word, sizeof(word));
174  word = ntohs(word);
175  } else if(count > 1) {
176  raw_words = new uint16_t[count];
177  inStream.read((char*) raw_words, count << 1);
178  uint16_t* wordPtr = raw_words;
179  for(uint32_t i = 0; i < count; i++, wordPtr++) *wordPtr = ntohs(*wordPtr);
180  }
181  }
182  // Type2 Packet
183  else if(type == ePacketType2) {
184  if(count == 1) {
185  inStream.read((char*) &word, sizeof(word));
186  word = ntohs(word);
187  } else if(count > 1) {
188  raw_words = new uint16_t[count];
189  inStream.read((char*) raw_words, count << 1);
190  uint16_t* wordPtr = raw_words;
191  for(uint32_t i = 0; i < count; i++, wordPtr++) *wordPtr = ntohs(*wordPtr);
192  }
193  }
194 
195  // create and return the packet
196  return Spartan6Packet(header, count, word, raw_words);
197  }
boost::uint16_t uint16_t
Imported type name.
Spartan6Packet(void)
Null constructor.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void torc::bitstream::Spartan6Packet::write ( std::ostream &  inStream) const
inline

Write a packet.

Definition at line 199 of file Spartan6Packet.hpp.

199  {
200  uint32_t size = getWordSize();
201  for(uint32_t i = 0; i < size; i++) {
202  uint16_t word = htons(operator[](i));
203  inStream.write((char*) &word, sizeof(word));
204  // type 2 packets need to insert two count words right after the header
205  // added count information in check for non-Type 2 headers such as Sync Word 2
206  if(i == 0 && isType2() && !isSyncWord1()) {
207  word = htons(mCount >> 16);
208  inStream.write((char*) &word, sizeof(word));
209  word = htons(mCount & 0x0000ffff);
210  inStream.write((char*) &word, sizeof(word));
211  // if this was a Type 2, we've just accounted for the two extra length words,
212  // so don't try to extract them form the packet payload
213  size -= 2;
214  }
215  }
216  }
uint32_t getWordSize(void) const
Returns the total number of words in the packet, including the header word. In the case of Type 2 pa...
boost::uint16_t uint16_t
Imported type name.

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class torc::bitstream::bitstream::Spartan6PacketUnitTest
friend

Definition at line 76 of file Spartan6Packet.hpp.

Field Documentation

int torc::bitstream::Spartan6Packet::mAddress

Definition at line 99 of file Spartan6Packet.hpp.

uint32_t torc::bitstream::Spartan6Packet::mCount

Definition at line 94 of file Spartan6Packet.hpp.

uint16_t torc::bitstream::Spartan6Packet::mHeader

Definition at line 93 of file Spartan6Packet.hpp.

EOpcode torc::bitstream::Spartan6Packet::mOpcode

Definition at line 98 of file Spartan6Packet.hpp.

EPacketType torc::bitstream::Spartan6Packet::mType

Definition at line 97 of file Spartan6Packet.hpp.

uint16_t torc::bitstream::Spartan6Packet::mWord

Definition at line 95 of file Spartan6Packet.hpp.

WordSharedArray torc::bitstream::Spartan6Packet::mWords

Definition at line 96 of file Spartan6Packet.hpp.

const char * torc::bitstream::Spartan6Packet::sOpcodeName
static
Initial value:
= {
"NOP", "READ", "WRITE", "RESERVED"
}

Packet opcode names.

Definition at line 103 of file Spartan6Packet.hpp.

const char * torc::bitstream::Spartan6Packet::sPacketTypeName
static
Initial value:
= {
"[UNKNOWN TYPE 0]", "TYPE1", "TYPE2", "[UNKNOWN TYPE 3]", "[UNKNOWN TYPE 4]",
"[UNKNOWN TYPE 5]", "[UNKNOWN TYPE 6]", "[UNKNOWN TYPE 7]"
}

Packet type names.

Definition at line 101 of file Spartan6Packet.hpp.


The documentation for this class was generated from the following files: