Variable accessible by ISR and Main code

Version 1
    Question: How can a variable that can be accessed by both the idle loop ( in TD_Poll ) and also by a USB ISR be implemented such that, if it is being accessed by TD_Poll, ISR is not able to manipulate it until TD_Poll finishes and vice-versa.



    There are many different code styles which might accomplish this protection.

    1.You could disable global interrupts (EA) for the protected area in TD_Poll and re-enable them afterward.You would not loose interrupts that arrive during that period, they would be queued during that period.

    2.Another, you may decide not to clear the specific ISR until after the protected area in TD_Poll.It is best to keep use of ISRs to a minimum and make life a little more simple.