Chinaunix首页 | 论坛 | 博客
  • 博客访问: 306304
  • 博文数量: 63
  • 博客积分: 1482
  • 博客等级: 上尉
  • 技术积分: 1185
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-12 19:06
个人简介

hello world!

文章分类

全部博文(63)

分类: LINUX

2011-03-17 23:31:13

一、s3c2440 时钟

    The Clock control logic in S3C2440A can generate the required clock signals including FCLK for CPU,

 HCLK for the AHB bus peripherals, and PCLK for the APB bus peripherals. The S3C2440A has two Phase

 Locked Loops (PLLs):one for FCLK, HCLK, and PCLK, and the other dedicated for USB block (48Mhz).

 The clock control logic can make slow clocks without PLL and connect/disconnect the clock to each 

peripheral block by software, which will reduce the power consumption.

二、寄存器

MPLLCON 0x4C000004 R/W MPLL configuration register 0x00096030

UPLLCON 0x4C000008 R/W UPLL configuration register 0x0004d030

CLKDIVN 0x4C000014 R/W Clock divider control register 0x00000000

#define MDIV_400_148 0x5c

#define PDIV_400_148 0x1

#define SDIV_400_148 0x1

#define CLKDVIN_400_148 0x5   /* 1:4:8 */

Fin=12MHZ

Mpll = (2 * m * Fin) / (p * 2^s)=400M

m = (MDIV + 8), p = (PDIV + 2), s = SDIV

m=0x5c+8=100

p=1+2=3

s=1

FCLK:HCLK:PCLK = 1:4:8,因此得出HCLK=100Mhz

Mpll = (2*m * Fin) / (p * 2s)

m = M (the value for divider M)+ 8, p = P (the value for divider P) + 2

三、源程序

