AnsweredAssumed Answered

CW5.1 with HCS08DZ60, P&E InitKBI bean error

Question asked by Andrea Pastega on Jul 27, 2007
Latest reply on Aug 8, 2007 by Andrea Pastega
Hello.
I'm using two InitKBI beans, one to have PortA interrupts on some pin, the other to have some other in PortB.
I had to setup the event handling to the same function, I don't understand well this need, anyway I did it and PE generated this code:

In Cpu.h: (this is the real IRQ function, as declared in Vectors.c)
----------------------------------------------------
ISR(Cpu__ivVport)
{
  if (PTASC_PTAIF) {                   /* Is the interrupt flag is set? */
    PTASC_PTAACK = 1;                  /* If yes then clear an interrupt flag */
    Interrupt_Buttons();
  }
  if (PTBSC_PTBIF) {                   /* Is the interrupt flag is set? */
    PTBSC_PTBACK = 1;                  /* If yes then clear an interrupt flag */
    Interrupt_Buttons();
  }
}
----------------------------------------------------
This is the function I wrote for handling:

ISR(Interrupt_Buttons)
{
// clear IRQ flag
PTASC |= 0x04;

// reset buttons pressure delay counter
BUTTONS_DELAY = 0xFF;

// test if buttons on port A has been pressed by user
if (!(PTAD & 0x80))   // PTT BUTTON
    BUTTONS_FLAG |= PTT_Key;
if (!(PTAD & 0x04))  // CH+       
    BUTTONS_FLAG |= ChUp_Key;
if (!(PTAD & 0x02))  // CH-
    BUTTONS_FLAG |= ChDown_Key;;
if (!(PTAD & 0x08))  // GAIN+
    BUTTONS_FLAG |= GainUp_Key;
if (!(PTAD & 0x10))  // GAIN-
    BUTTONS_FLAG |= GainDown_Key;

// test if buttons on port B has been pressed by user
if (!(PTBD & 0x04))
    BUTTONS_FLAG |= CCW_Key;
if (!(PTBD & 0x08))
    BUTTONS_FLAG |= CW_Key;
if (!(PTBD & 0x10))
    BUTTONS_FLAG |= Click_Key;
}


All this code works good if I remove or disable the second Init_KBI bean from the project,
while if I just add the second bean the code jumps to nowhere doing RTI in the end of the
execution of my buttons function. I analyzed the situation and I think I found a bug in the way
PE manages the interrupt.
If I use a single bean, it difines in the vector file MY interrupt function. that is called directly.
In this case, when it returns, it find in the stack all the data pushed by the IRQ request.
In the case I'm using two beans, the IRQ handling function is the first that is attached here,
in CPu.c. This goes well, except that then is calling as standard function what effectively is an
interrupt function. IN the end of the execution of this IRQ-function threated as standard-function,
the RTI pulls from the stack the data in different way as standard, and the return address is wrong.
What do you think about it?
Also, because the function in Cpu.c is calling portA or portB handling in two different points, why it is requested that the two beans have to use the same handling function?
I believe I will have to disable this beans and manage this interrupts manually.
Please let me know, thanks.

Outcomes