/* * Main */ int main(void) { init_tlb(); enable_tlb(); printf("Hello from Nios II!\n"); mutex = altera_avalon_mutex_open(MUTEX_0_NAME); // Initialize the hardware mutex mbox = OSSemCreate(0); // Initialize the message box CriticalFunctionPointers* cp = (CriticalFunctionPointers*)SHARED_MEMORY_BASE; // Wait for monitor to be done initialization of shared variables before retrieving their values while(cp->init_complete == 0); init_cpu1_isr(); // Initialize the ISR // Set the task(only one in this example) int arg_5 = CRITICAL_TASK_PRIORITY; OSTaskCreateExt(preemption_task, &arg_5, &critical_task_stk[TASK_STACKSIZE - 1], CRITICAL_TASK_PRIORITY, CRITICAL_TASK_PRIORITY, critical_task_stk, TASK_STACKSIZE, NULL,0); // Signal that the core has finished initializing altera_avalon_mutex_lock(mutex, 1); // Acquire the hardware mutex { cp->core_ready[1] = 1; } altera_avalon_mutex_unlock(mutex); // Memory // Start OS OSStart(); return 0; }
int main() { printf("Hello from cpu_3!\n"); alt_mutex_dev* mutex = altera_avalon_mutex_open( "/dev/mutex_1" ); while(TRUE) { altera_avalon_mutex_lock( mutex, 1 ); if (IORD_8DIRECT(FLAG,0) == 1) { value=IORD_8DIRECT(VALUE,0); printf("Reading from shared memory (safe): %d\n",value); IOWR_8DIRECT(VALUE,0,++value); IOWR_8DIRECT(FLAG,0,0); printf("\tWriting to shared memory (safe): %d\n",value); } altera_avalon_mutex_unlock( mutex ); delay(10); } return 0; }