Esempio n. 1
0
File: os.c Progetto: ismaellc/SOTR
//******** OS_AddThread ***************
// add three foregound threads to the scheduler
// Inputs: three pointers to a void/void foreground tasks
// Outputs: 1 if successful, 0 if this thread can not be added
int OS_AddThreads(void(*task0)(void),
                 void(*task1)(void),
                 void(*task2)(void)){ int32_t status;
  status = StartCritical();
  tcbs[0].next = &tcbs[1]; // 0 points to 1
  tcbs[1].next = &tcbs[2]; // 1 points to 2
  tcbs[2].next = &tcbs[0]; // 2 points to 0
  SetInitialStack(0); Stacks[0][STACKSIZE-2] = (int32_t)(task0); // PC
  SetInitialStack(1); Stacks[1][STACKSIZE-2] = (int32_t)(task1); // PC
  SetInitialStack(2); Stacks[2][STACKSIZE-2] = (int32_t)(task2); // PC
  RunPt = &tcbs[0];       // thread 0 will run first
  EndCritical(status);
  return 1;               // successful
}
Esempio n. 2
0
int OS_AddThread(void(*task)(void), unsigned long stackSize, unsigned long priority)
{
	uint32_t status;
	status = OS_StartCritical();
	//we will take the first thread from the dead pool
	if(DeadPt == '\0')
	{
		OS_DisableInterrupts();
		while(1){}
	}
	(DeadPt)->id = uniqueId; //unique id
	(DeadPt)->active = 1;
	(DeadPt)->sleepState = 0; //flag
	(DeadPt)->priority = priority; 
	(DeadPt)->blockedState = 0; //flag
	(DeadPt)->needToWakeUp = 0; //flag
	SetInitialStack(DeadPt, stackSize);
	(DeadPt)->stack[stackSize - 2] = (uint32_t)task; //push PC
	uniqueId++;
	addDeadToScheduler(&DeadPt);
	if(higherPriorityAdded == 1)
	{
		OS_Suspend();
	}
	OS_EndCritical(status);
	
	return 1;
}
Esempio n. 3
0
File: OS.c Progetto: c0lin91/EE445M
// -------------------------- OS_AddThread ---------------------------
int OS_AddThread(void(*task)(void), unsigned long stackSize, unsigned long priority){
  long status;
	int i = 0;
	
  status = StartCritical();
  
	while((thread[i].id != 0) && (i < NUMTHREADS)){
		i++;
	};
	
	if (thread[i].id != 0){
		EndCritical(status);
		return 0;
	}
	
	SetInitialStack(i, task);
	thread[i].id = i + 1;
	thread[i].priority = priority;
	thread[i].blockSt = 0;
	thread[i].sleepSt = 0;
	
	linkTCB(&Actives, &thread[i]);
	
  EndCritical(status);
  return 1;   //successfully added thread
}
Esempio n. 4
0
int task_create(void *setup_ptr) {
  int32_t i = 0, n = 0;
  int32_t *ptr = (int32_t *)setup_ptr;
  TASK_STRUCT *task = (TASK_STRUCT *)(*ptr);        // register r0
  int32_t numOftask = *((int32_t *)setup_ptr + 1);  // register r1
  // TASK_STRUCT task;
  TCB *TCBList = &OS_TCB[0];

  for (i = 0; i < numOftask; i++) {
    SetInitialStack(i);
    // save func value in both PC and LR Registers Initially
    STACK[i][STACK_SIZE - 2] = (int32_t)((task[i].func));
    STACK[i][STACK_SIZE - 3] = (int32_t)((task[i].func));
    TCBList[i].priority = task[i].priority;
    TCBList[i].C = task[i].C;
    TCBList[i].T = task[i].T;
    TCBList[i].next = &TCBList[i + 1];
  }
  RUNQ = &TCBList[0];
  // make run queue circular by going to last
  // valid task block and setting next to RUNQ
  TCBList[i - 1].next = RUNQ;
  return 0;
}