s3c2410的clock management
一、對(duì)clock的基本認(rèn)識(shí)
s3c2410有兩個(gè)pll,其中一個(gè)是MPLL,M即為main,用來(lái)產(chǎn)生三種時(shí)鐘信號(hào):Fclk(給CPU核供給時(shí)鐘信號(hào),我們所說(shuō)的s3c2410的cpu主頻為200MHz,就是指的這個(gè)時(shí)鐘信號(hào),相應(yīng)的,1/Fclk即為cpu時(shí)鐘周期)、Hclk(為AHB bus peripherals供給時(shí)鐘信號(hào),AHB為advanced high-performance bus)、Pclk(為APB bus peripherals供給時(shí)鐘信號(hào),APB為advanced peripherals bus)。在這里,需要了解一下AMBA system architecture了。這個(gè)可以到官方網(wǎng)站www.arm.com下載相關(guān)資料。簡(jiǎn)單的說(shuō),AMBA是一種協(xié)議,這種協(xié)議已經(jīng)稱為片上組織通信的事實(shí)上的標(biāo)準(zhǔn)(the de facto standard for on-chip fabric communication)。下面給出英文描述:
The AMBA protocol is an open standard, on-chip bus specification that details a stategy for the interconnection and management of functional blocks that makes up a system-on-chip(SoC).It facilitates "right-first-time" development of embedded processors with one or more CPU/signal processors and multiple peripherals. The AMBA protocol enhances a resuable design methodology by defining a common backbone for SoC modules.
需要知道的是,AMBA總線是ARM提出的一種解決方案,它并非唯一的規(guī)范,但是因?yàn)锳RM的廣泛使用,AMBA總線也就成為了事實(shí)上的規(guī)范了?,F(xiàn)在AMBA總線最新為AMBA 3 specification版本,包括AMBA 3 AXI Interface、AMBA 3 AHB Interface、AMBA 3 APB Interface、AMBA 3 ATB Interface。而s3c2410還只能支持AMBA 2 specification,這個(gè)版本包含AMBA 2 AHB Interface、AMBA 2 APB Interface。也就是在s3c2410的框圖中看到的兩種總線接口。需要注意的是,這兩種總線所連的外設(shè)是有區(qū)別的。AHB總線連接高速外設(shè),低速外設(shè)則通過(guò)APB總線互連。顯然,對(duì)不同總線上的外設(shè),應(yīng)該使用不同的時(shí)鐘信號(hào),AHB總線對(duì)應(yīng)Hclk,APB總線對(duì)應(yīng)Pclk。
AHB bus上的外設(shè)有LCD controller(CONT代表controller,控制器)、USB Host CONT、ExtMaster、Nand CONT和nand flash boot loader、bus CONT、interrupt CONT、power management、memory CONT(sram/nor/sdram等)。
APB bus上的外設(shè)有UART、USB device、SDI/MMC、Watch Dog Timer、bus CONT、spi、iic、iis、gpio、rtc、adc、timer/pwm。
二、clock設(shè)置的步驟
The crystal oscillator begins oscillation within several milliseconds.When nRESET is releasedafter the stabilization of OSC(XTIpll)clock,the PLL starts to operate according to thedefaultPLL configuration.However,PLL is commonly known to be unstable after power-onreset,so Fin is fed directly to FCLK instead of the Mpll(PLL output)before the software newly configures the PLLCON.Evenifthe user doesnotwant to change thedefaultvalue of PLLCONregisterafterreset,the user shouldwritethe same value into PLLCONregisterby software.
The PLL restarts the lockup sequence toward thenewfrequency only after the software configures the PLL with anewfrequency.FCLK can be configured as PLL output(Mpll)immediately afterlocktime.
1、上電幾個(gè)ms后,晶振輸出穩(wěn)定。Fclk=晶振頻率。nRESET恢復(fù)高電平后,cpu開(kāi)始執(zhí)行指令,這完全是硬件動(dòng)作,不需要軟件設(shè)置。
2、第一步軟件工作: 設(shè)置P M S divider control,也就是設(shè)置MPLLCON寄存器。
3、第二步軟件工作: 設(shè)置CLKDIVN。
這一步是設(shè)置分頻系數(shù),即Fclk為cpu主頻,Hclk由Fclk分頻得到,Pclk由Hclk分頻得到。
4、第三步軟件工作: CLKDIVN的補(bǔ)充設(shè)置
IfHDIVN=1,the CPU bus mode has to be changed from the fast bus mode to the asynchronous bus modeusingfollowing instructions.
MMU_SetAsyncBusMode
mrc p15,0,r0,c1,c0,0
orr r0,r0,#R1_nF:OR:R1_iA
mcr p15,0,r0,c1,c0,0
IfHDIVN=1andthe CPU bus mode is the fast bus mode,the CPU will operate by the HCLK.Thisfeature can be used to change the CPU frequency as a half without affecting the HCLKandPCLK.
翻譯:
@ FCLK:HCLK=1:2
.macroMMU_SetAsyncBusMode
mrc p15,0,r0,c1,c0,0
orr r0,r0,#(R1_iA|R1_iA)
mcr p15,0,r0,c1,c0,0
.endm
@ step3:set asynchronous bus mode
MMU_SetAsyncBusMode
5、第四步軟件工作:
@ step4:stay locktime
movr1,#CLK_CTL_BASE
ldr r2,=vLOCKTIME
strr2,[r1,#oLOCKTIME]
6、對(duì)外設(shè)的影響
在這個(gè)實(shí)驗(yàn)中,主要是有兩個(gè)需要改變,一個(gè)外設(shè)是UART,一個(gè)外設(shè)是SDRAM。
(1)UART,它是接在APB總線上,所以對(duì)應(yīng)的時(shí)鐘信號(hào)為Pclk,現(xiàn)在為50MHz。如果想要設(shè)置波特率為115200bps,那么根據(jù)公式UBRDIV0=(int)(PCLK/(bps*16))-1計(jì)算,應(yīng)該為26。如果放到程序中,那么應(yīng)該注意形式。具體如下:
UBRDIV0=((int)(PCLK/16./UART_BAUD_RATE)-1);
(2)SDRAM,主要的影響因素為刷新頻率。使用了兩片HY57V561620CT-H,查看手冊(cè)其刷新頻率為8192 refresh cycles/64ms,所以刷新周期64ms/8192=7.8125us??醇拇嫫鱎EFRESH的各個(gè)位的設(shè)置情況:
·REFEN[23]:開(kāi)啟自動(dòng)模式,設(shè)為1
·TREFMD[22]:設(shè)為Auto refresh模式,設(shè)為0
·Trp[21:20]:看看RAS precharge Time,查看SDRAM手冊(cè),發(fā)現(xiàn)-H系列此參數(shù)至少為20ns,現(xiàn)在Hclk對(duì)應(yīng)的時(shí)鐘周期為10ns,所以至少應(yīng)該為2個(gè)clock。可以設(shè)為00
·Tsrc: Semi Row Cycle Time,也就是RAS Cycle Time,至少65ms,所以至少得6.5clock,按照可選值,應(yīng)該設(shè)置為11
·Refresh[10:0]:
公式refresh period = (2^11 - refresh_count +1)/Hclk,由此推導(dǎo)出refresh_count=2^11+1-refresh period*Hclk。帶入數(shù)值,計(jì)算得出1268=0x04f4,這個(gè)數(shù)值要用四舍五入,減少誤差。
·其余的保留值,均設(shè)置為0
由此得出該寄存器的值應(yīng)該為0x008c04f4。