Example #1
0
File: OS.c Project: tach4455/EE345M
// ******** OS_Suspend ************
// suspend execution of currently running thread
// scheduler will choose another thread to execute
// Can be used to implement cooperative multitasking
// Same function as OS_Sleep(0)
// input:  none
// output: none
void OS_Suspend(void) {

  long curPriority;
  unsigned long curTimeSlice;
  volatile int i;

  OS_DisableInterrupts();

  // Determines NextPt
  Scheduler();

  // Get priority of next thread and calculate timeslice
  curPriority = (*NextPt).priority;
  curTimeSlice = calcTimeSlice(curPriority);

  // Sets next systick period, does not rest counting
  SysTickPeriodSet(curTimeSlice);

  // Write to register forces systick to reset counting
  NVIC_ST_CURRENT_R = 0;

  IntPendSet(FAULT_PENDSV);
  OS_EnableInterrupts();

  return;
}
Example #2
0
/**
 \brief Schedule the callback to be called in some specified time.

 The delay is expressed relative to the last compare event. It doesn't matter
 how long it took to call this function after the last compare, the timer will
 expire precisely delayTicks after the last one.

 The only possible problem is that it took so long to call this function that
 the delay specified is shorter than the time already elapsed since the last
 compare. In that case, this function triggers the interrupt to fire right away.

 This means that the interrupt may fire a bit off, but this inaccuracy does not
 propagate to subsequent timers.

 \param delayTicks Number of ticks before the timer expired, relative to the
 last compare event.
 */
void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks) {
	PORT_TIMER_WIDTH newCompareValue, current;
	PORT_TIMER_WIDTH temp_last_compare_value;

	if (!bsp_timer_vars.initiated){
		//as the timer runs forever the first time it is turned on has a weired value
		bsp_timer_vars.last_compare_value=SleepModeTimerCountGet();
		bsp_timer_vars.initiated=true;
	}

	temp_last_compare_value = bsp_timer_vars.last_compare_value;

	newCompareValue = bsp_timer_vars.last_compare_value + delayTicks + 1;
	bsp_timer_vars.last_compare_value = newCompareValue;

	current = SleepModeTimerCountGet();

	if (delayTicks < current - temp_last_compare_value) {

		// we're already too late, schedule the ISR right now manually
		// setting the interrupt flag triggers an interrupt
		bsp_timer_vars.tooclose++;
		bsp_timer_vars.diff=(current - temp_last_compare_value);
		bsp_timer_vars.last_compare_value = current;
		IntPendSet(INT_SMTIM);
	} else {
		// this is the normal case, have timer expire at newCompareValue
		SleepModeTimerCompareSet(newCompareValue);
	}
	//enable interrupt
	IntEnable(INT_SMTIM);
}
Example #3
0
void    RunBulk3(void)
{
#ifdef ENABLE_BULK
  if (BulkEnabled())
  {
    if (cwBulkDelay[3] == 0)
    {
      mpSerial[3] = mpSerial_Bulk[3];
      IntPendSet(INT_UART4);
    }
    else cwBulkDelay[3]--;
  }
#endif
}