0

3 Interrupts enabled, 1 UART to IRQ (serial port), Timer1 to IRQ (to control a flickering LED), and Timer0 to FIQ (to generate an output stepping signal).

first FIQ handler is empty:

void FIQ_HANDLER(void) __fiq
{
   if(FIQSTA & TIMER0)
   {
        T0CLR = 0;
        break;
   }
}

IRQ handler:

void IRQ_HANDLER(void) __irq
{
   if(IRQSTA & TIMER1)
   {
        T1CLR = 0;
        MAKE_LED_FLASH();
        break;
   }
   if(IRQSTA & UART)
   {
        BLAH_BLAH_BLAH();
        break;
   }
}

The code above works just fine, LED flashing, UART responses, and other functions well. But after I added some codes to the FIQ handler, mainly setting a counter(uint16) and let the IO go hign/low:

void FIQ_HANDLER(void) __fiq
    {
       if(FIQSTA & TIMER0)
       {
            if(cts>0)
            {
                IO_BLAH_BLAH_BLAH();
                cts--;
            }
            T0CLR = 0;
            break;
       }
    }

the CPU will lock itself up a few seconds after startup (~2sec), then led stops flashing, UART not responding. Even variable cts is set to 0 at beginning (thus if() cannot be entered).

I first thought it might because of the timer0 set too fast(so that more FIQs stacking together and less being clearing out). So I set timer0 to less frequently. And..alright, seems to be OKAY at startup, LED keeps flashing...but if I send some chars via serial port (UART), the system immediately get locked up again. -_-! WHAT'S WRONG?

Please, if I miss any important information to be written here, just let me know.

Kara
  • 6,115
  • 16
  • 50
  • 57
Ge Rong
  • 416
  • 5
  • 17
  • 1
    How often is the FIQ firing? Sounds like it may simply be consuming all the processor time. – PeterJ Dec 28 '12 at 23:49
  • 1
    Hmm.. does the 'IO_BLAH_BLAH_BLAH()' function use R0-R7? I'm guessing that the actual FIQ handler itself will not because the '__fiq' attrib signals to the compiler to use only R8-R14, but if that handler calls anything else, R0-R7 could get corrupted? – Martin James Dec 29 '12 at 10:38

1 Answers1

1

Perhaps one stack is overflowing and corrupting the other. Check that you've initialised the FIQ, IRQ, and other stacks correctly and that you've reserved enough memory for each stack.

kkrambo
  • 6,643
  • 1
  • 17
  • 30
  • 1
    +1 - yup, another good possibility. So far, I have managed to get away with all-assembler FIQ handlers that use no stack at all, just the swap-registers, but not always possible.. – Martin James Dec 29 '12 at 18:44
  • Thank guys. I checked the assembler (in IDE) and found related configs of IRQ memory and code optimization stuff. Just turned off all the memory and code optimization. can't 100% rely on those handlers anymore.... – Ge Rong Dec 31 '12 at 14:30