Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Variable accessible by ISR and Main code

Variable accessible by ISR and Main code

Anonymous
Not applicable
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.

 

Answer:

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.


0 Likes
160 Views
Contributors