I am trying to build a simple video game for a university course using altera DE0 or DE2 or DE1-SoC boards, i looked at the isa for the nios II cpu there is no atomic test-and-set instruction in the ISA. how would i build a simple lock here, anything that enforces mutual exclusion for a tiny period will work.
we are gonna have code that is gonna run from
main() and code that will run in the Interrupt Service Routine, and i want to put locks on some variables, is it possible?
It appears the Nios II architecture doesn't have atomic test-and-set instructions. Instead for synchronization of shared resources between multiple Nios II processors, the architecture uses an "Hardware Mutex Core". It works as a shared peripheral that provides an atomic test-and-test operation. You can read more about it in Altera's Creating Multiprocessor Nios II Systems Tutorial.
However, you probably don't an atomic test-and-set operation. You can make any sequence of instructions atomic with respect to interrupts on a single core system simply by disabling interrupts.