2024-03-27 03:34 AM - edited 2024-03-27 03:35 AM
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
#endasm
Enabling the interrupts
#asm
PUSH ISR_CC(1)
POP CC
#endasm
I 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;
}
Solved! Go to Solution.
2024-03-29 06:12 PM
I was using cosmic c compiler.
I did the following modifications for cosmic C and stvd.
uint8_t atomic_begin(void)
{
#asm
; Copy CC value, put in A reg for return value, and disable all interrupts.
push cc
pop a
sim
#endasm;
}
void atomic_end(const uint8_t istate) {
(void)istate;
#asm
; Restore CC from arg value in A reg.
push a
pop cc
#endasm;
}
//Usage is as follows
ISR()
{
uint8_t ISR_CC_ret = atomic_begin();
//execute your ISR
atomic_end(ISR_CC_ret);
}
2024-03-27 03:55 AM - edited 2024-03-27 03:56 AM
uint8_t atomic_begin(void) __naked {
__asm
; Copy CC value, put in A reg for return value, and disable all interrupts.
ld a,cc
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.
ld cc,a
push a
pop cc
__endasm;
}
@raja1 wrote: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
#endasm
Enabling the interrupts
#asm
PUSH ISR_CC(1)
POP CC
#endasm
I 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;
}
Does this make sense?
2024-03-29 06:12 PM
I was using cosmic c compiler.
I did the following modifications for cosmic C and stvd.
uint8_t atomic_begin(void)
{
#asm
; Copy CC value, put in A reg for return value, and disable all interrupts.
push cc
pop a
sim
#endasm;
}
void atomic_end(const uint8_t istate) {
(void)istate;
#asm
; Restore CC from arg value in A reg.
push a
pop cc
#endasm;
}
//Usage is as follows
ISR()
{
uint8_t ISR_CC_ret = atomic_begin();
//execute your ISR
atomic_end(ISR_CC_ret);
}