Altera_Forum
Honored Contributor
20 years agoSynchronizing between ISR and main code
Hello all,
What is the best way to ensure safe access to shared data between an ISR and the main code ? In my application, the ISR reads a packet from the FIFO of a custom UART and saves it in a buffer provided to it upon registration. It then asserts a "ready" flag on the data. The main code polls for this flag and processes the data when it's ready. How can I ensure that during the main code's processing the data the ISR won't jump again and override it ? It may cause corrupted data. Say the main code has read 5 out of 10 bytes and then the ISR has overwritten them. When the main code resumes it will read the remaining 5 bytes from the new message. Is disabling interrupts during the main's code reading of the data the best option ? What are the common guideline when dealing with data synchronization in ISRs for Nios ? Thanks in advance http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif