Tiny6410裸机开发/..

Tiny6410学习ing—(三)、ARM裸机开发—(4)、系统时钟(C语言配置)—② 
标签: 系统时钟 it


(三)、ARM裸机开发
(4)、系统时钟(C语言配置)—②
跟上一篇文章是一样的~~
所以不解释~~
不过这里我加了点位操作的概念~~
很让人蛋疼的是,在C或者汇编语言里面用来注释的,在这里还真成了注释,不能用于显示,所以


我就在“*/”之间加上了一个“~”~~
 
程序:
start.S
.globl _start
_start:
/* Peri Port Setup *~/
 ldr r0,=0x70000000
 orr r0,r0,#0x13
 mcr p15,0,r0,c15,c2,4
/* Close Watch Dog *~/
 ldr r0,=0x7e004000
 mov r1,#0
 str r1,[r0]
/* Setup SP *~/
 ldr sp,=8*1024
/* Go To Setup Clock *~/
 bl clock_init
/* Go To main *~/
 bl main
halt:
 b halt
clock.c
#define APLL_LOCK (*((volatile unsigned long *)0x7e00f000))
#define MPLL_LOCK (*((volatile unsigned long *)0x7e00f004))
#define EPLL_LOCK (*((volatile unsigned long *)0x7e00f008))
#define OTHERS  (*((volatile unsigned long *)0x7e00f900))
#define CLK_DIV0 (*((volatile unsigned long *)0x7e00f020))
#define ARM_RATIO 0 /* ARMCLK=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) *~/
#define APLL_CON (*((volatile unsigned long *)0x7e00f00c))
/* FOUTAPLL=MDIV*FIN/(PDIV*2^SDIV
        =266*12/(3*2^1)
    =532MHz *~/
#define APLL_CON_VAL ((1<<31)|(266<<16)|(3<<8)|(1))
#define MPLL_CON (*((volatile unsigned long *)0x7e00f010))
/* FOUTMPLL=MDIV*FIN/(PDIV*2^SDIV
    =266*12/(3*2^1)
    =532MHz *~/
#define MPLL_CON_VAL ((1<<31)|(266<<16)|(3<<8)|(1))
#define CLK_SRC  (*((volatile unsigned long *)0x7e00f01c))
void clock_init()
{
/* Set Lock Time *~/
 APLL_LOCK=0XFFFF;
 MPLL_LOCK=0XFFFF;
 EPLL_LOCK=0XFFFF;
/* Set Async Mode *~/
 OTHERS&=(~0XC0);
 while((OTHERS&0XF00)!=0);
/* Set CLK_DIV0 *~/
 CLK_DIV0=(ARM_RATIO)|(MPLL_RATIO<<4)|(HCLK_RATIO<<8)|(HCLKX2_RATIO<<9)|


(PCLK_RATIO<<12);
/* Set APLL_CON/MPLL_CON *~/
 APLL_CON=APLL_CON_VAL;
 MPLL_CON=MPLL_CON_VAL;
/* Start PLL *~/
 CLK_SRC=0X03;
 
}
led.c
#define GPKCON0  (*((volatile unsigned long *)0x7f008800))
#define GPKDAT  (*((volatile unsigned long *)0x7f008808))
/* Bit Operate *~/
#define SET_BIT(x,y) (x|=(1<<y))
#define CLR_BIT(x,y) (x&=~(1<<y))
#define CPL_BIT(x,y) (x^=(1<<y))
#define GET_BIT(x,y) (x&(1<<y))
void delay()
{
 volatile unsigned long i=0x10000;
 while(i--);
}
int main()
{
 int i=0;
 GPKCON0=0x11110000;
 GPKDAT=0XF0;
 while(1)
 {
  for(i=0;i<1000;i++)
  {
   if(i%2==0)
    CLR_BIT(GPKDAT,4);
   else
    SET_BIT(GPKDAT,4);
   delay();
  }
 }
 return(0);
}
最后是Makefile:
led.bin: 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
%.o : %.S
 arm-linux-gcc -o $@ $< -c
%.o : %.c
 arm-linux-gcc -o $@ $< -c
 
clean:
 rm *.o led.elf led.dis

 

你可能感兴趣的:(Tiny6410裸机开发/..)