cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
dummy_memory.cpp
Go to the documentation of this file.
1 
17 
42 
55 #include "dummy_memory.hpp"
56 
57 // Set the private data elements for a Read Command
59  this->readAddr = cmd.saddr(15, 0); // Start address
60  this->readId = cmd.saddr(31, 16); // Buffer address
61  uint16_t tempLen = (uint16_t) cmd.btt(15, 0); // Byte to Transfer
62  this->readLen = (int) tempLen;
63 }
64 
65 // Set the private data elements for a Write Command
67  this->writeAddr = cmd.saddr(15, 0); // Start address
68  this->writeId = cmd.saddr(31, 16); // Buffer address
69 }
70 
71 // Read a data chunk from the memory
73  readStorageIt = storage.find(readId);
74  if (readStorageIt == storage.end()) {
75  readStorageIt = createBuffer(readId);
76  // check it?
77  }
78  int i = 0;
79  chunk.setLE_TKeep(0);
80  while (this->readLen > 0 and i < 8) {
81  chunk.setLE_TData((readStorageIt->second)[readAddr], (i*8)+7, i*8);
82  chunk.setLE_TKeep(chunk.getLE_TKeep() | (0x01 << i));
83  readLen--;
84  readAddr++;
85  i++;
86  }
87  if (this->readLen == 0) {
88  chunk.setTLast(TLAST);
89  }
90  else {
91  chunk.setTLast(0);
92  }
93 }
94 
95 // Write a data chunk into the memory
97  writeStorageIt = storage.find(writeId);
98  if (writeStorageIt == storage.end()) {
99  writeStorageIt = createBuffer(writeId);
100  // check it?
101  }
102  // shuffleWord(word.data);
103  for (int i = 0; i < 8; i++) {
104  if (chunk.getLE_TKeep()[i]) {
105  (writeStorageIt->second)[writeAddr] = chunk.getLE_TData((i*8)+7, i*8);
106  writeAddr++;
107  }
108  else {
109  break;
110  }
111  }
112 }
113 
114 
115 std::map<ap_uint<16>, ap_uint<8>*>::iterator DummyMemory::createBuffer(ap_uint<16> id)
116 {
117  ap_uint<8>* array = new ap_uint<8>[65536]; // [255] default
118  std::pair<std::map<ap_uint<16>, ap_uint<8>*>::iterator, bool> ret;
119 
120  ret = storage.insert(std::make_pair(id, array));
121  if (ret.second) {
122  return ret.first;
123  }
124  return storage.end();
125 }
126 
127 void DummyMemory::shuffleWord(ap_uint<64>& word)
128 {
129  ap_uint<64> temp;
130 
131  temp( 7, 0) = word(63, 56);
132  temp(15, 8) = word(55, 48);
133  temp(23, 16) = word(47, 40);
134  temp(31, 24) = word(39, 32);
135 
136  temp(39, 32) = word(31, 24);
137  temp(47, 40) = word(23, 16);
138  temp(55, 48) = word(15, 8);
139  temp(63, 56) = word(7, 0);
140  word = temp;
141 }
142 
void setTLast(tLast last)
Definition: AxisRaw.hpp:246
LE_tKeep getLE_TKeep(int leHi=64/8-1, int leLo=0) const
Definition: AxisRaw.hpp:264
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
Definition: AxisRaw.hpp:260
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
Definition: AxisRaw.hpp:272
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
Definition: AxisRaw.hpp:276
ap_uint< 40 > saddr
ap_uint< 23 > btt
Definition: mem.hpp:85
: A class to emulate the TCP buffer memory.
void setReadCmd(DmCmd cmd)
void setWriteCmd(DmCmd cmd)
void readChunk(AxisApp &chunk)
void writeChunk(AxisApp &chunk)
#define TLAST
Definition: AxisRaw.hpp:116