Code:
typedef volatile union eventTag
...
check.all = event.all; // a IRQ could happen between
event.all &= ~check.all; // atomic way to clear it
compiles in to and is safe but compiler complains:
undefined behavior: the order of volatile accesses is undefined in this statement
Code:
mov.w &event,&check
mov.w &check,R15
bic.w R15,&event
if I leave out the volatile and in medium or high optimization
no warnings but if a IRQ sets a event flag between these two lines it will be lost
Code:
mov.w &event,&check
clr.w &event
is the only solution: Make it a function with pragma no optimization?
As I don't feel turning off and on GIE
update: if I tell it to use a temp register it works with volatile and no warnings
Code:
unsigned int temp = event.all;
check.all = temp;
event.all &= ~temp; // atomic way to clear it
mov.w &event,R15 // result is safe atomic-copy-and-clear
mov.w R15,&check // even if a IRQ happens R15 is always restored
bic.w R15,&event