Altera_Forum
Honored Contributor
19 years agoproblem with memcpy
Hi,
I want to copy many times a region of memory located in one of my slaves into a local buffer. This ram region is filled by a master, and i use a function which advice me when the ram have been updated. If i use the macro IORD it works fine, but is too slow for the system specs. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif int read_buffer( alt_u32 *dest_ptr, alt_u32 *source_ptr, int length) { int i; for (i=0;i<length;i++) { *dest_ptr++ = IORD(source_ptr,i); } } ... int main() { int i; alt_u32 buffer[122][188]; ... for (i=0;i<122;i++) { WaitUntilSlaveRamisUpdated(); read_buffer((alt_u32*) &buffer[i],(alt_u32*)MySlave_BASE,188); } ... } So, if we print the buffer, we will see something similar to .. buf[0][0] = 0; buf[0][1] = 1; .. buf[0][187] = 187; buf[1][0] = 188; buf[1][1] = 189; .. buf[122][188] = 22935; So i wanna try using memcpy. The problem is that memcpy only works for the first time i call it, and then never refresh the correct values. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/mad.gif int read_buffer( alt_u32 *dest_ptr, alt_u32 *source_ptr, int length) { memcpy(dest_ptr,source_ptr,188*4); } so, the result is buf[0][0] = 0; buf[0][1] = 1; .. buf[0][187] = 187; buf[1][0] = 0; buf[1][1] = 1; .. buf[122][188] = 187; I don't understand why is happening this. I have monitored the avalon signals in the signaltap, and it seems that memcpy only goes to my slave the first iteration. Does anybody understand this? Thanks in advance ! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/laugh.gif