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

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

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

Jump to solution
3,301 Views
shadoooo
Contributor I
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.

Labels (1)
Tags (1)
0 Kudos
1 Solution
1,079 Views
Phoenix
Contributor III
Unfortunatelly there is no patch for PE version 2.99 now.  Here is suggestion from PE developers:

Hoever, the problem can be easily workarounded. There are two ways:

A) Couldn't the user use the high-level bean KBI? This bean offers most features as the Init_KBI and moreover it automatically handles the flags so the user just writes en event code. (But please note that the KBI bean cannot be used together with Init_KBI).

B) If the user needs to use Init_KBI and ISR "Inter1" :

1) Open Processor Expert options using the menu command "ProcessorExpert -> Options -> Project options" and set Generate ISR = no.

2) Check if there is any bean in the project that has at least one event enabled. If it's not, enable some event in the CPU bean (e.g. OnReset)

3) In the file "Events.c" rewrite the definition "ISR(Inter1)" to "void

Inter1(void)" or create a new function with this name.

4) In the file "Events.h" rewrite the declaration "__interrupt void

Inter1(void);" to "void Inter1(void);" or create the new declaration.

------------------------

Please let me know the ServiceRequest number of your problems with v6.0 (because in version 6.0 this bug is fixed)

 

View solution in original post

0 Kudos
11 Replies
1,079 Views
Phoenix
Contributor III
Why is the InterruptButtons function defined as ISR? It is the mistake I think.. the interrupt is handled by ISR (CPU_ivVport) and any function called from there is not ISR more!
 
Phoenix


Message Edited by Phoenix on 2007-07-30 10:06 AM
0 Kudos
1,079 Views
shadoooo
Contributor I
This IS the problem, indeed. But this fuction definition is not my choice. The bug in the beans defines the fuctions for you, so you can easily fill in you code.
This works good if you are using a single bean, because it is calling directly for the IRQ vector the user function, defined as __interrupt.
If you use two beans together, the user function remains the same (still defined __interrupt), but the vector table filled-in by the beans calls the intermediate IRQ function, that is calling the wrongly defined user function.
I would prefer that the beans always calls the __interrupt user defined function with no intermediate routines,
so the user can also manage the flags by itself.

The workaround for this behaviour for me is to generate code using PE, then disabling the bugged beans and modifiy the code by hand. But of course the beans has to been fixed!
0 Kudos
1,079 Views
Phoenix
Contributor III
OK, sorry my mistake - I have turned off ISR generation.
I check it and you are right, in case of one KBI everything is fine but in case of two there is one ISR more.
I chekced it in CW for microcontrolers v6.0 and the bug is fixed there (there is no CPU-ivVport function implemented so you have to handle the the interupt flags self. I will check PE website for patch for 5.1 but if you can try to use v6.0.
0 Kudos
1,079 Views
shadoooo
Contributor I
This is another story...
As far as we started this new project with HCS08 two weeks ago, I tried to install CW6.
I had to switch to CW5.1 because of some problem with the installer that let hang my machine
just after the files are fully copied to the HD. It seems that it tries to register some component...
I already contacted Freescale support, we did some test but no lunk to understand what the problem is, so temporarily I switched to CW5.1...
I hope there's a patch for it...
0 Kudos
1,079 Views
Phoenix
Contributor III
Update: I contacted PE developers. I will inform you just when receive answer from them.
0 Kudos
1,079 Views
shadoooo
Contributor I
thanks
0 Kudos
1,080 Views
Phoenix
Contributor III
Unfortunatelly there is no patch for PE version 2.99 now.  Here is suggestion from PE developers:

Hoever, the problem can be easily workarounded. There are two ways:

A) Couldn't the user use the high-level bean KBI? This bean offers most features as the Init_KBI and moreover it automatically handles the flags so the user just writes en event code. (But please note that the KBI bean cannot be used together with Init_KBI).

B) If the user needs to use Init_KBI and ISR "Inter1" :

1) Open Processor Expert options using the menu command "ProcessorExpert -> Options -> Project options" and set Generate ISR = no.

2) Check if there is any bean in the project that has at least one event enabled. If it's not, enable some event in the CPU bean (e.g. OnReset)

3) In the file "Events.c" rewrite the definition "ISR(Inter1)" to "void

Inter1(void)" or create a new function with this name.

4) In the file "Events.h" rewrite the declaration "__interrupt void

Inter1(void);" to "void Inter1(void);" or create the new declaration.

------------------------

Please let me know the ServiceRequest number of your problems with v6.0 (because in version 6.0 this bug is fixed)

 

0 Kudos
1,079 Views
shadoooo
Contributor I
any new for a patch for PE?
0 Kudos
1,079 Views
Phoenix
Contributor III
Unfortunatelly as this bug is fixed in current version and workarround exists the patch is not released.
 
Please let me know the SR number you obtained for the problem with CW6.0 - I will investigate it and we can try to find final solution for you.
0 Kudos
1,079 Views
shadoooo
Contributor I
1-374566021
0 Kudos
1,079 Views
shadoooo
Contributor I
New info:

I tried to add the two beans, generate code and then suspend PE and edit lines in the Events.c and Events.h
declaring the Interrupt_Buttons no more as __interrupt, but as standars function. In this way it ends using RTS instead RTI, and indeed it works!
So the question is, what is the right way to manage this IRQs?
1) PE requires to have the same handling function for the two beans, but in this case there's no need to generate the intermediate function in Cpu.c, All the code is managed by the user (best way I think).
2) PE creates the intermediate function in Cpu.h, but in this case the handling functions can be also different
for different beans, and they have to be declared as standard functions...
Let me know, I'm waiting for a fix on PE.
Thanks
 

0 Kudos