.text .globl _start _start: ldr r0, =0x70000000 orr r0, r0, #0x13 mcr p15, 0, r0, c15, c2, 4 ldr r0, =0x7e004000 mov r1, #0 str r1, [r0] bl clock_init ldr sp, =8*1024 bl xxxx b .
start.S 文件,调用完时钟初始化函数后调用跑马灯程序。
.globl clock_init clock_init: ldr r0, =0x7E00F000 ldr r1, =0x0000FFFF str r1, [r0] str r1, [r0, #4] str r1, [r0, #8] #define OTHERS 0x7e00f900 ldr r0, =OTHERS ldr r1, [r0] bic r1, r1, #0xc0 str r1, [r0] loop1: ldr r0, =OTHERS ldr r1, [r0] and r1, r1, #0xf00 cmp r1, #0 bne loop1 #define ARM_RATIO 0 /* ARMCLK = DOUTAPLL / (ARM_RATIO + 1) */ #define HCLKX2_RATIO 1 /* HCLKX2 = HCLKX2IN / (HCLKX2_RATIO + 1) */ #define HCLK_RATIO 1 /* HCLK = HCLKX2 / (HCLK_RATIO + 1) */ #define PCLK_RATIO 3 /* PCLK = HCLKX2 / (PCLK_RATIO + 1) */ #define MPLL_RATIO 0 /* DOUTMPLL = MOUTMPLL / (MPLL_RATIO + 1) */ ldr r0, =0x7E00F020 /* CLK_DIV0 */ ldr r1, =(ARM_RATIO) | (MPLL_RATIO << 4) | (HCLK_RATIO << 8) | (HCLKX2_RATIO << 9) | (PCLK_RATIO << 12) str r1, [r0] #define APLL_CON_VAL ((1<<31) | (266 << 16) | (3 << 8) | (1)) ldr r0, =0x7E00F00C ldr r1, =APLL_CON_VAL str r1, [r0] /* * APLL_CON, FOUTAPL = MDIV * Fin / (PDIV*2^SDIV) = 266*12/(3*2^1) = 532MHz */ #define MPLL_CON_VAL ((1<<31) | (266 << 16) | (3 << 8) | (1)) ldr r0, =0x7E00F010 ldr r1, =MPLL_CON_VAL str r1, [r0] /* * MPLL_CON, FOUTMPL = MDIV * Fin / (PDIV*2^SDIV) = 266*12/(3*2^1) = 532MHz */ ldr r0, =0x7E00F01C ldr r1, =0x03 str r1, [r0] mov pc, lr
clock.S:时钟初始化。
all:start.o clock.o led.o arm-linux-ld -Ttext 0 -o led.elf start.o clock.o led.o arm-linux-objcopy -O binary led.elf led.bin arm-linux-objdump -D led.elf > led.dis cp led.bin /tftpboot/led.bin %.o:%.S arm-linux-gcc -c $< -o $@ %.o:%.c arm-linux-gcc -c -o $@ $< clean: rm -rf *.o *.elf *.dis *.bin /tftpboot/*.bin
Makefile:在跑马灯的基础上添加clock.o
void delay () { int i; for (i = 0; i < 100000; i++) ; } int xxxx (void) { volatile unsigned long *gpmcon = (volatile unsigned long *)0x7f008820; volatile unsigned long *gpmdat = (volatile unsigned long *)0x7f008824; int i; for (i = 1; i <= 4; i++){ if (1 == i){ *gpmcon &= ~0xffff; *gpmcon |= 0x1; }else if (2 == i){ *gpmcon &= ~0xffff; *gpmcon |= 0x10; }else if (3 == i){ *gpmcon &= ~0xffff; *gpmcon |= 0x100; }else if (4 == i){ *gpmcon &= ~0xffff; *gpmcon |= 0x1000; i = 0; } *gpmdat = 0; delay(); } return 0; }
led.c:同上一章一样。
结果:初始化时钟后,跑马灯速度明显快于不初始化时钟的跑马灯程序。