external interupts

yusuf ilker ozturk
I am trying to use K1 button as External interrupt and change the speed of
the blinking leds. When I run from RAM the program hangs, I think it never
enters to ISR and get out..
In the chinese forums I read about MMU but could not understand.

Can anybody has a clue about the below code?

Thanks,

Yusuf 

#include "S3C2440.h"


extern volatile int speed;

/* delay Function                                                          
   */
void delay100us(unsigned int tt)
{
   unsigned int i;
   for(;tt>0;tt--)
   {
     for(i=0;i<1000;i++){}
   }
}

int main(void) {
//INIT PORTS
   GPBCON = 0x15400;   //    GPB 5,6,7,8 output,
   GPGCON = 0x145442;   //    GPG 3,5,6,7,9,10 output,GPG 0 EINT[8]
   GPFCON = 0x1400;   //    GPF 5,6  output.  
//EINT[8] will be falling edge triggered. Enable EINT[8]
   EXTINT1 = 0x2;        
   EINTMASK = 0xFFFeFF;
   INTMSK &= ~(BIT_EINT8_23);   /* Enable BIT_EINT8_23 interrupt*/

  speed = 15000;
     while(1)
     {
      GPBDAT = 0x3C0 ;
       GPBDAT &= LED1L ;
       delay100us(speed);
       GPBDAT &= LED2L ;
       delay100us(speed);
       GPBDAT &= LED3L ;
       delay100us(speed);
       GPBDAT &= LED4L ;
       delay100us(speed);
  }
}

///////////////////////////////
#include <S3C2440.H>

volatile int speed;

extern void delay100us(unsigned int);

/* Common interrupt handler, handles all interrupts */
__irq void IRQ_Handler (void) {

  unsigned int msk = (1 << INTOFFSET);

  GPBDAT = 0x1E0 ;

  switch (msk) {
    case BIT_EINT8_23:            /* BIT_EINT8_23 interrupt mask */
    speed = 3000;
    break;
  }
  SRCPND = msk;                    /* Clear Interrupt*/
  INTPND = msk;
}

ram
Hi,

You have to initialize the external interrupt vector with your ISR. This
location might be after the 0x20 location. This assignment is just like the
IRQ and FIQ initialization.

Regards,
Ram.

nanas
Hi Ram,
can u give me the example code of interrupt inisialisation?

purnendu
you need to write the address of your interrupt handler come ISR i.e.
"IRQ_Handler" in the vector address table. if its a common ISR the place
the irq_handler add in all locations of vec table.eg:

        *(unsigned int *(0x...vector loc...))= IRQ_Handler;
If processor is having interrupt controller as in s3c2440(arm920T) the
write  IRQ location in specific addresses under the interrupt controller

purnendu
the eg. i gave in the previous suggestion would rather be :

       *(unsigned int *(0x...vector loc...))= (unsigned int)IRQ_Handler;

kiranvarma
hi pernendu,

I am getting dummy_isr error in the hyperteminal for interrupt serial
program.
plz help me to come out of this.
so many people says use mmu.h
but nobody providing complete mmu.h and mmu.c files. 
files available in the internet are not complete and my compiler(KEIL ARM)
showing errors. plz help me.

kiranvarma
i am using s3c2440 processor in mini2440 board.

Anatoliy
You can look at Interrupt example at: code.google.com/p/startos

Shahid Riaz
void Init_Timer4(void){
  rTCON &= xff8fffff;     //clear manual update bit, stop Timer4
  rTCFG0 &= 0xffff00ff;    //clear Timer 2,3 & 4 prescaler 1
  rTCFG0 |= 0xf00;   //set prescaler = 15+1 = 16  
  rTCFG1 &= 0xfff0ffff;   //set Timer4 1/2 Mux
  rTCFG1 |= 0x10000;   //  set Timer4 MUX 1/4    
  rTCNTB4 = (PCLK / (4*15*1000)) - 1;  //get 1mSec Interval value   
 
  rTCON |= 0x200000;     // manual updata 
  rTCON &= 0xff8fffff;   // down the manual update flag
  rTCON |=  0x500000;    // interval mode auto reload and start Timer 0  

  rEINTPEND |= (BIT_TIMER4);
  rEINTMASK &= ~(BIT_TIMER4); 
  ClearPending(BIT_TIMER4);
  pISR_TIMER4= (U32) Timer4_IRQ;
  EnableIrq(BIT_TIMER4);  
}

int MiliSec10Count = 0;
int timer1ms[4];
int timer10ms[4];

void __irq Timer4_IRQ(void){

int i;

  ClearPending(BIT_TIMER4);
  if(rEINTPEND & (1<<14)) {
     rEINTPEND |= (1<< 14);
  }
  for(i=0; i<4; i++){
     if(timer1ms[i])
     timer1ms[i]--;
  }
  if(++MiliSec10Count==10){
     MiliSec10Count = 0;
     for(i=0; i<4; i++){
        if(timer10ms[i])
  timer10ms[i]--;  
     }
  }
}

this is a simple code, I defined 4 1 msec timer and 4 10 msec timer. If any
timer have value, interrupt service routine will decrement its value
otherwise do noting simply clear pending interrupt and exit. 

while as concern to interrupt setup, every interrupt has its own mechanism
to start and setup. This is 100% working code and I am using it in my DOS
like OS. It keep update the OS timer. I have used timer4 because it dont
have any OUT. So other timers can be available for other functions. Enjoy
this code with interrupts.

amir
Dear "Shahid Riaz"
This code is not working at all.