Hi,
I am working on a motion control project for TMS320F28069 using CCS6.1.2 compiler 6.4.9. Without optimizations everything works fine.
Now I am trying to optimize my code for speed. Using highest levels --opt_level4 and -- opt_for_speed5, produces some unwanted behavior. Specifically, in a part of C code, which prepares a buffer for SCI transmission and finally enables a transmit interrupt, in the final code generated by the compiler, enabling the interrupt occurs a few lines before finalizing the buffer pointer causing occasionally transmitting bytes outside of the buffer. The C code looks like this:
Return_Status = Defined_Status;
// send the checksum and start Tx
// buffer is almost ready, just need to set the pointer and start transmission
TXbytes++;
*TXpointer = checksum;
TXpointer = TXbuffer;
TXENA; // #define TXENA SciaRegs.SCIFFTX.bit.TXFFIENA = 1
TXpointer and TXbuffer are volatile as well as SciaRegs.
This is the code from disassembly window during debug:
C$L493:
00d799: 9208 MOV AL, @0x8
2642 Return_Status = Defined_Status;
00d79a: 930A MOV AH, @0xa
2644 TXbytes++;
00d79b: 0A02 INC @0x2
00d79c: 761F01C1 MOVW DP, #0x1c1
2645 *TXpointer = checksum;
00d79e: 96C4 MOV *+XAR4[0], AL
2647 LDCN_TXENA;
00d79f: 1A1A0020 OR @0x1a, #0x0020
00d7a1: 761F04CE MOVW DP, #0x4ce
2646 TXpointer = TXbuffer;
00d7a3: B20C MOVL @0xc, XAR1
2642 Return_Status = Defined_Status;
00d7a4: 9705 MOV @0x5, AH
Looks like the generated code is randomly reordered (or at least I cannot find any reasonable explanation).
Now, I have so many questions about this and don't know where to start. Here are a few:
1. Is this a bug or am I missing something?
2. Is there a way to disable reordering at this particular place of my code or in the whole project?
3. What optimization settings allow this kind of reordering? I tried a few different optimization levels but run into random illegal interrupts and cannot figure out what part of the code is causing these.
4. What would you guys recommend to solve this problem?
Thank you in advance!
Vesko