Author Topic: [Ndless] Interrupts newbie here  (Read 7087 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
[Ndless] Interrupts newbie here
« on: January 05, 2014, 01:19:43 pm »
Hey guys,

I want to make, like, the simplest interrupt ever : increment a variable if the second timer (0x900D0000) reaches zero.

About interrupts, I already know ... nothing. I'd need something like :

Code: [Select]
attachInterrupt(0x900D0000, incrementTimer);
...

void incrementTimer(void)
{
  timing++;
}

Can anyone help me with that ?
« Last Edit: January 05, 2014, 01:20:31 pm by Matrefeytontias »

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless] Interrupts newbie here
« Reply #1 on: January 05, 2014, 01:53:33 pm »
You need to set some VIC registers at 0xDC000000 to activate only the interrupt you want,
write the address of a function with __attribute__((interrupt("IRQ"))) (IIRC) to one of ARM's exception vectors.
0x38 should be the one for IRQs and then you have to reset bit 0x80 in the CPSR and hopefully it doesn't crash :P
« Last Edit: January 05, 2014, 05:06:58 pm by Vogtinator »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Interrupts newbie here
« Reply #2 on: January 05, 2014, 02:36:49 pm »
</chinese>

Do you have English explanations instead ? D: I said I was a newbie9001 on-purpose :/

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless] Interrupts newbie here
« Reply #3 on: January 05, 2014, 05:06:20 pm »
1. Disable all IRQs: VIC_REG(0x14) = ~0
2. Enable the IRQ you want: VIC_REG(0x10) = 1 << IRQ (2nd timer is 19)
3. Install your irq handler:
Code: [Select]
volatile int timing = 0;
static void __attribute__((interrupt("IRQ"))) irq_handler()
{ timing++; TIMER_REG(0xc)=1;}
*0x38 = (uint32_t)irq_handler;
4. Configure the timer
5. Reset bit 0x80 in the cpsr:
Code: [Select]
    __asm__ volatile("mrs r0, cpsr;"
                    "bic r0, r0, #0x80;"
                    "msr cpsr_c, r0;" ::: "r0");
6. Make some coffee, after the coffee is finished, you'll have
7. Profit!

You'll have to find out VIC_REG, TIMER_REG, step 4 and why I'm writing to 0x38 yourself :P

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Interrupts newbie here
« Reply #4 on: January 06, 2014, 01:04:11 am »
Is that for the CX or the non-CX ? Also why do I have to guess, there's no way I could find out myself >_< I've read both Hackspire pages about Interrupts and Memory-mapped I/O registers, and can't guess sh*t <_<

If Step 4 only deals with the controller itself (like setting the timer load or the divider), I know how to do that. I guess 0x38 is a pointer called on interruption, but where the hell did you get that value from >_< the rest really I have no clue on.
« Last Edit: January 06, 2014, 01:07:54 am by Matrefeytontias »

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless] Interrupts newbie here
« Reply #5 on: January 06, 2014, 06:23:34 am »
It's for the CX, you'll have to find out how to do it on the older calcs yourself, it's not really that hard.
The things you'll have to do won't change, just what you have to write to which address.
Quote
I guess 0x38 is a pointer called on interruption, but where the hell did you get that value from >_< the rest really I have no clue on.
Enter debug mode in nspire_emu and "u 0".

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Interrupts newbie here
« Reply #6 on: January 06, 2014, 06:27:06 am »
The things you'll have to do won't change, just what you have to write to which address.

They will, since the CX and non-CX have different interrupt hardware. I'll see for the rest.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless] Interrupts newbie here
« Reply #7 on: January 06, 2014, 06:51:27 am »
Only difference is that you'll have to ACK interrupts to the IC on the older calcs.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Interrupts newbie here
« Reply #8 on: January 06, 2014, 08:05:04 am »
About interrupts, I already know ... nothing.


Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: [Ndless] Interrupts newbie here
« Reply #9 on: January 06, 2014, 08:34:52 am »
ACK=acknowledge
IC=Interrupt controller