예제 #1
0
int8_t nrk_wait (nrk_time_t t)
{
  uint8_t timer;
  uint16_t nw;

  nrk_stack_check ();

  nrk_int_disable ();
  nrk_cur_task_TCB->suspend_flag = 1;
  nrk_cur_task_TCB->num_periods = 1;
  timer = _nrk_os_timer_get ();

//printf( "t1 %lu %lu\n",t.secs, t.nano_secs/NANOS_PER_MS);
  nw = _nrk_time_to_ticks (t);
//printf( "t2 %u\n",nw );
  nrk_cur_task_TCB->next_wakeup = nw + timer;
//printf( "wu %u\n",nrk_cur_task_TCB->next_wakeup );
  if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD))
    if ((timer + TIME_PAD) <= _nrk_get_next_wakeup ()) {
      timer += TIME_PAD;
      _nrk_prev_timer_val = timer;
      _nrk_set_next_wakeup (timer);
    }
  nrk_int_enable ();

  _nrk_wait_for_scheduler ();
  return NRK_OK;
}
예제 #2
0
파일: nrk_task.c 프로젝트: prashar/nanork
int8_t nrk_wait_until_next_period() {
	uint8_t timer;

	nrk_stack_check();
	// Next Period Wakeup Time is Set inside scheduler when a task becomes Runnable
	nrk_int_disable();
	nrk_cur_task_TCB->num_periods = 1;
	nrk_cur_task_TCB->suspend_flag = 1;
	timer = _nrk_os_timer_get();

	//nrk_cur_task_TCB->cpu_remaining=_nrk_prev_timer_val+1;

	if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD))
		if ((timer + TIME_PAD) <= _nrk_get_next_wakeup()) {
			timer += TIME_PAD;
			_nrk_prev_timer_val = timer;
			_nrk_set_next_wakeup(timer);
		}

	printf("Task %u finished in %u. \r\n",nrk_cur_task_TCB->task_ID,timer);

	nrk_int_enable();
	_nrk_wait_for_scheduler();
	return NRK_OK;
}
예제 #3
0
int8_t nrk_wait_until_next_n_periods (uint16_t p)
{
  uint8_t timer;

  nrk_stack_check ();

  if (p == 0)
    p = 1;
// Next Period Wakeup Time is Set inside scheduler when a task becomes Runnable 
  nrk_int_disable ();
  nrk_cur_task_TCB->suspend_flag = 1;
  nrk_cur_task_TCB->num_periods = p;
  timer = _nrk_os_timer_get ();

//nrk_cur_task_TCB->cpu_remaining=_nrk_prev_timer_val+1;

// +2 allows for potential time conflict resolution
  if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD))       // 254 8bit overflow point - 2
    if ((timer + TIME_PAD) <= _nrk_get_next_wakeup ()) {
      timer += TIME_PAD;
      _nrk_prev_timer_val = timer;
      _nrk_set_next_wakeup (timer);
    }

  nrk_int_enable ();
  _nrk_wait_for_scheduler ();
  return NRK_OK;
}
예제 #4
0
int8_t nrk_wait_until_next_period ()
{
    uint8_t timer;
	 //Abhijeet disabled this...	Haww
		//NVIC_EnableIRQ(TIMER0_IRQn);
		//NVIC_EnableIRQ(TIMER1_IRQn);
    //nrk_stack_check ();
// Next Period Wakeup Time is Set inside scheduler when a task becomes Runnable
    nrk_int_disable ();
    nrk_cur_task_TCB->num_periods = 1;
    nrk_cur_task_TCB->suspend_flag = 1;
    timer = _nrk_os_timer_get ();

//nrk_cur_task_TCB->cpu_remaining=_nrk_prev_timer_val+1;

    if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD)) // if(timer<(250-10))
        if ((timer + TIME_PAD) <= _nrk_get_next_wakeup ())
        {
            timer += TIME_PAD;
            _nrk_prev_timer_val = timer;                  // pdiener: why is this only set in this special case?
            _nrk_set_next_wakeup (timer);                 // pdiener: Set next wakeup to NOW...Ask Madhur and Abhijeet
        }

    nrk_int_enable ();
    _nrk_wait_for_scheduler ();
		//pc6.printf("should not come here");
    return NRK_OK;
}
예제 #5
0
파일: nrk_task.c 프로젝트: vishnudh/RTOS
int8_t nrk_wait_until_next_period ()
{
  uint16_t timer;

  nrk_stack_check ();
// Next Period Wakeup Time is Set inside scheduler when a task becomes Runnable // EXCEPT THIS CAUSES A FIRST-TIME-THROUGH BUG
  nrk_int_disable ();
  nrk_cur_task_TCB->num_periods = 1;
  nrk_cur_task_TCB->suspend_flag = 1;
  nrk_cur_task_TCB->next_wakeup = nrk_cur_task_TCB->next_period;
  timer = _nrk_os_timer_get ();

//nrk_cur_task_TCB->cpu_remaining=_nrk_prev_timer_val+1;

  if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD))
    if ((timer + TIME_PAD) <= _nrk_get_next_wakeup ()) {
      timer += TIME_PAD;
      _nrk_prev_timer_val = timer;
      _nrk_set_next_wakeup (timer);
    }

  nrk_int_enable ();
  _nrk_wait_for_scheduler ();
  return NRK_OK;
}
예제 #6
0
int8_t nrk_wait_until_next_period ()
{
    uint8_t timer;

    nrk_stack_check ();
// Next Period Wakeup Time is Set inside scheduler when a task becomes Runnable
    nrk_int_disable ();
    nrk_cur_task_TCB->num_periods = 1;
    nrk_cur_task_TCB->suspend_flag = 1;
    timer = _nrk_os_timer_get ();

//nrk_cur_task_TCB->cpu_remaining=_nrk_prev_timer_val+1;

    if (timer < (MAX_SCHED_WAKEUP_TIME - TIME_PAD))
        if ((timer + TIME_PAD) <= _nrk_get_next_wakeup ())
        {
            timer += TIME_PAD;
            _nrk_prev_timer_val = timer;                  // pdiener: why is this only set in this special case?
            _nrk_set_next_wakeup (timer);                 // pdiener: Set next wakeup to NOW
        }

    nrk_int_enable ();
    _nrk_wait_for_scheduler ();
    return NRK_OK;
}
예제 #7
0
파일: nrk_task.c 프로젝트: prashar/nanork
int8_t nrk_wait_until_nw() {
	uint8_t timer;
	nrk_int_disable();
	nrk_cur_task_TCB->suspend_flag = 1;
	nrk_cur_task_TCB->nw_flag = 1;
	timer = _nrk_os_timer_get();

	if (timer < MAX_SCHED_WAKEUP_TIME - TIME_PAD)
		if ((timer + TIME_PAD) <= _nrk_get_next_wakeup()) {
			timer += TIME_PAD;
			_nrk_prev_timer_val = timer;
			_nrk_set_next_wakeup(timer);
		}
	//else nrk_cur_task_TCB->next_wakeup=ticks+1;
	nrk_int_enable();
	//while(nrk_cur_task_TCB->suspend_flag==1);
	_nrk_wait_for_scheduler();
	return NRK_OK;
}
예제 #8
0
void nrk_idle_task()
{
volatile unsigned char *stkc;
// unsigned int *stk ;  // 2 bytes
while(1)
{

  nrk_stack_check(); 
  
  if(_nrk_get_next_wakeup()<=NRK_SLEEP_WAKEUP_TIME) 
    {
	    _nrk_cpu_state=1;
	    nrk_idle();
    }
    else {
	#ifndef NRK_NO_POWER_DOWN
	    // Allow last UART byte to get out
    	    nrk_spin_wait_us(10);  
	    _nrk_cpu_state=2;
	    nrk_sleep();
	#else
	    nrk_idle();
	#endif
    }
 
#ifdef NRK_STACK_CHECK
   if(nrk_idle_task_stk[0]!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH);
   #ifdef KERNEL_STK_ARRAY
   	if(nrk_kernel_stk[0]!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH);
   #else
   	stkc=(unsigned char*)(NRK_KERNEL_STK_TOP-NRK_KERNEL_STACKSIZE);
   	if(*stkc!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH);
   #endif
#endif



}


}