start.S

  1. /*
  2.  *************************************************************************
  3.  *
  4.  * lcl bootloader
  5.  *
  6.  *************************************************************************
  7.  */

  8. .globl _start
  9. _start:    b    start_code


  10. start_code:
  11.     /*
  12.      * set the cpu to SVC32 mode
  13.      */
  14.     mrs    r0, cpsr
  15.     bic    r0, r0, #0x1f
  16.     orr    r0, r0, #0xd3
  17.     msr    cpsr, r0

  18.     bl clock_init
  19.     bl cpu_init_crit
  20.     bl copy_code_to_sdram
  21.     
  22.     /*
  23.      *run in sdram
  24.      */

  25.     ldr sp, =0x34000000
  26.     ldr lr, =halt_loop          @璁剧疆杩斿洖鍦板潃
  27.     ldr pc, =    Main                     //0x30100034


  28. halt_loop:
  29.    b halt_loop

  30.    /*
  31.     * copy code from interal 4K sdram to sdram
  32.     */

  33. copy_code_to_sdram:
  34.   
  35. #define SDRAM_BASE 0x30000000

  36.     mov r1,#2048
  37.     ldr r2,=0x30100000
  38.     mov r3,#4*1024
  39.    
  40. 1:
  41.     ldr r4,[r1],#4
  42.     str r4,[r2],#4
  43.     cmp r1,r3
  44.     bne 1b
  45.     mov pc,lr

  46.     /*
  47.      *clock initialize. Mpll=405MHZ 1:4:8
  48.      */
  49. clock_init:

  50. #define pWTCON            0x53000000
  51. #define INTMSK            0x4A000008     /* Interupt-Controller base addresses */
  52. #define INTSUBMSK        0x4A00001C
  53. #define CLKDIVN            0x4C000014     /* clock divisor register */
  54. #define CLK_CTL_BASE    0x4C000000    /* clock base address */
  55.         
  56. #define MDIV_405        0x7f << 12    /* MDIV 0x7f*/
  57. #define PSDIV_405        0x21        /* PDIV SDIV 0x2 0x1 */
  58.         
  59.         /* turn off the watchdog */
  60.         
  61.         ldr r0, =pWTCON
  62.         mov r1, #0x0
  63.         str r1, [r0]
  64.             
  65.         /*
  66.          * mask all IRQs by setting all bits in the INTMR - default
  67.          */
  68.         
  69.         ldr r1, =0x7fff
  70.         ldr r0, =INTSUBMSK
  71.         str r1, [r0]
  72.         
  73.         /* FCLK:HCLK:PCLK = 1:4:8 */
  74.         ldr r0, =CLKDIVN
  75.         mov r1, #5                 //1:4:8

  76.         str r1, [r0]
  77.             
  78.         mrc p15, 0, r1, c1, c0, 0    //切换到实时总线HCLK

  79.         orr r1, r1, #0xc0000000     
  80.         mcr p15, 0, r1, c1, c0, 0    
  81.             
  82.             
  83.         mov r1, #CLK_CTL_BASE    
  84.         mov r2, #MDIV_405    
  85.         add r2, r2, #PSDIV_405    
  86.         str r2, [r1, #0x04]     /* MPLLCON address     Mpll=405MHZ */


  87.     /*
  88.      *MMU and SDRAM initialize
  89.      */
  90.      
  91. cpu_init_crit:
  92.     /*
  93.      * flush v4 I/D caches
  94.      */
  95.     mov    r0, #0
  96.     mcr    p15, 0, r0, c7, c7, 0    /* flush v3/v4 cache */
  97.     mcr    p15, 0, r0, c8, c7, 0    /* flush v4 TLB */

  98.     /*
  99.      * disable MMU stuff and caches
  100.      */
  101.     mrc    p15, 0, r0, c1, c0, 0
  102.     bic    r0, r0, #0x00002300    @ clear bits 13, 9:8 (--V- --RS)
  103.     bic    r0, r0, #0x00000087    @ clear bits 7, 2:0 (B--- -CAM)
  104.     orr    r0, r0, #0x00000002    @ set bit 2 (A) Align
  105.     orr    r0, r0, #0x00001000    @ set bit 12 (I) I-Cache
  106.     mcr    p15, 0, r0, c1, c0, 0

  107.     /*
  108.      * before relocating, we have to setup RAM timing
  109.      * because memory timing is board-dependend, you will
  110.      * find a lowlevel_init.S in your board directory.
  111.      */
  112.     mov    ip, lr

  113.     bl memsetup     /* memory control configuration */

  114.     mov    lr, ip
  115.     mov    pc, lr

  116. memsetup:
  117.     /* memory control configuration */
  118.     /* make r0 relative the current location so that it */
  119.     /* reads SMRDATA out of FLASH rather than memory ! */

  120. #define MEM_CTL_BASE    0x48000000

  121.     mov r1,#MEM_CTL_BASE
  122.     adr r2,mem_cfg_val
  123.     add r3,r1,#52
  124. 1:
  125.     ldr     r4, [r2], #4
  126.     str     r4, [r1], #4
  127.     cmp     r1, r3
  128.     bne     1b
  129.     mov     pc,lr    

  130. .align 4
  131.         /* the literal pools origin */    
  132. mem_cfg_val:
  133.     .long        0x22011110
  134.     .long        0x00000700
  135.     .long        0x00000700
  136.     .long        0x00000700
  137.     .long        0x00000700
  138.     .long        0x00000700
  139.     .long        0x00000700    @BANK5
  140.     .long        0x00018005
  141.     .long        0x00018005    
  142.     .long        0x00ac03f4    @REFRESH // 12MHZ 0x00ac07a3

  143.     .long        0x000000B1
  144.     .long        0x00000030
  145.     .long        0x00000030

main.c

 

  1. /*
  2. GPBCON 0x56000010 Port B control
  3. GPBDAT 0x56000014 Port B data
  4. GPBUP 0x56000018 Pull-up control B

  5. LED1 GPB5 LED2 GPB6 LED3 GPB7 LED4 GPB8

  6. GPB8 [17:16] 00 = Input 01 = Output
  7.              10 = nXDREQ1 11 = Reserved
  8. GPB7 [15:14] 00 = Input 01 = Output
  9.              10 = nXDACK1 11 = Reserved
  10. GPB6 [13:12] 00 = Input 01 = Output
  11.              10 = nXBREQ 11 = reserved
  12. GPB5 [11:10] 00 = Input 01 = Output
  13.              10 = nXBACK 11 = reserved
  14. #define S3C24X0_GPIO_BASE        0x56000000

  15. GPGCON = 0000 0000 1000 0000 1010 1000 1000 0010=0x80a882

  16. GPG0 Input/output EinT8 – – K1
  17. GPG3 Input/output EinT11 nSS1 –     K2
  18. GPG5 Input/output EinT13 SPIMISO1 – k3
  19. GPG6 Input/output EinT14 SPIMISO1 – k4
  20. GPG7 Input/output EinT15 SPICLK1 – k5
  21. GPG11 Input/output EinT19 TCLK1 – k6
  22. */

  23. #define GPBCON (*(volatile unsigned long *) 0x56000010)
  24. #define GPBDAT (*(volatile unsigned long *) 0x56000014)
  25. #define GPBUP (*(volatile unsigned long *) 0x56000018)

  26. #define GPGCON (*(volatile unsigned long *) 0x56000060)
  27. #define GPGDAT (*(volatile unsigned long *) 0x56000064)
  28. #define GPGUP (*(volatile unsigned long *) 0x56000068)

  29. #define GPX_up 0x00000000

  30. #define GPB5_out (1<<(5*2))
  31. #define GPB6_out (1<<(6*2))
  32. #define GPB7_out (1<<(7*2))
  33. #define GPB8_out (1<<(8*2))

  34. #define GPG0_in ~(3<<(0*2))
  35. #define GPG3_in ~(3<<(3*2))
  36. #define GPG5_in ~(3<<(5*2))
  37. #define GPG6_in ~(3<<(6*2))

  38. void leds_init()
  39. {
  40.     GPBCON = (GPB5_out | GPB6_out | GPB7_out | GPB8_out);
  41.     GPBUP     = GPX_up;
  42. }
  43. void buttons_init()
  44. {
  45.     GPGCON = (GPG0_in & GPG3_in & GPG5_in & GPG6_in);
  46.     GPGUP     = GPX_up;
  47. }

  48. int Main()
  49. {
  50.     unsigned long dwDat;
  51.     leds_init();
  52.     buttons_init();

  53.     while (1)
  54.     {
  55.         dwDat=GPGDAT;
  56.         if(dwDat & (1<<0))
  57.             GPBDAT |=(1<<5);
  58.         else
  59.             GPBDAT &=~(1<<5);    

  60.         if(dwDat & (1<<3))
  61.             GPBDAT |=(1<<6);    
  62.         else
  63.             GPBDAT &=~(1<<6);    

  64.         if(dwDat & (1<<5))
  65.             GPBDAT |=(1<<7);
  66.         else
  67.             GPBDAT &=~(1<<7);    

  68.         if(dwDat & (1<<6))
  69.             GPBDAT |=(1<<8);    
  70.         else
  71.             GPBDAT &=~(1<<8);                
  72.     }

  73.     return 0;
  74. }

mem.lds

  1. SECTIONS {
  2.   firtst     0x00000000 : { start.o}
  3.   second     0x30000800 : AT(2048) { main.o }
  4. }

makefile

 

  1. objs := start.o main.o

  2. sdram.bin : $(objs)
  3.     arm-linux-ld -Tsdram.lds    -o sdram_elf $^
  4.     arm-linux-objcopy -O binary -S sdram_elf $@
  5.     arm-linux-objdump -D -m arm sdram_elf > sdram.dis

  6. %.o:%.c
  7.     arm-linux-gcc -Wall -c -O2 -o $@ $<

  8. %.o:%.S
  9.     arm-linux-gcc -Wall -c -O2 -o $@ $<

  10. clean:
  11.     rm -f sdram.dis sdram.bin sdram_elf *.o

以下为能直接运行的二进制文件,下载到Nand Flash 的 Black0 直接以Nand Flash运行.

 sdram.rar   

阅读(1536) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~