EasyManuals Logo

Texas Instruments C28 Series Student Guide

Texas Instruments C28 Series
342 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #333 background imageLoading...
Page #333 background image
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

Table of Contents

Other manuals for Texas Instruments C28 Series

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments C28 Series and is the answer not in the manual?

Texas Instruments C28 Series Specifications

General IconGeneral
BrandTexas Instruments
ModelC28 Series
CategoryComputer Hardware
LanguageEnglish

Related product manuals