| |
Programming the CCCR and
the CCLKCFG Register
1) Programming the CCCR (Core Clock Configuration Register)
The CCCR is a memory-mapped register. To access it, we need to use
VirtualAlloc and VirtualCopy to enable the program to write to it.
Steps:
| Define VirtualCopy in a .h file since it is not an exported function in
eVC++ but exported in Platform Builder. core.dll contains the implementation
and both eVC++ and Platform Builder have access to it. |
extern "C" BOOL VirtualCopy(LPVOID dest, LPVOID src, DWORD size, DWORD flags);
| Use VirutalAlloc to allocate the memory |
LPVOID VirtualCCCR
= VirtualAlloc(0, sizeof(DWORD), MEM_RESERVE, PAGE_NOACCESS);
| Use VirtualCopy to map the memory location we want to write to: |
if(!VirtualCopy((LPVOID)VirtualCCCR, (LPVOID)CCCR, sizeof(DWORD), PAGE_READWRITE
|PAGE_NOCACHE | PAGE_PHYSICAL))
{
VirtualFree(VirtualCCCR,0,MEM_RELEASE);
VirtualCCCR = NULL;
}
| Using the different frequency level we have computed, write the value to
it, for example: |
*(int *)VirtualCCCR = 289;
2) Programming the CCLKCFG Register
This is a Co-Processor Register. More specifically, it is Register 6 of
Co-Processor 14. We need to enable the proper mode to allow frequency change.
Steps:
| Write the required ARM assembly language into a .asm file and link it into
the Project Workspace, the code in bold below is writing 2 to the CCLKCFG
Register which will set the FCS (Frequency Change Sequence) bit. |
AREA |.data|, DATA
|?ControlFreq@@3PCKC| DCD 0x41300000 ; ControlFreq
EXPORT |?enable_frequency_change@@YAXXZ| ; enable_frequency_change
AREA |.pdata|, PDATA
|$T24415| DCD |?enable_frequency_change@@YAXXZ|
DCD 0x40000501
AREA |.text|, CODE
|?enable_frequency_change@@YAXXZ| PROC ; enable_frequency_change
; Line 7
sub sp, sp, #4
|$M24413|
; Line 9
mov r3, #2
str r3, [sp]
mov r3, #2
mcr p14, 0, r3, c6, c0, 0
; Line 10
add sp, sp, #4
mov pc, lr
|$M24414|
ENDP ; |?enable_frequency_change@@YAXXZ|, enable_frequency_change
| Set the build instructions for this file and the output, for example: |
build command: armasm file.asm ARMDbg\file.obj
output: ARMDbg\file.obj
Note: We have to set the value of CCCR first before calling
enable_frequency_chage() which set the CCCLKCFG Register.
|