I am writing a program in C for PIC32 uC , that have a global variable(uint32_t type) that can be read/modified from multiple Interrupt Service Routines and from the main.
I know that is not safe so I was wondering how to make it safe ? Is there an example that show how to make it safe ?
Edit 1:
Can interrupts interrupt each other? yes
Does the ISR update the variable? yes
Does main update the variable? yes
Are writes and reads to the variable atomic and how do you know? Not sure
Is there a RTOS present? No
If you really need to keep global variables that can be modified during the servicing of several interrupts that can interrupt each other, I suggest you following way to do: