Optimization Levels
Volatile Usage
Optimization Issue: “Volatile” Variables
Optimization Issue: “Volatile” Variables
unsigned
unsigned
int
int
*CTRL
*CTRL
while (*CTRL !=1);
while (*CTRL !=1);
volatile
volatile
unsigned
unsigned
int
int
*CTRL
*CTRL
while (*CTRL !=1);
while (*CTRL !=1);
Wrong: Wait loop for a hardware signal
Wrong: Wait loop for a hardware signal
Solution:
Solution:
Problem:
Problem:
The compiler does not know that this pointer may refer to a
The compiler does not know that this pointer may refer to a
hardware register that may change outside the scope of the C pro
hardware register that may change outside the scope of the C pro
gram.
gram.
Hence it may be eliminated (optimized out of existence!)
Hence it may be eliminated (optimized out of existence!)
CTRL
CTRL
= 1?
= 1?
No
No
Yes
Yes
Optimizer removes
Optimizer removes
empty loop
empty loop
empty
empty
loop
loop
When using optimization, it is important to declare variables as
When using optimization, it is important to declare variables as
volatile
volatile
when:
when:
The memory location may be
The memory location may be
modifed
modifed
by something other than the
by something other than the
compiler (e.g. it’s a memory
compiler (e.g. it’s a memory
-
-
mapped peripheral register).
mapped peripheral register).
The order of operations should not be rearranged by the compiler
The order of operations should not be rearranged by the compiler
Define the pointer as “volatile” to prevent the optimizer from o
Define the pointer as “volatile” to prevent the optimizer from o
ptimizing
ptimizing
C28x – C Programming
D - 11
Summary of Contents for C28 Series
Page 64: ...Summary 3 16 C28x Peripheral Registers Header Files ...
Page 78: ...Interrupt Sources 4 14 C28x Reset and Interrupts ...
Page 218: ...Lab 9 DSP BIOS 9 22 C28x Using DSP BIOS ...
Page 244: ...Lab 10 Programming the Flash 10 26 C28x System Design ...
Page 273: ...Appendix A eZdsp F2812 C28x Appendix A eZdsp F2812 A 1 ...
Page 276: ...Appendix P2 Expansion Interface A 4 C28x Appendix A eZdsp F2812 ...
Page 277: ...Appendix P4 P8 P7 I O Interface C28x Appendix A eZdsp F2812 A 5 ...
Page 278: ...Appendix A 6 C28x Appendix A eZdsp F2812 ...
Page 279: ...Appendix P5 P9 Analog Interface C28x Appendix A eZdsp F2812 A 7 ...
Page 282: ...Appendix A 10 C28x Appendix A eZdsp F2812 TP1 TP2 Test Points ...