예제 #1
0
void rt_block (U16 timeout, U8 block_state) {
  /* Block running task and choose next ready task.                         */
  /* "timeout" sets a time-out value or is 0xffff (=no time-out).           */
  /* "block_state" defines the appropriate task state */
  P_TCB next_TCB;

  if (timeout) {
    if (timeout < 0xffff) {
      rt_put_dly (os_tsk.run, timeout);
    }
    os_tsk.run->state = block_state;
    next_TCB = rt_get_first (&os_rdy);
    rt_switch_req (next_TCB);
  }
}
예제 #2
0
void rt_systick (void) {
  /* Check for system clock update, suspend running task. */
  P_TCB next;

  os_tsk.run->state = READY;
  rt_put_rdy_first (os_tsk.run);

  /* Check Round Robin timeout. */
  rt_chk_robin ();

  /* Update delays. */
  os_time++;
  rt_dec_dly ();

  /* Check the user timers. */
  rt_tmr_tick ();

  /* Switch back to highest ready task */
  next = rt_get_first (&os_rdy);
  rt_switch_req (next);
}
예제 #3
0
파일: rt_Task.c 프로젝트: DanKupiniak/mbed
void rt_sys_init (void) {
#else
void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk) {
#endif
  /* Initialize system and start up task declared with "first_task". */
  U32 i;

  DBG_INIT();

  /* Initialize dynamic memory and task TCB pointers to NULL. */
  for (i = 0U; i < os_maxtaskrun; i++) {
    os_active_TCB[i] = NULL;
  }
  rt_init_box (mp_tcb, (U32)mp_tcb_size, sizeof(struct OS_TCB));
  rt_init_box (mp_stk, mp_stk_size, BOX_ALIGN_8 | (U16)(os_stackinfo));
  rt_init_box ((U32 *)m_tmr, (U32)mp_tmr_size, sizeof(struct OS_TMR));

  /* Set up TCB of idle demon */
  os_idle_TCB.task_id    = 255U;
  os_idle_TCB.priv_stack = 0U;
  rt_init_context (&os_idle_TCB, 0U, os_idle_demon);

  /* Set up ready list: initially empty */
  os_rdy.cb_type = HCB;
  os_rdy.p_lnk   = NULL;
  /* Set up delay list: initially empty */
  os_dly.cb_type = HCB;
  os_dly.p_dlnk  = NULL;
  os_dly.p_blnk  = NULL;
  os_dly.delta_time = 0U;

  /* Fix SP and system variables to assume idle task is running */
  /* Transform main program into idle task by assuming idle TCB */
#ifndef __CMSIS_RTOS
  rt_set_PSP (os_idle_TCB.tsk_stack+32U);
#endif
  os_tsk.run = &os_idle_TCB;
  os_tsk.run->state = RUNNING;

  /* Set the current thread to idle, so that on exit from this SVCall we do not
   * de-reference a NULL TCB. */
  rt_switch_req(&os_idle_TCB);

  /* Initialize ps queue */
  os_psq->first = 0U;
  os_psq->last  = 0U;
  os_psq->size  = os_fifo_size;

  rt_init_robin ();

#ifndef __CMSIS_RTOS
  /* Initialize SVC and PendSV */
  rt_svc_init ();

  /* Initialize and start system clock timer */
  os_tick_irqn = os_tick_init ();
  if (os_tick_irqn >= 0) {
    OS_X_INIT((U32)os_tick_irqn);
  }

  /* Start up first user task before entering the endless loop */
  rt_tsk_create (first_task, prio_stksz, stk, NULL);
#endif
}