SMAC /  Interrupts scrambling Passed Variables

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

SMAC /  Interrupts scrambling Passed Variables

2,305 Views
mjcoury
Contributor I
It appears that the interrupts in the SMAC are scrambling the values of passed variabled.  This of course is a problem - anyone seen this before and have a fix for it?  I assumed that the codewarrior / SMAC demo code had provisions to safely store the register during an interrupt?


Thoughts?

Thanks

Mike
Labels (1)
0 Kudos
Reply
6 Replies

905 Views
mjcoury
Contributor I
Anyone? Bueler? Anyone?
0 Kudos
Reply

905 Views
Alban
Senior Contributor II
Hello,

You cannot PASS a variable to an interrupt on HC08 and S08.
Interrupts are declared as "void JojoISR(void)".

If content of CPU registers are not saved properly, check the compiler parameters (go into Edit -> TargetName... -> Compiler)

Regards,
Alban.

0 Kudos
Reply

905 Views
mjcoury
Contributor I
You mis understand - I am passing variables between normal functions, but when an interrupt is fired before the function is called, the passed value that is stored in the HX register is lost forever and is replaced by Junk that was used during the interrupt...
0 Kudos
Reply

905 Views
CrasyCat
Specialist III
Hello
 
Are you programming in ANSI C or in Assembler?
 
Normally when an interrupt occurs, the hardware is saving register A,  X, SR, PC on the stack.
Register H is not saved automatically by the hardware.
 
If you are programming in assembler you need to save H on the stack at the beginning of the interrupt (instruction PSHH) and restore it at the end of the interrupt(instruction PULH).
 
If you are programming in ANSI C then it depends on the compiler you are using.
CodeWarrior compiler is automatically taking care of saving/restoring the register H is you define your interrupt function using interrupt keyword.
 
For Example:
interrupt void intFunc(void) {
 
For other compiler, please check your compiler vendor manual to check whether and how you can make sure register H is saved/ restored in interrupt functions.
 
I hope this helps.
 
CrasyCat
0 Kudos
Reply

905 Views
Alban
Senior Contributor II
Hi CrasyCat,

Funny, I had the same trouble on S12XE with the GPAGE register.
I think you can also put a #pragma SAVE_ALL_REGS before the ISR code. That worked for me.

But on CW HC08 and S08, the PUSHH is systematically done by CW, even if HX is not used in the ISR :smileyhappy:

Cheers,
Alban.
0 Kudos
Reply

905 Views
mjcoury
Contributor I
Crasy -

I am programming in Codewarrior version 3.0...


and all i know is that while I am using the Real Time Debugger - for some, not all, instances of passing variables... if there is a interrupt called, specifically ones related to SMAC / Zigbee interactions, when the code returns to the step before the JSR in the assembly the values in the Registers are not correct and after the JSR those incorrect values in the register are what end up getting passed / manipulated in my function... my only work around at those point is to use some nasty globals to store the values elsewhere during the JSR / Interrupt period....
0 Kudos
Reply