207{
208
211
212 flxcard_bar2_regs_t *bar2 = (flxcard_bar2_regs_t *)
mFlxCard.openBackDoor( 2 );
213
214 size_t lNrBytes = 0;
215 for (size_t i = 0; i < aData.size(); i++)
216 lNrBytes += aData.at(i).second;
217
218 assert((lNrBytes % 4) == 0);
219
220 char *allocated = NULL;
221 posix_memalign((void **)&allocated, 4096, lNrBytes + 4096);
222 if (allocated == NULL) {
223 exception::FlxCommunicationError lExc;
224 log(lExc,
"Failed to allocate ", uhal::Integer(lNrBytes + 4096),
" bytes in File::write/2 function");
225 throw lExc;
226 }
227
228
229 char* buffer = allocated;
230 size_t lNrBytesCopied = 0;
231 for (size_t i = 0; i < aData.size(); i++) {
232 memcpy(buffer + lNrBytesCopied, aData.at(i).first, aData.at(i).second);
233 lNrBytesCopied += aData.at(i).second;
234 }
235
236 lNrBytesCopied = 0;
237 uint32_t lAddr = aAddr/2;
238
239 while (lNrBytesCopied < lNrBytes) {
240 bar2->IPBUS_WRITE_ADDRESS = lAddr;
241 char* lSrcPtr = buffer + lNrBytesCopied;
242 if ((lNrBytes - lNrBytesCopied) >= 8) {
243 bar2->IPBUS_WRITE_DATA.DATA = *(uint64_t*) lSrcPtr;
244 lNrBytesCopied += 8;
245 }
246 else if ((lNrBytes - lNrBytesCopied) >= 4) {
247 bar2->IPBUS_WRITE_DATA.DATA = uint64_t(*(uint32_t*) lSrcPtr);
248 lNrBytesCopied += 4;
249 }
250
251 ++lAddr;
252 }
253
254 free(allocated);
255}