Hi everybody,
I have developed a code for s12xdp512 that uses,
On s12x CPU:
- 2 PITs(10us and 1ms) which one with interrupt,
- 2 SPI (Masters at 10MHz and 1.67 MHz),
- 1 SCI (115200 bps) with interrupt,
and on Xgate:
- 1 SPI (Slave) on xgate working at 8MHz.
The xgate receives a SPI frame with length variable depending of a command byte defined in a proprietary protocol that comes from another processor. I have too a signal for framing all frame transmitted from the other processor (this signal in idle is high and comes to low when before any transmission between the other processor and Xgate and comes to high when the transmission comes to a end).
I was trying to program some fail-safe code, to prevent the case that previous transmission has being cut to half for some unknown reason, by using the IRQ interruption to stop any pending or running thread and restart the communication on xgate.
But my problem is this, everytime that I register #IRQ on interruption vector, I get approximaly between 30 seconds to 2 minutes from that I click on run button on debugger to get an ILLEGAL_BP. If I don't register the interruption I don't have any problem (the maximum time that I have left the board running was for 3 days consecutive).
I have have defined this sets:
on prm file:
VECTOR ADDRESS 0xFFF2 IRQ_INT // Interrupt function for external interrupts
on main.c file:
(initialization code)
IRQCR_IRQE=1; /* Falling edge selected */ IRQCR_IRQEN=1; /* External Interrupts Enabled */
(interruption definition)
interrupt void IRQ_INT(void){ IRQCR_IRQEN=0; asm("CLI"); IRQCR_IRQEN=1;}
Can anyone have some idea about why is this happening?
Stack size not large enough would be the first thing to check.
on prm file i have the stacksize define has:
STACKSIZE 0xFFF /* size of the stack (will be allocated in DEFAULT_RAM) */
It shouldn't be a problem. There is any form to check the stack usage?
0xFFF should be enough stack.
I normally fill the stack at startup with a known value. It is then easy to look at the stack in the debugger and see how much is left. You can also set a write watchpoint in the debugger near the bottom of the stack. If the stack grows past that point, the watchpoint will trigger, and you can work out why.
The stack can overflow if you allow an interrupt to interrupt itself. You code snippet shows a CLI inside the IRQ, then you enable interrupts. If there is an further IRQ request pending it will interrupt before the existing IRQ has exited when you do the IRQCR_IRQEN=1 , and the stack will keep growing.