SPRAA85E November 2005 – December 2017 SM320F2812 , SM320F2812-EP , TMS320F280021 , TMS320F280021-Q1 , TMS320F280023 , TMS320F280023-Q1 , TMS320F280023C , TMS320F280025 , TMS320F280025-Q1 , TMS320F280025C , TMS320F280025C-Q1 , TMS320F280040-Q1 , TMS320F280040C-Q1 , TMS320F280041 , TMS320F280041-Q1 , TMS320F280041C , TMS320F280041C-Q1 , TMS320F280045 , TMS320F280048-Q1 , TMS320F280048C-Q1 , TMS320F280049 , TMS320F280049-Q1 , TMS320F280049C , TMS320F280049C-Q1 , TMS320F2801 , TMS320F2801-Q1 , TMS320F2802 , TMS320F2802-Q1 , TMS320F28044 , TMS320F2806 , TMS320F2806-Q1 , TMS320F28062 , TMS320F28062-Q1 , TMS320F28062F , TMS320F28062F-Q1 , TMS320F28063 , TMS320F28064 , TMS320F28065 , TMS320F28066 , TMS320F28066-Q1 , TMS320F28067 , TMS320F28067-Q1 , TMS320F28068F , TMS320F28068M , TMS320F28069 , TMS320F28069-Q1 , TMS320F28069F , TMS320F28069F-Q1 , TMS320F28069M , TMS320F28069M-Q1 , TMS320F28075 , TMS320F28075-Q1 , TMS320F2808 , TMS320F2808-Q1 , TMS320F2809 , TMS320F2810 , TMS320F2810-Q1 , TMS320F2811 , TMS320F2811-Q1 , TMS320F2812 , TMS320F2812-Q1 , TMS320F28232 , TMS320F28232-Q1 , TMS320F28234 , TMS320F28234-Q1 , TMS320F28235 , TMS320F28235-Q1 , TMS320F28332 , TMS320F28333 , TMS320F28334 , TMS320F28335 , TMS320F28335-Q1 , TMS320F28374D , TMS320F28374S , TMS320F28375D , TMS320F28375S , TMS320F28375S-Q1 , TMS320F28376D , TMS320F28376S , TMS320F28377D , TMS320F28377D-EP , TMS320F28377D-Q1 , TMS320F28377S , TMS320F28377S-Q1 , TMS320F28379D , TMS320F28379D-Q1 , TMS320F28379S , TMS320R2811
C-Source Code Generated Assembly
Memory Instruction
// Enable only 2801 Peripheral Clocks
EALLOW; 3F82A7 EALLOW
3F82A8 MOVW DP,#0x01C0
SysCtrlRegs.PCLKCR0.bit.rsvd1 = 0; 3F82AA AND @28,#0xFFFC
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; 3F82AC AND @28,#0xFFFB
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; 3F82AE OR @28,#0x0008
SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1; 3F82B0 OR @28,#0x0010
SysCtrlRegs.PCLKCR0.bit.rsvd2 = 0; 3F82B2 AND @28,#0xFFDF
SysCtrlRegs.PCLKCR0.bit.SPICENCLK = 1; 3F82B4 OR @28,#0x0040
SysCtrlRegs.PCLKCR0.bit.SPIDENCLK = 1; 3F82B6 OR @28,#0x0080
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; 3F82B8 OR @28,#0x0100
SysCtrlRegs.PCLKCR0.bit.SPIBENCLK = 1; 3F82BA OR @28,#0x0200
SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; 3F82BC OR @28,#0x0400
SysCtrlRegs.PCLKCR0.bit.SCIBENCLK = 0; 3F82BE AND @28,#0xF7FF
SysCtrlRegs.PCLKCR0.bit.rsvd3 = 0; 3F82C0 AND @28,#0xCFFF
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK= 1; 3F82C2 OR @28,#0x4000
SysCtrlRegs.PCLKCR0.bit.ECANBENCLK= 0; 3F82C4 AND @28,#0x7FFF
EDIS; 3F82C6 EDIS
NOTE
EALLOW and EDIS are macros defined in the C/C++ Header Files and Peripheral Examples. These macros expand to the EALLOW and EDIS assembly instructions.
The EALLOW protection mechanism prevents spurious CPU writes to several registers. Executing EALLOW permits the CPU to write freely to protected registers and executing EDIS protects them once more. For information on EALLOW protection and a list of protected registers, see the device-specific System Control and Interrupts Reference Guide or Technical Reference Manual (TRM).
To calculate how many cycles the code in Example 13 will take, you need to know how many wait states are required to access the PCLKCR0 register. Wait state information for all memory blocks and peripheral frames is listed in the device specific data manual. The PCLKCR0 register is in peripheral frame 2; this frame requires two wait states for a read access and no wait states for a write access. This means a read from PCLKCR0 takes three cycles total and a write takes one cycle. In addition, a new access to PCLKCR0 cannot begin until the previous write is complete. This built-in protection mechanism removes pipeline effects and makes sure operations proceed in the correct order; all of the peripheral registers have this protection. In Example 13, each access to the PCLKCR0 register will take six cycles; the pipeline phases are shown in Table 3.
CPU-Pipeline Phase (1) | ||||
---|---|---|---|---|
Read 1 - Read Begins | Read 2 - Data Latched | Execute - Value Modified | Write - Value written | Cycle |
AND @28,#0xFFFC
|
1 | |||
AND @28,#0xFFFC
|
2 | |||
AND @28,#0xFFFC
|
3 | |||
AND @28,#0xFFFC
|
4 | |||
AND @28,#0xFFFC
|
5 | |||
AND @28,#0xFFFC
|
6 | |||
AND @28,#0xFFFB
|
7 | |||
AND @28,#0xFFFB
|
8 | |||
AND @28,#0xFFFB
|
9 | |||
AND @28,#0xFFFB
|
10 | |||
AND @28,#0xFFFB
|
11 | |||
AND @28,#0xFFFB
|
12 | |||
OR @28,#0x0008
|
13 | |||
OR @28,#0x0008
|
14 | |||
OR @28,#0x0008
|
15 | |||
OR @28,#0x0008
|
16 | |||
OR @28,#0x0008
|
17 | |||
OR @28,#0x0008
|
18 | |||
OR @28,#0x0010
|
||||
etc... |
When code size and cycle counts must be kept to a minimum, it is beneficial to reduce the number of instructions required to initialize a register to as few as possible. Here are some options for reducing code size:
As mentioned in Section 3.1, register-file variables are declared as volatile. For this reason, enabling the optimizer alone will not reduce the number of instructions. The keyword volatile alerts the compiler that the variable's value can change outside of the currently executing code. While removing the volatile keyword would reduce code size, it is not recommended. Removing volatile must be done with great care and only where the developer is certain doing so will not yield incorrect results.
The union definitions discussed in Section 3.4 allow access to either specific bit fields or to the entire register. When a write is performed to the entire register using the .all member of the union, code size is reduced. This method creates very efficient code as shown in Example 14. Using .all, however, makes the code both harder to write and harder to read. It is not immediately evident how different bit fields in the register are configured.