Altera_Forum
Honored Contributor
15 years agoMutex - uClinux (without mmu)
Hi
I have a project thar includes 2 NIOS2 CPUs. Both need to access the same memory area in an SRAM. One of the CPUs runs software developed with the NIOS2 IDE, another runs uClinux. To control access to SRAM, I tried to use a mutex (altera_avalon_mutex). In the CPU that runs the NIOS2 IDE software, I used altera_avalon_mutex_open, altera_avalon_mutex_lock and altera_avalon_mutex_unlock functions. Since I have no access to these functions in uClinux, I develop my own lock and unlock functions based on mutex documentation (Altera) and the mutex source code. The uClinux CPU has cpuid = 0, and the mutex address is 0x00000000. Below is my implementation of the functions lock and unlock.void lock(void)
{
do
{
outl(0x00000001, 0x00000000); // CPUID = 0, VALUE = 1 at address 0x00000000 (register "mutex")
}
while (inl(0x00000000) != 0x00000001); // register "mutex" must have the written value to lock.
}
void unlock(void)
{
outl(0x00000001, 0x00000001); // register "reset", RESET = 1
outl(0x00000000, 0x00000000); // register "mutex", CPUID = 0, VALUE = 1
} The implementation of mutex in uClinux not worked, it means that both CPUs had accessed memory at same time. Is my implementation correct? Can anyone please help me? Thanks