You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Interrupts and new gccvb
Posted on: 2007/7/16 16:35
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Hi guys, I have a new problem developing for the VB, this time is about interrupts, some time ago I asked for how to measure time and got some responses... sadly I didn't understand that much about interrupts and made somethings wrong... the time measurement. I was not calculating time based on the timer interrupt but with some fancy software method which in the end proved to not be that much accurate.

I have been all the weekend trying to figure it out why when
compiling with the latest version of gccvb, crt0.s and vb.ld, somehow,
the following VIP_REGS just don't update its state:

INTPEN is allways 0x601F

This way I can't get the timer interrupt to work, and all physics
simulations just can't be done accurately.

Now, I have noticed a few things from the new crt0.s, it defines the
timer interrupt vector as follows:

/* INTTIM (7FFFE10h) - Timer Interrupt */
add -4, sp
st.w r1, 0[sp]
movhi hi(_tim_vector), r0, r1
movea lo(_tim_vector), r1, r1
jmp [r1]


now, the add -4, sp instructions as the VB development manual states
that has to be written in order to not loose the call records, but it obligates the programmer to put the following
instruction at the end of his tim_vector function:

add 4, sp

otherwise, the control flow is lost.

I've tried to compile using older versions of ctr0.s anb vb.ld, even one
from the gccvb for Windows but the result is the same.

This problem causes that even when the tim interrupt flag is raised in
TRC hardware registry, the interrupt it is not fired, but just the first time.

Any idea?

Thanks a lot for your time.

jorgeche
Top

#2
Re: Interrupts and new gccvb
Posted on: 2007/7/16 18:54
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
I haven't used the interrupts on the new gccVB, but inside the ISR there should be an add 4, sp before the reti. Does the rest of the program still run, or does it lock up? If everything else runs, you're probably getting out of the interrupt just fine, but the interrupt flag probably isn't being cleared (I never really looked at it for the V810, but usually you have to clear the interrupt once it occurs or it'll never occur again). I just took a quick look at the V810 manual and it looks like it may be the EP bit in the PSW (which I thought reti was supposed to take care of). I assume you're testing this in the emulator? If so, dump the registers and check the flags. You may also want to make sure it's actually calling reti and not jmp or another branch.

DogP
Top

#3
Re: Interrupts and new gccvb
Posted on: 2007/7/16 19:54
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
ok... here is how it goes:

first activate interrupts
//setup interrupts
VIP_REGS[INTCLR] = VIP_REGS[INTPND];
VIP_REGS[INTENB] = 0x0000;
setIntLevel(0);
INT_ENABLE;
//setup timer
timerFreq(TIMER_100US);
timerSet(TIME_MS(10));
timerClearStat();
timerInt(1);
timerEnable(1);

then the interrupt handler

void tim_vector() {
timerInt(0);
VIP_REGS[INTCLR] = VIP_REGS[INTPND];
timerEnable(0);
timerClearStat();
timerEnable(1);
count++; //global variable
timerInt(1);
setIntLevel(0);
asm("add 4,r3"); //if not put, the sp will point to other call record
}

and in the machine code I get:


07002c02 <_tim_vector>:
7002c02: 5f 01 mov lp, r10
7002c04: 00 ac 68 82 jal 700ae6c <__save_r31>
7002c08: c0 40 mov 0, r6
.
.
.
.
7002c4a: 64 44 add 4, sp
7002c4c: 00 a8 2c 82 jr 700ae78 <__return_r31>



and for the interrupt vector:


0703fe00 <_int_table>:
703fe00: 7c 44 add -4, sp
703fe02: 23 dc 00 00 st.w r1, 0[sp]
703fe06: 20 bc 01 07 movhi 1793, r0, r1
703fe0a: 21 a0 8a 89 movea -30326, r1, r1
703fe0e: 01 18 jmp [r1]
703fe10: 7c 44 add -4, sp
703fe12: 23 dc 00 00 st.w r1, 0[sp]
703fe16: 20 bc 00 07 movhi 1792, r0, r1
703fe1a: 21 a0 02 2c movea 11266, r1, r1
703fe1e: 01 18 jmp [r1]
.
.
.
.

So, I guess I'm not getting the EP bit in the PSW be cleared?...

Later I used a code from Lameboyadvance wich includes a reti instruction:

asm("
di /* Disable interrupts */
add 4, r3 /* Set sp back to previous value */
ei /* Re-enable interrrupts */
reti /* Return from interrupt */
");

return;


but I get the same result:

VIP_REGS[INTPND] = 0x601E always



Thanks for your support
Top

#4
Re: Interrupts and new gccvb
Posted on: 2007/7/16 19:57
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Shouldn't the setIntLevel function clear the PSW status?
Top

#5
Re: Interrupts and new gccvb
Posted on: 2007/7/16 22:22
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Hi, it definitively has to do with the new ctr0.s and vb.ld script, I have compiled the demo clock included in the old gccvb under the new one, using the ctr0.o, vb.ld and vb.hdr that came with the old gccvb and it works. the problem is that I think the old scripts and headers does not support multiple o files which my project is divided into.

If I compile the same clock demo, using the new script and crt0, the interrupts don't get fired.
Top

#6
Re: Interrupts and new gccvb
Posted on: 2007/7/16 23:41
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
I haven't used the setIntLevel function, so I don't really know what it does, but it sounds like it just sets the interrupt mask. I believe reti is supposed to clear the interrupt. I thought the new gccVB was supposed to handle all the interrupt stuff for you though... is there a reason you need any inline asm? Have you tried making a simple app that just keeps causing the interrupt? Oh, and shouldn't tim_vector() have a return; at the end? Possibly the compiler looks for the return and handles the stack and reti there, but gets confused if there's no return... I dunno :-P.

DogP
Top

#7
Re: Interrupts and new gccvb
Posted on: 2007/7/16 23:46
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Oh... you could try manually clearing the interrupt in the PSW, or manually restoring the saved PSW from the EIPSW.

DogP
Top

#8
Re: Interrupts and new gccvb
Posted on: 2007/7/17 0:12
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
I will try to manually restore PSW from the EIPSW. as you say tonight. It is very weird. Indeed, the asm statement is mandatory, otherwise the program restores the wrong call record from the stack on handler's return. I be tried these:

asm("add 4,r3");
asm("reti");
return;

but nothing changes, I am begging to believe that there is something wrong with the linker, maybe linking multiples object files or with the ctr0.o file, because the clock demo works either with the new compiler, and with the new vb.ld script, but fails with the new ctr0.

Now, when I try to compile my project with the new compiler, new vb.ld script and old ctr0.o, it again doesn't work.
Top

#9
Re: Interrupts and new gccvb
Posted on: 2007/7/17 0:18
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Now, the old crt0.s does have at the end of the interrupt handler a reti instruction that the new one does not... maybe there is the key... I will experiment tonight, thanks DogP.
Top

#10
Re: Interrupts and new gccvb
Posted on: 2007/7/17 0:28
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Cool... keep us updated.

DogP
Top

 Top   Previous Topic   Next Topic


Register To Post