I have a custom memCopy() function from a TI motorware project. The function takes a start address pointer, an end address pointer and a destination address pointer.
void memCopy(uint16_t *srcStartAddr,uint16_t *srcEndAddr,uint16_t *dstAddr)
I want to use this function to copy a structure from Flash into a copy of that structure in RAM. I'm trying save those addresses as pointers as below.
uint16_t *start;
uint16_t *end;
uint16_t *dest;
start = (uint16_t *)&myStructInFlash;
end = (uint16_t *)(&myStructInFlash + (sizeof(myStructInFlash)));
dest = (uint16_t *)&myStructInRAM;
When I step the code through in the debugger, the start and dest pointers look correct, but the end pointer is rubbish. Something like 0xFFFFFFFF I think, it didn't make sense to me anyway.
I assume the problem is with my "address arithmetic". Is there a proper way to do this?
Thanks in advance, Colm
Follow up:
Great, thanks Ian. I was not aware that's how pointer arithmetic worked.
As the others have mentioned about the inclusive vs exclusive last address... The function is as follows
void memCopy(uint16_t *srcStartAddr,uint16_t *srcEndAddr,uint16_t *dstAddr)
{
while(srcStartAddr <= srcEndAddr)
{
*dstAddr++ = *srcStartAddr++;
}
return;
}
From this, I think it would require the "last uint16_t" as opposed to the uint16_t that comes after which (&myStruct + 1) would produce.
How would I obtain the uint16_t just before that? (uint16_t)((&myStruct + 1) - 1) ?