gonzui


Format: Advanced Search

mtkernel_3/kernel/tkernel/task.hbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.00
    4:  *
    5:  *    Copyright (C) 2006-2019 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.1.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2019/12/11.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      task.h
   16:  *      Task Definition
   17:  */
   18: 
   19: #ifndef _TASK_
   20: #define _TASK_
   21: 
   22: /*
   23:  * Internal expression of task state
   24:  *      Can check with 'state & TS_WAIT' whether the task is in the wait state.
   25:  *      Can check with 'state & TS_SUSPEND' whether the task is in the forced 
   26:  *      wait state.
   27:  */
   28: typedef enum {
   29:         TS_NONEXIST    = 0,       /* Unregistered state */
   30:         TS_READY       = 1,  /* RUN or READY state */
   31:         TS_WAIT                = 2,  /* WAIT state */
   32:         TS_SUSPEND     = 4,        /* SUSPEND state */
   33:         TS_WAITSUS     = 6,        /* Both WAIT and SUSPEND state */
   34:         TS_DORMANT     = 8 /* DORMANT state */
   35: } TSTAT;
   36: 
   37: /*
   38:  * If the task is alive ( except NON-EXISTENT,DORMANT ), return TRUE.
   39:  */
   40: Inline BOOL knl_task_alive( TSTAT state )
   41: {
   42:         return ( (state & (TS_READY|TS_WAIT|TS_SUSPEND)) != 0 );
   43: }
   44: 
   45: 
   46: /*
   47:  * Task priority internal/external expression conversion macro
   48:  */
   49: #define int_priority(x)         ( (INT)((x) - MIN_TSKPRI) )
   50: #define ext_tskpri(x)           ( (PRI)((x) + MIN_TSKPRI) )
   51: 
   52: 
   53: /*
   54:  * Task control information
   55:  */
   56: IMPORT TCB      knl_tcb_table[];     /* Task control block */
   57: IMPORT QUEUE    knl_free_tcb;      /* FreeQue */
   58: 
   59: /*
   60:  * Get TCB from task ID.
   61:  */
   62: #define get_tcb(id)             ( &knl_tcb_table[INDEX_TSK(id)] )
   63: #define get_tcb_self(id)        ( ( (id) == TSK_SELF )? knl_ctxtsk: get_tcb(id) )
   64: 
   65: /*
   66:  * Prepare task execution.
   67:  */
   68: IMPORT void knl_make_dormant( TCB *tcb );
   69: 
   70: /*
   71:  * Make task executable.
   72:  *      If the 'tcb' task priority is higher than the executed task,
   73:  *      make it executable. If the priority is lower, connect the task to the 
   74:  *      ready queue.
   75:  */
   76: IMPORT void knl_make_ready( TCB *tcb );
   77: 
   78: /*
   79:  * Make task non-executable.
   80:  *      Change the 'tcb' task state to be a non-executable state (wait state, 
   81:  *      forced wait, or dormant state). When calling this function, the
   82:  *      task must be executable. Change 'tcb->state' on the caller side
   83:  *      after returning from this function.
   84:  */
   85: IMPORT void knl_make_non_ready( TCB *tcb );
   86: 
   87: /*
   88:  * Change task priority.
   89:  *      Change 'tcb' task priority to 'priority'.
   90:  *      Then make the required task state transition occur.
   91:  */
   92: IMPORT void knl_change_task_priority( TCB *tcb, INT priority );
   93: 
   94: /*
   95:  * Rotate ready queue.
   96:  *      'rotate_ready_queue' rotates the priority ready queue at 'priority'.
   97:  *      'rotate_ready_queue_run' rotates the ready queue including the highest 
   98:  *      priority task in the ready queue.
   99:  */
  100: IMPORT void knl_rotate_ready_queue( INT priority );
  101: IMPORT void knl_rotate_ready_queue_run( void );
  102: 
  103: 
  104: #include "ready_queue.h"
  105: 
  106: /*
  107:  * Reselect task to execute
  108:  *      Set 'schedtsk' to the head task at the ready queue.
  109:  */
  110: Inline void knl_reschedule( void )
  111: {
  112:         TCB    *toptsk;
  113: 
  114:         toptsk = knl_ready_queue_top(&knl_ready_queue);
  115:         if ( knl_schedtsk != toptsk ) {
  116:                 knl_schedtsk = toptsk;
  117:         }
  118: }
  119: 
  120: #endif /* _TASK_ */