ARM9 S3C2440 - Initialization configuration of interrupts and timers

Publisher:YaqiLatest update time:2015-09-07 Source: eefocusKeywords:ARM9 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   ARM9  S3C2440 has a lot of registers, which is one of the differences between it and single-chip microcomputer. ARM programming is mainly about register operations, but with so many registers, it is easy to forget the setting of a certain register. If you can summarize the steps of register configuration so that it has rules to follow, you can find the right one when you apply it. If you don't use ARM for a long time, it will be a waste of time to read the annoying chip user manual again when you use it again. In this way, you can record these key points while you are familiar with them, and you can recall them by looking at them later. This is also the reason why I write these blogs.

The main steps for timer initialization configuration are:

 

1. Setting of rTCFG0 and rTCFG1

   First, we need to set the timer clock frequency.

Timer  input  clock  Frequency=  PCLK  {prescaler  value+1}  {divider  value}

   [7:0] of TCFG0 stores the prescaler  value of timer 0 and timer 1, and [15:8] stores the prescaler  value of timer 2, timer 3, and timer 4.

    Every four bits of TCFG1, starting from the low bit, represent the divider  value.

0000  1/2 

0001  1/4 

0010  1/8

0011  1/16 

01xx  External  TCLK0

For example: rTCFG0  49;               //pclk/(49+1)

      rTCFG1  0x03;             //16 division = 62500HZ

 

2.  Setting of rTCNTBx and rTCMPBx

   Set TCON to start timer x (x represents 0-4, 2440 has 5 16-bit timers, timers 0-3 have PWM function and output pins, and timer 4 has no output pins). At this time, TCNTBx→TCNTx, TCMPBx→TCMPx, at the working frequency of the timer, TCNTx starts to decrease by 1, and its value can be obtained by reading TCNTOx. When TCNTx=TCMPx, the output pin TOUTx of timer x reverses, and TCNTx continues to count by 1. When TCNTx=0, its output pin TOUTx reverses again and triggers the interrupt of timer x. Therefore, the timing value used for interruption is determined by rTCNTBx. When used as PWM function, the frequency of PWM is determined by rTCNTBx, and the duty cycle is determined by rTCMPBx. The duty cycle is equal to rTCMPBx  rTCNTBx. TOUTx (x=0~3) is connected to an external buzzer to control the frequency of the buzzer or an external LED light to control the brightness of the LED light. The larger the duty cycle, the larger the buzzer frequency and the brighter the LED light.  If not used for PWM, rTCMPB0 is generally  set to 0.

For example: rTCNTB0  62500/2;           //TCNTB0[15:0]=count value  

      rTCMPB0  0;

 

3. Setting of rTCON

    The TCON register controls the start of the timer (1 means start), whether to automatically load the initial value (TCNTBx  and TCMPBx, 1 means automatic loading), whether the PWM dead zone is started (1 means enabling the dead zone), and TOUTx reversal start (1 means allowing reversal).

For example: rTCON  = 0x09;   //, start the timer and allow reloading of TCNTB0 and TCMPB0

 

4. Clear the IRQ or FIQ interrupt, such as calling the ClearPending(BIT_TIMER0) function.

    For sub-interrupts use ClearSubPending(int  bit).

 The macro definition of BIT_TIMER0 in 2440addr.h is

#define  BIT_TIMER0 (0x1<<10)

The definition of the ClearPending function in the header file 2440addr.h is:

__inline  void  ClearPending(int  bit)

{

register  i;

rSRCPND  bit;

rINTPND  bit;

rINTPND;

}

 

__inline  void  ClearSubPending(int  bit)

