Bitstream Interpretation Library (BIL)  0.1
V5AddressLayout.cpp
Go to the documentation of this file.
1 
8 
9 using namespace bil;
10 
11 // the following constants tell how much frames a resource needs per column type
12 // and per block:
13 // in INTERCONNECT_AND_CFG block
14 const unsigned CLB_CFG_FRAMES = 36;
15 const unsigned DSP_CFG_FRAMES = 28;
16 const unsigned BRAM_CFG_FRAMES = 30;
17 const unsigned IOB_CFG_FRAMES = 54;
18 const unsigned CLK_CFG_FRAMES = 4;
19 const unsigned SERIAL_CFG_FRAMES = 32;
20 // in BRAM_CONTENT block
21 const unsigned BRAM_CNT_FRAMES = 128;
22 // in SPECIAL block
23 const unsigned ALL_SPECIAL_FRAMES = 1;
24 // in BRAM_NONCFGDATA block
25 const unsigned BRAM_NONCFG_FRAMES = 1;
26 
27 
29  m_upperRowCount(1),
30  m_lowerRowCount(1),
31  m_columns(1, V5CfgColumn::CLB),
32  m_bramCount(0)
33 {
34 
35 }
36 
37 
38 V5AddressLayout::V5AddressLayout(unsigned upperRowCount, unsigned lowerRowCount, const V5CfgColumnSequence& columnSequence):
39  m_upperRowCount(upperRowCount),
40  m_lowerRowCount(lowerRowCount),
41  m_columns(columnSequence),
42  m_bramCount(countBRAMs(columnSequence))
43 {
44  // at least one row, at most ROWCOUNT_MAX rows
45  if (0 == m_upperRowCount) throw Exception();
46  if (ROWCOUNT_MAX < m_upperRowCount) throw Exception();
47  // at least one row, at most ROWCOUNT_MAX rows
48  if (0 == m_lowerRowCount) throw Exception();
49  if (ROWCOUNT_MAX < m_lowerRowCount) throw Exception();
50  // at least one column, at most COLUMNCOUNT_MAX rows
51  if (0 == m_columns.size()) throw Exception();
52  if (COLUMNCOUNT_MAX < m_columns.size()) throw Exception();
53 }
54 
55 
56 void V5AddressLayout::upperRowCount(unsigned count)
57 {
58  // at least one row, at most ROWCOUNT_MAX rows
59  if (0 == count) throw Exception();
60  if (ROWCOUNT_MAX < count) throw Exception();
61  m_upperRowCount = count;
62 }
63 
64 
66 {
67  return m_upperRowCount;
68 }
69 
70 
71 void V5AddressLayout::lowerRowCount(unsigned count)
72 {
73  // at least one row, at most ROWCOUNT_MAX rows
74  if (0 == count) throw Exception();
75  if (ROWCOUNT_MAX < count) throw Exception();
76  m_lowerRowCount = count;
77 }
78 
79 
81 {
82  return m_lowerRowCount;
83 }
84 
85 
87 {
88  // at least one column, at most COLUMNCOUNT_MAX rows
89  if (0 == columns.size()) throw Exception();
90  if (COLUMNCOUNT_MAX < columns.size()) throw Exception();
91  m_columns = columns;
92  m_bramCount = countBRAMs(m_columns);
93 }
94 
95 
97 {
98  return m_columns;
99 }
100 
101 
102 unsigned V5AddressLayout::rowCount(bool lowerHalf) const
103 {
104  if (lowerHalf) return m_lowerRowCount;
105  return m_upperRowCount;
106 }
107 
108 
110 {
111  switch (block)
112  {
113  // Interconnection and configuration subspace and dynamic reconfiguration
114  // subspace share the same columns. Return the size of the stored row.
116  case V5CfgBlock::SPECIAL: return m_columns.size();
117 
118  // BRAM content and non-configuration subspace: return BRAM column count.
120  case V5CfgBlock::BRAM_NONCFGDATA: return m_bramCount;
121 
122  // invalid block: zero columns
123  default: return 0;
124  }
125 }
126 
127 
129 {
130  switch (block)
131  {
132  // Interconnection and configuration subspace: every column type has its
133  // specific number of frames per resource.
135  switch (column)
136  {
137  case V5CfgColumn::CLB: return CLB_CFG_FRAMES;
138  case V5CfgColumn::DSP: return DSP_CFG_FRAMES;
139  case V5CfgColumn::BRAM: return BRAM_CFG_FRAMES;
140  case V5CfgColumn::IOB: return IOB_CFG_FRAMES;
141  case V5CfgColumn::CLK: return CLK_CFG_FRAMES;
143  default: return 0;
144  };
145 
146  // BRAM content subspace: each BRAM needs 128 frames of memory data.
147  // All other column types have no frames.
149  if (V5CfgColumn::BRAM == column) return BRAM_CNT_FRAMES;
150  else return 0;
151 
152  // Dynamic reconfiguration subspace: one frame per column.
153  case V5CfgBlock::SPECIAL:
154  switch (column)
155  {
156  case V5CfgColumn::CLB: ;
157  case V5CfgColumn::DSP: ;
158  case V5CfgColumn::BRAM: ;
159  case V5CfgColumn::IOB: ;
160  case V5CfgColumn::CLK: ;
162  default: return 0;
163  };
164 
165  // BRAM non-configuration subspace: each BRAM needs 1 frame.
166  // All other columns have no frames.
168  if (V5CfgColumn::BRAM == column) return BRAM_NONCFG_FRAMES;
169  else return 0;
170 
171  // invalid block: zero frames
172  default: return 0;
173  }
174 }
175 
176 
178 {
179  switch (block)
180  {
181  // Interconnection and configuration subspace and dynamic reconfiguration
182  // subspace share the same columns. Lookup column type and return it.
184  case V5CfgBlock::SPECIAL:
185  // test if columnIndex is valid
186  if ((m_columns.size()) <= columnIndex) throw Exception();
187  return m_columns[columnIndex];
188 
189  // BRAM content and non-configuration subspace subspace: return BRAM type.
192  // test if columnIndex is valid
193  if (columnIndex >= m_bramCount) throw Exception();
194  return V5CfgColumn::BRAM;
195 
196  // invalid block: nothing to return
197  default: throw ;
198  }
199 }
200 
201 
202 unsigned V5AddressLayout::countBRAMs(const V5CfgColumnSequence& columns) const
203 {
204  // loop over given columns, count BRAM columns, and return their number
205  unsigned count = 0;
206  size_t columnCount = columns.size();
207  for (size_t i = 0; i < columnCount; ++i)
208  if (V5CfgColumn::BRAM == columns[i]) ++count;
209  return count;
210 }