MCF5208 interrupt problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF5208 interrupt problem

2,804 Views
Mr_Ushuaia
Contributor I
Hi,
 
my problem is the following: I can not handle any interrupt! In my example I just want to handle the interrupt with timer 0.
Here is the code:
 
void main(void)
{
       mcf5xxx_irq_disable();
       mcf5xxx_set_handler(68, PIT0_handler); 
 
       MCF5208_INTC_ICR(4) = MCF5208_INTC_ICR_IL(2);
       MCF5208_INTC_IMRL &= ~(0
                           |MCF5208_INTC_IMRL_INT_MASK4); 
       
        MCF5208_PIT0_PMR =  40000;                     // 40MHz/40000 = 1kHz
       MCF5208_PIT0_PCSR = 0                            
                           | MCF5208_PIT_PCSR_EN        // Bit 0: PIT enable
                           | MCF5208_PIT_PCSR_RLD     // Bit 1: Counter reloaded from PMRn on count of 0x0000
                           | MCF5208_PIT_PCSR_PIE       // Bit 3: PIT interrupt enable
                           | MCF5208_PIT_PCSR_PRE(1); // Bit 8-11: Prescaler 2 (80MHz/2=40MHz)
   
       mcf5xxx_irq_enable();
}
 
 
__interrupt__ void PIT0_handler(void)
       printf("Interrupt occured");
        fflush(stdout);
 
       MCF5208_PIT0_PCSR = MCF5208_PIT0_PCSR
                          | MCF5208_PIT_PCSR_PIF;
}
But what happens is an illegal instruction error. If I disable the "mcf5xxx_irq_enable()" the flag is on when the counter reaches 0x0000.
Does someone tell me what is wrong?
 
Mr. Ushuaia
Labels (1)
0 Kudos
6 Replies

621 Views
SimonMarsden_de
Contributor II
I'm only guessing, but could the problem be caused because the main() routine has terminated by the time the interrupt occurs?

You could investigate by adding something like:

while (1)
; // Wait forever

...to the end of the main function. (Of course, in real code you'll want to do something more useful, or use STOP, or similar).

Of course, your example may just be a simplified part of a larger bit of code, in which case ignore me :smileyhappy:
0 Kudos

621 Views
Mr_Ushuaia
Contributor I
Hi Simon Marsden
 
Thank you for your quick response. As you guessed my example is a simplified part of a larger bit of code. Anyway if I copy exactly this code and add "while(1)" at the end of the main function I still have the same problem.
 
Mr. Ushuaia
0 Kudos

621 Views
SimonMarsden_de
Contributor II
Hi

I don't have a 5208 board handy, but I got curious and tried your code on a Freescale M5329EVB. (The 5329 has a similar PIT and interrupt controller, so I just had to modify the code a little). Guess what - it all works OK.

Maybe the PIT is nothing to do with the problem. If you're enabling interrupts, it's possible that an interrupt related to something else is occuring and killing you before the PIT handler runs.

To test this theory, you could try changing the code so that only the PIT interrupt is enabled:

MCF_INTC_IMRH = 0xffffffff;
MCF_INTC_IMRL = ~MCF5208_INTC_IMRL_INT_MASK4;
0 Kudos

621 Views
p_vagnoni
Contributor III
Hello,
 
my tip for you is: have you insert the interrupt in the vector table?
 
I mean, i work with the 52235 and I have similar problem, remember that when you add some interrupt function you have to define it in the vector table (I think it is in the *vectors.s file).
 
Best regards
0 Kudos

621 Views
Mr_Ushuaia
Contributor I
Hi
 
thank you everyone for your help. But it still does not work. In fact, when I redo a project and when I compile a simple main (print ot the screen "hello world") that works. But when I want to compile the "Coldfire Support file" in which there is the vectors.s file, I cannot! I get this message:
. Link error: Undefined: "mcf5xxx_exception_handler"
 Referenced from "asm_set_ipl" in "mcf5xxx_lo.s"
. Link failed
 
It seems it do not recognize this function. But why? This is an integrated function to handle exceptions!
I did not remember that when I started my program I used tricks in order to compile without problems.
 
Maybe someone met this problem. I wrote to my handler but I did not get answer. Any idea?
 
Mr. Ushuaia
0 Kudos

621 Views
p_vagnoni
Contributor III
Hi,
 
maybe you have not include the file "mcf5xxx.c": Infact in this file there is a definition of this function that is called in "mcf5xxx_lo.s" as the error message says you!!
 
Bye,
0 Kudos