221{
222
225
226 flxcard_bar2_regs_t* bar2 = (flxcard_bar2_regs_t*)
mFlxCard.openBackDoor(2);
227
228 size_t lNrBytes = 0;
229 for (size_t i = 0; i < aData.size(); i++)
230 lNrBytes += aData.at(i).second;
231
232 assert((lNrBytes % 4) == 0);
233
234 char* allocated = NULL;
235 posix_memalign((void**)&allocated, 4096 , lNrBytes + 4096);
236 if (allocated == NULL) {
237 exception::FlxCommunicationError lExc;
238 log(lExc,
"Failed to allocate ", uhal::Integer(lNrBytes + 4096),
" bytes in File::write/2 function");
239 throw lExc;
240 }
241
242
243 char* buffer = allocated;
244 size_t lNrBytesCopied = 0;
245 for (size_t i = 0; i < aData.size(); i++) {
246 memcpy(buffer + lNrBytesCopied, aData.at(i).first, aData.at(i).second);
247 lNrBytesCopied += aData.at(i).second;
248 }
249
250 lNrBytesCopied = 0;
251 uint32_t lAddr = aAddr / 2;
252
253 while (lNrBytesCopied < lNrBytes) {
254 bar2->IPBUS_WRITE_ADDRESS = lAddr;
255 char* lSrcPtr = buffer + lNrBytesCopied;
256 if ((lNrBytes - lNrBytesCopied) >= 8) {
257 bar2->IPBUS_WRITE_DATA.DATA = *(uint64_t*)lSrcPtr;
258 lNrBytesCopied += 8;
259 } else if ((lNrBytes - lNrBytesCopied) >= 4) {
260 bar2->IPBUS_WRITE_DATA.DATA = uint64_t(*(uint32_t*)lSrcPtr);
261 lNrBytesCopied += 4;
262 }
263
264 ++lAddr;
265 }
266
267 free(allocated);
268}