We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm writing a library to set a Port BIT , that can be used on ARTX for xc167 . I use a function with parameters "PortAddr" and "PortBit" :
*(PortAddr) |= ( 1<<PortBit );
and analog function for Clear the bit . This function is translated to (pseudo)Assembler :
MOV R4,PortState OR R4,bit MOV PortState,R4
When an interrupt access to the same port ( to set or clear a bit ) , and the interruption is before or after OR operation , I have an error because the the final value of the port is not correct .
I would like to use a solution that use the single instruction BSET and BCLR ( like compiled for direct set or clear ) , but I dont' find a good solution . The only one I find out is to insert a "switch ... case" , but it's not the better I think .
I hope someone have a good solution for me . Thank You
You could wrap the sequence within an atomic.
MOV R6,#0x01 SHL R6,R9 ATOMIC #3 MOV R4,[R8] OR R4,R6 MOV [R8],R4
I have not so much experience with Assembler , but finally I used Your suggestion , and now my system work fine .
Thank You very much