Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Timer Interrupt Handler   Message List  
Reply | Forward Message #5974 of 15019 |
Re: [gbadev] Timer Interrupt Handler

What I did was add some code to my crt0.s for the irq handler. You must
write it in ARM code (.arm or .code 32). I'm not sure if you have to
save/restore registers, but I did. I call my c code interrupt handler
(which is in thumb code) to do the real stuff.

The interrupt actually happens when a timer rolls over (65535 to 0), so make
sure you enable the timer, and set the irq enable on it.

Here is some code:

#define TIMER0_IRQ 3
#define TIMER1_IRQ 4
#define TIMER2_IRQ 5
#define TIMER3_IRQ 6
#define REG_IME *(volatile uint16*)0x4000208
#define REG_IE *(volatile uint16*)0x4000200
#define REG_IF *(volatile uint16*)0x4000202
#define REG_TM0D *(volatile uint16*)0x4000100
#define REG_TM0CNT *(volatile uint16*)0x4000102
#define REG_TM1D *(volatile uint16*)0x4000104
#define REG_TM1CNT *(volatile uint16*)0x4000106
#define REG_TM2D *(volatile uint16*)0x4000108
#define REG_TM2CNT *(volatile uint16*)0x400010A
#define REG_TM3D *(volatile uint16*)0x400010C
#define REG_TM3CNT *(volatile uint16*)0x400010E
#define TIM_IRQ_ENABLE (1 << 6)


typedef struct
{
uint32 r00,r01,r02,r03,r04,r05,r06,r07,r08,r09,r10;
uint32 r11,r12,sp,lr;
}reg_list;

enabling irq for timer0
REG_IME = 0; // disable master irq
REG_IE |= (1 << TIMER0_IRQ); // enable timer0 irq
REG_TM0D = 0; // set timer 0 value
REG_TM0CNT |= TIM_IRQ_ENABLE; // make timer 0 trigger an irq, done't forget
to setup the timer and enable it
REG_IME = 1; // enable master irq

handling an interrupt (c code)
void _gba_interrupt_handler(reg_list *regs)
{
uint16 irqs = REG_IF;
uint32 set = (irqs & (1 << TIMER0_IRQ));
if(set)
{
// PROCESS INTERRUPT FOR TIMER 0 here
}

// clear irq flags
REG_IF = irqs;

// re-enable them
REG_IE |= irqs;
}

asm code for irq handling (note: it seems stmia and ldmia are broken on
Mappy):
.CODE 32
.ALIGN 2
.EXTERN _gba_interrupt_handler
.GLOBL _arm_irq_handler
.TYPE _arm_irq_handler,function

_arm_irq_handler:
@ save registers
str r0, [sp, #-4]!
str lr, [sp, #-4]!
sub sp, sp, #15*4
stmia sp, {r0 - lr}^
mov r0, sp

@ call the interrupt handler
bl _gba_interrupt_handler

@ restore registers
ldmia sp, {r0 - lr}^
mov r0, r0
ldr lr, [sp, #15*4]
add sp, sp, #15*4+8

bx lr






Wed Aug 1, 2001 6:04 pm

jeff@...
Send Email Send Email

Forward
Message #5974 of 15019 |
Expand Messages Author Sort by Date

How do you setup a Timer Interrupt Handler on the GBA? I am having problems getting it to work. Thanks [Non-text portions of this message have been removed]...
Travis Estrada
ztte@...
Send Email
Aug 1, 2001
4:49 pm

What I did was add some code to my crt0.s for the irq handler. You must write it in ARM code (.arm or .code 32). I'm not sure if you have to save/restore...
Jeff Slutter
jeff@...
Send Email
Aug 1, 2001
9:44 pm

... You don't, the compiler has 3 seperate sets of registers for system, irq, and swi modes. I'm not sure of the details, but I am pretty sure that your irq...
Jason Wilkins
fenix@...
Send Email
Aug 2, 2001
12:21 am

As others have said: This is FIRQ mode you're thinking about, which is unused on a regular GBA. There is a R14_irq and an R13_irq, but R0 - R12 are the user...
Eddie Edwards
eddie@...
Send Email
Aug 3, 2001
1:17 pm

... Now, that totally rulz! ^_^ Thanks for the info, I never would have thought of it (guess I'm not sneaky enough)....
Jason Wilkins
fenix@...
Send Email
Aug 5, 2001
3:58 pm

Hello Jason, Friday, August 03, 2001, 10:26:36 PM, you wrote: ... JW> Now, that totally rulz! ^_^ Thanks for the info, I never would have JW> thought of it...
groepaz
groepaz@...
Send Email
Aug 5, 2001
9:15 pm

Hi Banked registers have their own instance for every cpu-mode (system & user having the same non-banked regs. Upon entering an interrupt: - the link register...
Vince 0x0f
vince_0x0f@...
Send Email
Aug 2, 2001
3:02 pm

... When will your interrupt be an FIQ on the GBA? Aren't all the hardware interrupts IRQ?...
Thomas
sorcererxiii@...
Send Email
Aug 2, 2001
6:17 pm

Hello Thomas, Thursday, August 02, 2001, 7:56:30 PM, you wrote: ... T> When will your interrupt be an FIQ on the GBA? Aren't all the T> hardware interrupts...
groepaz
groepaz@...
Send Email
Aug 2, 2001
8:53 pm

... Yeah, thanks. I read that, but it got distorted. I rely on my memory being better than that, I must be getting old......
Jason Wilkins
fenix@...
Send Email
Aug 3, 2001
3:46 pm

Thanks, I didn't know that ... _________________________________________________________________ Get your FREE download of MSN Explorer at...
Vince 0x0f
vince_0x0f@...
Send Email
Aug 2, 2001
9:54 pm

How to you setup an irq to run your code when an interrupt occurs does anyone has an example of this? Thanks ... This message was sent using TSTT Webmail. ...
ztte@...
Send Email
Aug 5, 2001
4:01 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help