Bitstream Interpretation Library (BIL)  0.1
BuswidthPatternRawData.cpp
Go to the documentation of this file.
1 
8 
9 using namespace bil;
10 
11 
12 const size_t BUSWIDTH_PATTERN_SIZE = 2;
13 const boost::uint32_t BUSWIDTH_WORD1 = 0x000000bb;
14 const boost::uint32_t BUSWIDTH_WORD2 = 0x11220044;
15 
16 
17 size_t bil::isBuswidthPattern(const boost::uint32_t* words, size_t wordCount)
18 {
19  // test if data is large enough
20  if (BUSWIDTH_PATTERN_SIZE > wordCount) return 0;
21  // test if both words are correct
22  if (BUSWIDTH_WORD1 != *words++) return 0;
23  if (BUSWIDTH_WORD2 != *words) return 0;
24  // buswidth pattern raw data found, return its size
25  return BUSWIDTH_PATTERN_SIZE;
26 }
27 
28 
29 size_t bil::writeBuswidthPattern(boost::uint32_t* words, size_t wordCount)
30 {
31  // check if buffer is large enough
32  if (BUSWIDTH_PATTERN_SIZE > wordCount) throw Exception();
33  // write buswidth pattern
34  *words++ = BUSWIDTH_WORD1;
35  *words = BUSWIDTH_WORD2;
36  // return written size
37  return BUSWIDTH_PATTERN_SIZE;
38 }