S3C2410 clock and timer

Publisher:genius6Latest update time:2016-04-20 Source: eefocusKeywords:clock  timer  s3c2410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Connect an external crystal oscillator and then generate a clock source through the internal circuit

Directly use the external clock source

Select by setting the pin

 

FCLK  cpu

HCLK  AHB

PCLK  APB

 

PLL increases the system clock speed through the clock control logic PLL

 

UPLL  USB

MPLL  FCLK HCLK PCLK

 

PLL is not started FCLK=Fin (crystal frequency)

 

The s3c2410 has five 16-bit timers,  of which the first four timers have PWM function  , that is, an output pin  can be controlled by the timer to periodically high or low levels. The clock source of the timer is PCLK

 

 

@**********************************************************************************
@ File: head.S
@ Function: Initialize, set the interrupt mode, system mode stack, and interrupt handling function
@******************************************************************************       
  
.extern     main
.text
.global _start
_start:
@**********************************************************************************       
@ Interrupt vector. In this program, except Reset and HandleIRQ, other exceptions are not used
@******************************************************************************       
    Reset

@ 0x04: The vector address of the undefined instruction abort mode
HandleUndef:
    HandleUndef
 
@ 0x08: The vector address of the management mode, which is entered by the SWI instruction
HandleSWI:
    HandleSWI

@ 0x0c: vector address of the exception caused by instruction prefetch termination
HandlePrefetchAbort:
    HandlePrefetchAbort

@ 0x10: The vector address of the exception caused by data access termination
HandleDataAbort:
    HandleDataAbort

@ 0x14: Reserved
HandleNotUsed:
    HandleNotUsed

@ 0x18: interrupt mode vector address
    HandleIRQ

@ 0x1c: Vector address of fast interrupt mode
HandleFIQ:
    HandleFIQ

 

 

Reset:                  
   ldr sp, =4096           @ Set the stack pointer. The following are all C functions. You need to set the stack before calling
   bl  disable_watch_dog   @ Turn off WATCHDOG, otherwise the CPU will restart continuously

 


   bl  clock_init          @ Set up MPLL, change FCLK, HCLK, PCLK


   bl  memsetup            @ Set up the memory controller to use SDRAM
   bl  copy_steppingstone_to_sdram     @ Copy code to SDRAM
   ldr pc, =on_sdram                   @ Jump to SDRAM and continue execution
on_sdram:
   msr cpsr_c, #0xd2       @ Enter interrupt mode
   ldr sp, =4096           @ Set interrupt mode stack pointer

 

   msr cpsr_c, #0xdf       @ Enter system mode
   ldr sp, =0x34000000     @ Set the system mode stack pointer,

 

   bl  init_led            @ Initialize the GPIO pin of LED


   bl  timer0_init         @ Initialize timer 0  


   bl  init_irq            @ Call the interrupt initialization function in init.c
   msr cpsr_c, #0x5f       @ Set I-bit=0, open IRQ interrupt
   
   ldr lr, =halt_loop      @ Set the return address
   ldr pc, =main           @ Call the main function
halt_loop:
    halt_loop

HandleIRQ:
   sub lr, lr, #4                  @ Calculate the return address
   stmdb   sp!,    { r0-r12,lr }   @ Save the used registers
                                   @ Note that sp at this time is the sp of interrupt mode
                                   @ The initial value is 4096 set above
   
   ldr lr, =int_return             @ Set the return address after calling ISR, i.e. EINT_Handle function 
   ldr pc, =Timer0_Handle          @ Call interrupt service function, in interrupt.c
int_return:
   ldmia   sp!,    { r0-r12,pc }^  @ Interrupt return, ^ means copy the value of spsr to cpsr

 

 

 

#include "s3c24xx.h"
 
void disable_watch_dog(void);
void clock_init(void);
void memsetup(void);
void copy_steppingstone_to_sdram(void);
void init_led(void);
void timer0_init(void);
void init_irq(void);


void disable_watch_dog(void)
{
   WTCON = 0;  // It is very simple to turn off WATCHDOG, just write 0 to this register
}

