Forum Discussion
Altera_Forum
Honored Contributor
20 years agoDon't forget to specify variables as "volatile" to prevent them being optimised out.
Sometimes I do tricks such as implementing S/R Flip Flops or counters in hardware, with different memory addresses to set/reset increment/decrement/read them. For simple FIFO buffers I'll do e.g. "ISR owns write pointer", "main thread owns read pointer" as Scott says. I will also use a "main thread is using this" flag as you've suggested. So//shared
volatile int MT_Access;
//main thread
MT_Access = 1;
<do something>
MT_Access = 0;
//ISR
if (0 == MT_Access)
{
<update something>
}