Tuesday, 17 May 2011

Copy array from round buffer with memcopy()

Since I started to work with embedded systems I had to start thing about pointers... A subject foreign in my previews Java development. Bellow is a small spinet of my code to copy arrays with pointers. Also the use of some Microblaze functions use are shown...

void BufferMemoryCopy(void* dest, GPS_BUFFER* buff, u16 buff_offset, u32 size)
// Microblaze -- typedef Xuint16 u16;
u16 pos = (buff->Tail16 + buff_offset) & GPS_FIFO_MASK; // Fifo mast is used in roun buffer
if ((pos + size) <= GPS_FIFO_SIZE)
        memcpy(dest, &buff->Buffer[pos], size);
memcpy(dest, &buff->Buffer[pos], GPS_FIFO_SIZE - pos);
memcpy(dest  + (GPS_FIFO_SIZE - pos), &buff->Buffer[0], size - (GPS_FIFO_SIZE - pos));

No comments:

Post a Comment