{

register  i;

rSUBSRCPND  bit;

rINTPND;

    ClearPending and ClearSubPending are inline functions. During compilation, similar to macro replacement, the function body is used to replace the function name at the calling point instead of calling these two functions. The cost of increasing the size of the program code is exchanged for the efficiency of program operation, because function calls need to protect the scene, and stack push and pop consume CPU time.

    The corresponding bits of SRCPND, SUBSRCPND, and INTPND are 1, indicating that a corresponding interrupt has occurred. Multiple bits of SRCPND and SUBSRCPND can be set to 1 at the same time, indicating that multiple interrupts have occurred. However, the INTPND register is prioritized, so only one bit can be 1 at the same time.

    It is also worth noting that the clearing of the three suspend registers SRCPND, INTPND, and SUBSRCPND is not done by directly writing 0, but by setting the corresponding position to 1. This must be paid attention to. Of course, when programming, you can directly call these two functions, which are already included in the header file, but it is still very interesting to understand this special feature.

 

5. Setting of rEXTINTx (P301), rEINTPEND (P306), and rEINTMASK (P305)

    These three registers are for external interrupts. The timer is an internal interrupt. There is no need to configure these registers for timer initialization. When using external interrupts such as buttons and switches, these registers must be configured.

    The EXTINTx register is used to set the interrupt trigger mode of 25 external interrupts, 000  low level, 001  high level, 01x  = falling edge  , 0x  rising edge, 11x  edge triggered Both  edge  triggered. For example, set the interrupt trigger mode of external interrupts 11, 13-15 to falling edge triggered.

rEXTINT1  &=  ~(7<<12  7<<20  7<<24  7<<28);
rEXTINT1  |=  (2<<12  2<<20  2<<24  2<<28) ;

   If the corresponding bit of the EINTPEND register is 1, it means the corresponding external interrupt occurs, and 0 means no corresponding interrupt occurs. The register should be cleared during initialization to prevent interference from the original interrupt. The clearing method is the same as the clearing method of the three registers SRCPND, SUBSRCPND, and INTPND. Write 1 to the corresponding bit, but there is no function call similar to ClearPending, so you must write it yourself. For example, the external interrupt 11, 13-15 interrupt pending register is cleared:

rEINTPEND  |=  (1<<11)|(1<<13)|(1<<14)|(1<<15);

    EINTMASK register 0 means enabling the corresponding bit interrupt, 1 means disabling the corresponding bit interrupt. The default is disabled. For example, if external interrupts 11, 13-15 are enabled, the corresponding bits are written as 0.
rEINTMASK  &=  ~((1<<11)|(1<<13)|(1<<14)|(1<<15));

In addition, ClearPending (BIT_EINT1 | BIT_EINT2 | BIT_EINT8_23) should be used to clear the interrupt pending register. Note that  EINTPEND  just now clears the secondary interrupt, and EXTINT  8-23  all pass  the interrupt number 5 belonging to IRQ  , so the main IRQ interrupt is cleared here.

 

6. Setting of rINTMOD (P386), optional

   Generally, it can be left unset, because the default interrupt mode is IRQ mode, unless you want to set it to FIQ mode, the corresponding bit of INT is 1, the interrupt source is FIQ mode, 0 means IRQ mode, FIQ is usually used to handle particularly urgent interrupts. [page]

 

7. rPRIORITY (P390) ​​setting, optional

   Priority register setting, set the interrupt priority. Generally, it is not set and the default priority can be used.

 

8. Set the interrupt program entry, such as pISR_TIMER0  (U32)IRQ_Timer0_Handle;

    External interrupt pISR_EINT8_23  (U32)Key_ISR;

    Key_ISR is the name of the interrupt program function, that is, the entry address of the interrupt service function, which is forced to be converted to an unsigned 32-bit integer here.

The macro definition of pISR_EINT8_23  in 2440addr.h is

#define   pISR_EINT8_23   (*(unsigned  *)(_ISR_STARTADDRESS+0x34))

   pISR_EINT8_23 is an address in the vector table. When external interrupt 8-23 occurs, the program jumps to the corresponding address of the interrupt vector table. The vector table stores the entry address of the interrupt service function, and the program executes the interrupt service program.

 

 9. Enable interrupts, such as EnableIrq(BIT_TIMER0); 

Enable external interrupt EnableIrq(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);

This macro is defined in 2440addr.h and its prototype is

#define EnableIrq(bit) rINTMSK  &=  ~(bit)

#define EnableSubIrq(bit) rINTSUBMSK  &=  ~(bit)

 

At this point, all interrupt and timer initialization work is completed!

 

10. Write an interrupt service routine

static  void  __irq  Key_ISR(void){}

_irq is a C keyword that tells the compiler that this program is an interrupt program so that special processing can be done. In an interrupt program, the main things to do are:

(1) Clear the interrupt source pending register, such as ClearPending (BIT_EINT8_23);

(2) For external interrupts, the relevant bits of the EINTPEND register must be cleared, such as

 rEINTPEND  |=  1<<  11; The purpose of these two steps is to prevent repeated interrupts. When there are multiple interrupt sources, it is necessary to determine which interrupt source it is and clear the corresponding bit.

(3) Complete the functions of interrupt characteristics. For example, key interrupt service program

static  void  __irq  Key_ISR(void)

{

U8  key;

   if(rINTPND==BIT_EINT8_23) 

   {

     ClearPending(BIT_EINT8_23);

       if(rEINTPEND&(1<<11)) 

      {

        rEINTPEND  |=  1<<  11;

      }

      if(rEINTPEND&(1<<19)) 

     {

        rEINTPEND  |=  1<<  19;

     }

  }

  if(rINTPND==BIT_EINT0) 

  {

      ClearPending(BIT_EINT0);

  }

  if(rINTPND==BIT_EINT2) 

  {

     ClearPending(BIT_EINT2);

  }//The above are all to clear the corresponding bits of the relevant registers. When using multiple interrupts, it is necessary to determine which bit to clear conditionally.

 Write the interrupt program for specific functions here

}

 

 

Timer initialization    

void  Timer0_init(void)

{

  //Timer  init

  rTCFG0  49;               //pclk/(49+1)

  rTCFG1  0x03;             //16 division = 62500HZ

  rTCNTB0  62500/2;           //TCNTB0[15:0]=count value  

  rTCMPB0  0;    

  rTCON  =0x09;   //Start the timer and allow the count value to be reloaded into TCNTB0, TCMPB0

  

  ClearPending(BIT_TIMER0);

  pISR_TIMER0  (U32)IRQ_Timer0_Handle;

  EnableIrq(BIT_TIMER0); 

}

  Timer interrupt processing function  

static  void  __irq  IRQ_Timer0_Handle(void)

{

    

ClearPending(BIT_TIMER0);

    Write the interrupt program for specific functions here

}

Keywords:ARM9 Reference address:ARM9 S3C2440 - Initialization configuration of interrupts and timers

Previous article:ARM9 S3C2440—GPIO initialization settings
Next article:ARM9 S3C2440-ADC and touch screen control detailed explanation

Recommended ReadingLatest update time:2024-11-23 05:17

Overview of S3C2440 power-on startup process
1. S3C2440 startup method 1. Boot media When S3C2440 is powered on, it determines the position where the instruction starts to be executed (i.e. the position of the boot ROM) by judging the signal combination of OM0 and OM1. At the same time, these two signals are also used to determine the bus width of BANK0 (nGCS0).
[Microcontroller]
Overview of S3C2440 power-on startup process
S3C2440 UART serial port driver 1
1.1 UART serial port Universal Asynchronous Receiver and Transmitter (UART) is abbreviated as UART. It is usually the default communication interface configured in embedded devices. This is because many embedded devices do not have display screens and cannot obtain real-time data information of embedded devices. They
[Microcontroller]
S3C2440 UART serial port driver 1
Software/Hardware Design of Web Server Boa Based on ARM9
1. Introduction to ARM Generally speaking, any dedicated hardware and software system with a microprocessor can be called an embedded system. It is a dedicated computer system embedded in an object system, centered on applications and based on computer technology. The hardware and software can be tailored to meet the
[Power Management]
Software/Hardware Design of Web Server Boa Based on ARM9
Design of I2C touch screen based on ARM processor S3C2440 and Linux system
0 Introduction With the development of computer-related technologies, ARM embedded systems are increasingly widely used and are increasingly integrated into people's lives. Touch screen devices are widely used in this embedded field due to their friendly human-computer interaction, convenient and flexible oper
[Microcontroller]
Design of I2C touch screen based on ARM processor S3C2440 and Linux system
USB hot-swap driver problem for s3c2440
The USB driver of s3c2440 has better support in the newer LINUX kernel, and the code modification is less, but there are still some problems. The modification records are as follows: 1. Pay attention to selecting the following items in the compilation options, and the others can be selected according to a
[Microcontroller]
Implementation of external NANDFLASH control based on ARM9 core processor
NANDFLASH NAND has a fast write-back speed, a small chip area, and especially a large capacity, which makes it an obvious advantage. Page is the basic storage unit in NAND. One page is generally 512B (there are also largepage NAND FLASH with 2kB per page), and multiple pages form a block. The number of pages in a bl
[Microcontroller]
Implementation of external NANDFLASH control based on ARM9 core processor
Samsung S3C2440 processor interrupt alias
#define BIT_EINT0  (0x1) #define BIT_EINT1  (0x1 1) #define BIT_EINT2  (0x1 2) #define BIT_EINT3  (0x1 3) #define BIT_EINT4_7  (0x1 4) #define BIT_EINT8_23 (0x1 5) #define BIT_CAM   (0x1 6)  // Added for 2440. #define BIT_BAT_FLT  (0x1 7) #define BIT_TICK  (0x1 8) #define BIT_WDT_AC97 (0x1 9) // Changed from
[Microcontroller]
Detailed explanation of U-boot transplantation on S3C2440 (1)
1. Transplantation environment Host: VMWare--Fedora 9 Development board: Mini2440--64MB Nand, Kernel:2.6.30.4 Compiler: arm-linux-gcc-4.3.2.tgz u-boot:u-boot-2009.08.tar.bz2 2. Transplantation steps Features of this transplant include: Support Nand Flash reading and writing Support booting from Nor/Nand Flash
[Microcontroller]
Detailed explanation of U-boot transplantation on S3C2440 (1)
Latest Microcontroller Articles
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号