Beispiel #1
0
/*
 * 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;
}
IMPLEMENTATION [mp]:

#include <cstdlib>
#include <cstdio>

#include "config.h"
#include "delayloop.h"
#include "fpu.h"
#include "globals.h"
#include "helping_lock.h"
#include "kernel_task.h"
#include "processor.h"
#include "scheduler.h"
#include "task.h"
#include "thread.h"
#include "thread_state.h"
#include "timer.h"
#include "timer_tick.h"
#include "spin_lock.h"

PUBLIC static
Kernel_thread *
App_cpu_thread::may_be_create(Cpu_number cpu, bool cpu_never_seen_before)
{
  if (!cpu_never_seen_before)
    {
      kernel_context(cpu)->reset_kernel_sp();
      return static_cast<Kernel_thread *>(kernel_context(cpu));
    }

  Kernel_thread *t = new (Ram_quota::root) App_cpu_thread;
  assert (t);

  set_cpu_of(t, cpu);
  check(t->bind(Kernel_task::kernel_task(), User<Utcb>::Ptr(0)));
  return t;
}


// the kernel bootstrap routine
IMPLEMENT
void
App_cpu_thread::bootstrap()
{
  extern Spin_lock<Mword> _tramp_mp_spinlock;

  state_change_dirty(0, Thread_ready);		// Set myself ready


  Fpu::init(cpu(true));

  // initialize the current_mem_space function to point to the kernel space
  Kernel_task::kernel_task()->make_current();

  Mem_unit::tlb_flush();

  Cpu::cpus.current().set_online(1);

  _tramp_mp_spinlock.set(1);

  kernel_context(cpu(true), this);
  Sched_context::rq.current().set_idle(this->sched());
  Rcu::leave_idle(cpu(true));

  Timer_tick::setup(cpu(true));
  Timer_tick::enable(cpu(true));
  enable_tlb(cpu(true));
  // Setup initial timeslice
  Sched_context::rq.current().set_current_sched(sched());

  Per_cpu_data::run_late_ctors(cpu(true));

  Scheduler::scheduler.trigger_hotplug_event();

  cpu_lock.clear();

  printf("CPU[%u]: goes to idle loop\n", cxx::int_value<Cpu_number>(cpu(true)));

  for (;;)
    idle_op();
}