#define S3C2410_MPLL_200MHZ     ((0x5c<<12)|(0x04<<4)|(0x00))
#define S3C2440_MPLL_200MHZ     ((0x5c<<12)|(0x01<<4)|(0x02))

void clock_init(void)
{
   // LOCKTIME = 0x00ffffff;   // Use the default value
   CLKDIVN  = 0x03;            // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1

   
__asm__(
   "mrc    p15, 0, r1, c1, c0, 0n"        
   "orr    r1, r1, #0xc0000000n"          
   "mcr    p15, 0, r1, c1, c0, 0n"        
   );

   
   if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))
   {
       MPLLCON = S3C2410_MPLL_200MHZ; 
   }
   else
   {
       MPLLCON = S3C2440_MPLL_200MHZ; 
        
}


void memsetup(void)
{
   volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;

   
   
   p[0] = 0x22011110;     //BWSCON
   p[1] = 0x00000700;     //BANKCON0
   p[2] = 0x00000700;     //BANKCON1
   p[3] = 0x00000700;     //BANKCON2
   p[4] = 0x00000700;     //BANKCON3 
   p[5] = 0x00000700;     //BANKCON4
   p[6] = 0x00000700;     //BANKCON5
   p[7] = 0x00018005;     //BANKCON6
   p[8] = 0x00018005;     //BANKCON7
   
   
   p[9]  = 0x008C04F4;
   p[10 ] = 0x000000B1;     //BANKSIZE
   p[11] = 0x00000030;     //MRSRB6
   p[12] = 0x00000030;     //MRSRB7
}

void copy_steppingstone_to_sdram(void)
{
   unsigned int *pdwSrc  = (unsigned int *)0;
   unsigned int *pdwDest = (unsigned int *)0x30000000;
   
   while (pdwSrc < (unsigned int *)4096)
   {
       *pdwDest = *pdwSrc;
       pdwDest++;
       pdwSrc++;
   }
}


#define GPB5_out        (1<<(5*2))      // LED1
#define GPB6_out        (1<<(6*2))      // LED2
#define GPB7_out        (1<<(7*2))      // LED3
#define GPB8_out        (1<<(8*2))      // LED4


#define GPG11_eint      (2<<(11*2))     // K1,EINT19
#define GPG3_eint       (2<<(3*2))      // K2,EINT11
#define GPF3_eint       (2<<(3*2))      / / K3,EINT3
#define GPF2_eint       (2<<(2*2))      // K4,EINT2
 
void init_led(void)
{
   GPBCON = GPB5_out | GPB6_out | GPB7_out | GPB8_out;
}


void timer0_init(void)
{
   TCFG0  = 99;        // Prescaler 0 = 99        
   TCFG1  = 0x03;      // Select 16-division
   TCNTB0 = 31250;     // Trigger an interrupt every 0.5 seconds
   TCON   |= (1<<1);   // Manual update
   TCON   = 0x09;      // Automatically load, clear the "manual update" bit, and start timer 0
}


void init_irq(void)
      
   // Timer 0 interrupt enable
   INTMSK   &= (~(1<<10));
}

 


#include "s3c24xx.h"

void Timer0_Handle(void)
{
   
   if(INTOFFSET == 10)
   {
       GPBDAT = ~(GPBDAT & (0xf << 5));
   }
   //Clear interrupt
   SRCPND = 1 << INTOFFSET;
   INTPND = INTPND;     
}

 

 

int main(void)
{
   while(1);
   return 0;
}


Keywords:clock  timer  s3c2410 Reference address:S3C2410 clock and timer

Previous article:UART Operation
Next article:Operation of s3c24xx interrupts

Recommended ReadingLatest update time:2024-11-16 07:40

S3C2440 clock system notes
1. Overall Architecture The main clock source of S3C2440 can be an external resonator (XTIpll) or an external input clock (EXTCLK), which generates a high-frequency clock signal through the phase-locked loop MPLL and UPLL, and is distributed and transmitted to the AHB bus, APB bus, USB device, and kernel. Among
[Microcontroller]
S3C2440 clock system notes
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号