Traditional and Structure Approach to C Coding
Is the Structure Approach Efficient?
Is the Structure Approach Efficient?
(This example could not have been coded any more efficiently wit
(This example could not have been coded any more efficiently wit
h hand assembly)
h hand assembly)
The structure approach enables efficient compiler use of
The structure approach enables efficient compiler use of
DP addressing mode and C28x Atomic operations
DP addressing mode and C28x Atomic operations
C Source Code
C Source Code
// Stop CPU Timer0
// Stop CPU Timer0
CpuTimer0Regs.TCR.bit.TSS = 1;
CpuTimer0Regs.TCR.bit.TSS = 1;
// Load new 32
// Load new 32
-
-
bit period value
bit period value
CpuTimer0Regs.PRD.all = 0x00010000;
CpuTimer0Regs.PRD.all = 0x00010000;
// Start CPU Timer0
// Start CPU Timer0
CpuTimer0Regs.TCR.bit.TSS = 0;
CpuTimer0Regs.TCR.bit.TSS = 0;
Generated Assembly Code
Generated Assembly Code
MOVW DP, #0030
MOVW DP, #0030
OR @4, #0x0010
OR @4, #0x0010
MOVL XAR4, #0x010000
MOVL XAR4, #0x010000
MOVL @2, XAR4
MOVL @2, XAR4
AND @4, #0xffef
AND @4, #0xffef
5 Words, 5 cycles
5 Words, 5 cycles
-
-
Easy to read the code w/o comments
Easy to read the code w/o comments
-
-
Bit mask built
Bit mask built
-
-
in to structure
in to structure
Compare with the #define Approach
Compare with the #define Approach
The #define approach relies heavily on less
The #define approach relies heavily on less
-
-
efficient
efficient
pointers for random memory access, and often does not
pointers for random memory access, and often does not
take advantage of C28x atomic operations
take advantage of C28x atomic operations
C Source Code
C Source Code
// Stop CPU Timer0
// Stop CPU Timer0
*TIMER0TCR |= 0x0010;
*TIMER0TCR |= 0x0010;
// Load new 32
// Load new 32
-
-
bit period value
bit period value
*TIMER0TPR32 = 0x00010000;
*TIMER0TPR32 = 0x00010000;
// Start CPU Timer0
// Start CPU Timer0
*TIMER0TCR |= 0xFFEF;
*TIMER0TCR |= 0xFFEF;
Generated Assembly Code
Generated Assembly Code
MOV AL,*(0:0x0c04)
MOV AL,*(0:0x0c04)
ORB AL, #0x10
ORB AL, #0x10
MOV *(0:0x0c04), AL
MOV *(0:0x0c04), AL
MOVL XAR4, #3078
MOVL XAR4, #3078
MOVL XAR5, #65536
MOVL XAR5, #65536
MOVL *+XAR4[0], XAR5
MOVL *+XAR4[0], XAR5
MOV AL, *(0:0x0c04)
MOV AL, *(0:0x0c04)
OR AL, #0xffef
OR AL, #0xffef
MOV *(0:0x0c04), AL
MOV *(0:0x0c04), AL
9 Words, 9 cycles
9 Words, 9 cycles
-
-
Hard to read the code w/o comments
Hard to read the code w/o comments
-
-
User had to determine the bit mask
User had to determine the bit mask
C28x - Peripheral Registers Header Files
3 - 5
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 ...