Other Parts Discussed in Thread: C2000WARE
Tool/software: TI C/C++ Compiler
I'm trying to copy out the adc results into a structure in my application using memcpy and I'm noticing different compiler interpretations depending on how my pointers are declared. I have the code working, but I'd like to understand this better. Let me explain....
volatile uint16_t * vsource = (volatile uint16_t *)((uintptr_t)(ADCARESULT_BASE)); volatile uint16_t * vdest = &(adcData.adcAData); uint16_t * source = (volatile uint16_t *)((uintptr_t)(ADCARESULT_BASE)); uint16_t * dest = &(adcData.adcAData); memcpy(vdest, vsource, sizeof(adcAData_t)); memcpy(dest, vsource, sizeof(adcAData_t)); memcpy(dest, source, sizeof(adcAData_t));
Each call to memcpy above generates different ASM.
When both the destination and source are volatile pointers, a branch to the actual memcopy function is performed. This copy works.
243 memcpy(vdest, vsource, sizeof(adcAData_t)); 08659b: 8342 MOVL XAR5, *-SP[2] 08659c: 0210 MOVB ACC, #16 08659d: 76487611 LCR memcpy
When the source is volatile and the destination is not, the copy is implemented using a repeat and PWRITE instruction. This copy works.
244 memcpy(dest, vsource, sizeof(adcAData_t)); 08659f: 8A42 MOVL XAR4, *-SP[2] 0865a0: C548 MOVL XAR7, *-SP[8] 0865a1: F60F RPT #15 0865a2: 2684 || PWRITE *XAR7, *XAR4++ 0865a3: 7700 NOP 0865a4: 7700 NOP
When neither the source or destination is volatile, the copy is implemented using a repeat and PREAD instruction. This copy does not work.
245 memcpy(dest, source, sizeof(adcAData_t)); 0865a5: 8A48 MOVL XAR4, *-SP[8] 0865a6: C546 MOVL XAR7, *-SP[6] 0865a7: F60F RPT #15 0865a8: 2484 || PREAD *XAR4++, *XAR7
My C28x assembly is a little rusty but I looked at the instruction set guide and checked XAR4 and XAR7 and they have the correct values in them in all of the above cases. However in the third case the memory at the destination address is zero'ed out instead of data from the adc result registers being copied over. Can someone help me understand why the third case doesn't work? I'm guessing this has something to do with the compiler not knowing what addressing mode to use? Please enlighten me :)
Best,
Trey