How to enable and disable a maskable interrupt from inside an ISR in stm8A
Hello all.
I have an ISR inside which I want to disable and enable interrupts.
Reference manual says :
Disabling the interrupts
#asm
PUSH CC
POP ISR_CC(1)
SIM
#endasmEnabling the interrupts
#asm
PUSH ISR_CC(1)
POP CC
#endasmI want to achieve mutual exclusion. I have tried using sim and rim and it works for now.
However the above method got me confused.
What do I do for POP ISR_CC ?
Please suggest me exact ways.
I have found this inside a blog. Is it correct?
uint8_t atomic_begin(void) __naked {
__asm
; Copy CC value, put in A reg for return value, and disable all interrupts.
push cc
pop a
sim
ret
__endasm;
}
void atomic_end(const uint8_t istate) {
(void)istate;
__asm
; Restore CC from arg value in A reg.
push a
pop cc
__endasm;
}