Traditional and Structure Approach to C Coding
Traditional and Structure Approach to C Coding
Traditional Approach to C Coding
Traditional Approach to C Coding
#define ADCTRL1 (volatile unsigned
#define ADCTRL1 (volatile unsigned
int
int
*)0x00007100
*)0x00007100
#define ADCTRL2 (volatile unsigned
#define ADCTRL2 (volatile unsigned
int
int
*)0x00007101
*)0x00007101
...
...
void main(void)
void main(void)
{
{
*ADCTRL1 = 0x1234;
*ADCTRL1 = 0x1234;
//write entire register
//write entire register
*ADCTRL2 |= 0x4000;
*ADCTRL2 |= 0x4000;
//reset sequencer #1
//reset sequencer #1
}
}
Disadvantages
Disadvantages
-
-
Requires individual masks to be generated to
Requires individual masks to be generated to
manipulate individual bits
manipulate individual bits
-
-
Cannot easily display bit fields in Watch window
Cannot easily display bit fields in Watch window
-
-
Will generate less efficient code in many cases
Will generate less efficient code in many cases
Advantages
Advantages
-
-
Simple, fast and easy to type
Simple, fast and easy to type
-
-
Variable names exactly match register names (easy
Variable names exactly match register names (easy
to remember)
to remember)
Structure Approach to C Coding
Structure Approach to C Coding
void main(void)
void main(void)
{
{
AdcRegs
AdcRegs
.ADCTRL1.all = 0x1234;
.ADCTRL1.all = 0x1234;
//write entire register
//write entire register
AdcRegs
AdcRegs
.ADCTRL2.bit.RST_SEQ1 = 1;
.ADCTRL2.bit.RST_SEQ1 = 1;
//reset sequencer #1
//reset sequencer #1
}
}
Disadvantages
Disadvantages
-
-
Can be difficult to remember the structure names
Can be difficult to remember the structure names
(Code Maestro to the rescue!)
(Code Maestro to the rescue!)
-
-
More to type (again, Code Maestro to the rescue)
More to type (again, Code Maestro to the rescue)
Advantages
Advantages
-
-
Easy to manipulate individual bits.
Easy to manipulate individual bits.
-
-
Watch window is amazing! (next slide)
Watch window is amazing! (next slide)
-
-
Generates most efficient code (on C28x)
Generates most efficient code (on C28x)
C28x - Peripheral Registers Header Files 3 - 3