HCS08 global interrupt flag context save/restore

HCS08 global interrupt flag context save/restore

Post by Ether Jone » Sun, 17 Dec 2006 10:32:28


Does anyone know how to "push flags" on the HCS08 series
microcontrollers?

I have a section of code that I need to make non-interruptable. But I
can't simply do this:

DisableInterrupts
<non-interruptable code here>
EnableInterrupts

... because I don't know whether or not interrupts were disabled in the
first place, and if they were disabled, I don't want to enable them. I
want to leave things the way I found them.

In the Intel world, I'd just do this:

PUSHF (push flags)
DisableInterrupts
<non-interruptable code here>
POPF (pop flags, restoring whatever state existed before I disabled
interrupts)

I read all the docs I could find, but never saw this issue addressed.
It says that the "CCR" register contains the global interrupt flag, but
there's no assembly instruction to read it or push it unto the stack.

Does anyone have a solution for this?
 
 
 

HCS08 global interrupt flag context save/restore

Post by Stephen Pi » Wed, 20 Dec 2006 18:50:58

Transfer the CCR to the accumulator and push the accumulator, pop and
restore, eg:

TPA ;save CCR
PSHA
DisableInterrupts
<non-interruptable code here>
EnableInterrupts
PULA
TAP ;restore CCR

If you need to preserve A just add appropriate psha & pula.

 
 
 

HCS08 global interrupt flag context save/restore

Post by Ether Jone » Thu, 21 Dec 2006 05:28:18


Thank you.

I think the "EnableInterrupts" in the code above is unnecessary (and
undesirable, since the original goal was to NOT enable interrupts if
they were already disabled when this code sequence executed). When
you PULA and TAP, it will restore the CCR to what is was upon entry, be
that enabled or disabled.