S3C6410时钟控制(1.2)系统时钟设定
三、S3C6410时钟初始化的具体流程。
1:设定PLL_LOCK寄存器。参见上面的PLL_LOCK(1)。
对应代码:(C或者汇编)
//1-设定hold时间,rPLLLOCK寄存器
rAPLLLOCK = 0xFFFF;
rMPLLLOCK = 0xFFFF;
rEPLLLOCK = 0xFFFF;
------------------------------------------------------
//set the clock time
ldr r0, =0x7e00f000 //APLL_CLOCK
ldr r1, =0xffff
str r1, [r0]
str r1, [r0, #0x4] //MPLL_CLOCK
str r1, [r0, #0x8] //EPLL_CLOCK
2:设定时钟同步异步工作模式。参见上面的其他寄存器OTHERS(6)。
对应代码:(C或者汇编)
//2-设定时钟同步异步模式,以及HCLK2/HCLK/PCLK的时钟源,
//bit[11~8]只读,表示同步模式OK;bit[7]0-异步,1-同步;bit[6]系统时钟源选择0-MOUTMPLL,1-DOUTAPLL
rOTHERS |= (0xC0);//bit7/6置1,同步模式,DoutAPLL
while(!(rOTHERS & 0xf00));//当bit[11~8]=0时,设置完成
------------------------------------------------------------------------
//set Async mode
ldr r0, =0x7e00f900 //OTHERS
ldr r1, [r0]
bic r1, #0xc0
str r1, [r0]
//wait for Async mode
loop1:
ldr r0, =0x7e00f900
ldr r1, [r0]
and r1, #0xf00
cmp r1, #0x00
bne loop1
3:设定时钟分频系数。参加上面的CLK_DIV0~2(3).
对应代码:(C或者汇编)
//3-设定时钟分频系数,rCLKDIV0/1/2,下面仅用rCLKDIV0,占用了bit[15:12,11:9,8,4,3:0]
//#define ARM_RATIO 0 //ARM_CLK=DOUTAPLL/(ARM_RATIO+1),bit[3:0],复位为0
//#define MPLL_RATIO 0 //DOUTMPLL = MOUTMPLL/(MPLL_RATIO+1),bit[4],复位为0
//#define HCLK_RATIO 1 //HCLK = HCLKX2/(HCLK_RATIO+1)<=133Mhz,bit[8],复位为0
//#define HCLKX2_RATIO 1 //HCLKX2 = HCLKX2IN/(HCLKX2_RATIO+1)<=266Mhz,bit[11:9],复位为0
//#define PCLK_RATIO 3 //PCLK = HCLKX2/(PCLK_RATIO+1)<=66Mhz,bit[15:12],复位为1,必须为奇数
rCLKDIV0 |= ((ARM_RATIO<<0)|(MPLL_RATIO<<4)|(HCLK_RATIO<<8)|(HCLKX2_RATIO<<9)|(PCLK_RATIO<<12))
----------------------------------------------------------------------------------------------------------------
//set the DIV
#define ARM_RATIO 0 //ARM_CLK=DOUTAPLL / (ARM_RATIO + 1)
#define MPLL_RATIO 0 //DOUTMPLL = MOUTMPLL / (MPLL_RATIO + 1)
#define HCLK_RATIO 1 //HCLK = HCLKX2 / (HCLK_RATIO + 1)
#define HCLKX2_RATIO 1 //HCLKX2 = HCLKX2IN / (HCLKX2_RATIO + 1)
#define PCLK_RATIO 3 //PCLK = HCLKX2 / (PCLK_RATIO + 1) <=66Mhz
ldr r0, =0x7e00f020 //CLK_DIV0
ldr r1, =(ARM_RATIO) | (MPLL_RATIO << 4) | (HCLK_RATIO << 8) | (HCLKX2_RATIO << 9) | (PCLK_RATIO << 12)
str r1, [r0]
4:设置PLL_CON寄存器,见上面的PLL_CON(1)
程序如下:(C或者汇编)
//4-设定各PLL的输出频率,PLLCON,最高位bit[31]PLL使能位,1-使能
#define MDIV 266 //有参照频率,533-266-3-1,100-400-3-4,bit[25~16]
#define PDIV 3 //200-400-3-3,266-266-3-2,bit[13:8]
#define SDIV 1 //400-400-3-2,667-333-3-1,bit[2:0]
rAPLLCON = ((1<<31)|(MDIV<<16)|(PDIV<<8)|(SDIV<<0));//533-266-3-1
rMPLLCON = ((1<<31)|(MDIV<<16)|(PDIV<<8)|(SDIV<<0));//533-266-3-1
//rEPLLCON0
//rEPLLCON1
------------------------------------------------------------------------------
//init the frequence
#define SDIV 1
#define PDIV 3
#define MDIV 266 //final 532Mhz
ldr r0, =0x7e00f00c //APLL_CON
ldr r1, =(1 << 31) | (MDIV << 16) | (PDIV << 8) | (SDIV)
str r1, [r0]
ldr r0, =0x7e00f010 //MPLL_CON
str r1, [r0]
5:设置PLL的输出为系统各个时钟的时钟源,即CLK_SRC寄存器(2)
程序如下:(C或者汇编)
//5-设置PLL的输出为各个时钟的时钟源,即CLK_SRC寄存器,
//BIT[0]-APLL_SEL;BIT[1]-MPLL_SEL;BIT[2]-EPLL_SEL
rCLKSRC = 0x03;//APLL_SEL,MPLL_SEL
-----------------------------------------------------------------
ldr r0, =0x7e00f01c
ldr r1, =0x03
str r1, [r0]
大家也可参考“http://blog.csdn.net/mr_raptor/article/details/6442914”
文章评论(0条评论)
登录后参与讨论