
Traditional and Structure Approach to C Coding
3 - 6
C2000 Microcontroller Workshop - Peripheral Registers Header Files
view, as well as modify individual bit fields in a register. No need for a reference guide to
identify the bit fields.
Is the Structure Approach Efficient?
You could not have coded this example any more efficiently with hand assembly!
The structure approach enables efficient compiler use of
DP addressing mode and C28x atomic operations
C Source Code
// Stop CPU Timer0
CpuTimer0Regs.TCR.bit.TSS = 1;
// Load new 32-bit period value
CpuTimer0Regs.PRD.all = 0x00010000;
// Start CPU Timer0
CpuTimer0Regs.TCR.bit.TSS = 0;
Generated Assembly Code*
MOVW DP, #0030
OR @4, #0x0010
MOVL XAR4, #0x010000
MOVL @2, XAR4
AND @4, #0xFFEF
5 words, 5 cycles
-
Easy to read the code w/o comments
-
Bit mask built-in to structure
* C28x Compiler v5.0.1 with -g and either -o1, -o2, or -o3 optimization level
Compare with the #define Approach
The #define approach relies heavily on less-efficient pointers for
random memory access, and often does not take advantage of
C28x atomic operations
C Source Code
// Stop CPU Timer0
*TIMER0TCR |= 0x0010;
// Load new 32-bit period value
*TIMER0TPRD32 = 0x00010000;
// Start CPU Timer0
*TIMER0TCR &= 0xFFEF;
Generated Assembly Code*
MOV @AL,*(0:0x0C04)
ORB AL, #0x10
MOV *(0:0x0C04), @AL
MOVL XAR5, #0x010000
MOVL XAR4, #0x000C0A
MOVL *+XAR4[0], XAR5
MOV @AL, *(0:0x0C04)
AND @AL, #0xFFEF
MOV *(0:0x0C04), @AL
9 words, 9 cycles
-
Hard to read the code w/o comments
-
User had to determine the bit mask
* C28x Compiler v5.0.1 with -g and either -o1, -o2, or -o3 optimization level
Summary of Contents for C2000 Piccolo LaunchPad
Page 74: ...Interrupts 4 18 C2000 Microcontroller Workshop Reset and Interrupts ...
Page 100: ...Lab 5 System Initialization 5 26 C2000 Microcontroller Workshop System Initialization ...
Page 218: ...Lab 8 IQmath FIR Filter 8 42 C2000 Microcontroller Workshop Numerical Concepts ...
Page 334: ...F28069 controlCARD A 4 C2000 Microcontroller Workshop Appendix A Experimenter s Kit SW2 ...
Page 336: ...F28035 controlCARD A 6 C2000 Microcontroller Workshop Appendix A Experimenter s Kit SW2 SW3 ...