gonzui


Format: Advanced Search

tkernel_2/kernel/tkernel/src/task.hbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2012/10/24.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      task.h (T-Kernel/OS)
   18:  *      Task Definition
   19:  */
   20: 
   21: #ifndef _TASK_
   22: #define _TASK_
   23: 
   24: #ifndef __mtxcb__
   25: #define __mtxcb__
   26: typedef struct mutex_control_block      MTXCB;
   27: #endif
   28: 
   29: #ifndef __tcb__
   30: #define __tcb__
   31: typedef struct task_control_block       TCB;
   32: #endif
   33: 
   34: #include <sys/queue.h>
   35: #include <sys/str_align.h>
   36: #include "timer.h"
   37: #include "winfo.h"
   38: 
   39: /*
   40:  * Internal expression of task state
   41:  *      Can check with 'state & TS_WAIT' whether the task is in the wait state.
   42:  *      Can check with 'state & TS_SUSPEND' whether the task is in the forced
   43:  *      wait state.
   44:  */
   45: typedef enum {
   46:         TS_NONEXIST    = 0,       /* Unregistered state */
   47:         TS_READY       = 1,  /* RUN or READY state */
   48:         TS_WAIT                = 2,  /* WAIT state */
   49:         TS_SUSPEND     = 4,        /* SUSPEND state */
   50:         TS_WAITSUS     = 6,        /* Both WAIT and SUSPEND state */
   51:         TS_DORMANT     = 8 /* DORMANT state */
   52: } TSTAT;
   53: 
   54: /*
   55:  * If the task is alive ( except NON-EXISTENT,DORMANT ), return TRUE.
   56:  */
   57: Inline BOOL task_alive( TSTAT state )
   58: {
   59:         return ( (state & (TS_READY|TS_WAIT|TS_SUSPEND)) != 0 );
   60: }
   61: 
   62: /*
   63:  * Task priority internal/external expression conversion macro
   64:  */
   65: #define int_priority(x)         ( (INT)((x) - MIN_PRI) )
   66: #define ext_tskpri(x)           ( (PRI)((x) + MIN_PRI) )
   67: 
   68: /*
   69:  * Task control block (TCB)
   70:  */
   71: struct task_control_block {
   72:         QUEUE  tskque;          /* Task queue */
   73:         ID     tskid;              /* Task ID */
   74:         void   *exinf;           /* Extended information */
   75:         ATR    tskatr;            /* Task attribute */
   76:         FP     task;               /* Task startup address */
   77:         ID     resid;              /* Assigned resource group ID */
   78: 
   79:         INT    stksz;             /* User stack size */
   80:         INT    sstksz;            /* System stack size */
   81: 
   82:         INT    :0;                /* ### From here */
   83:         UB     reqdct;             /* DCT request (Depends on implementation,
   84:                                    the usage is different) */
   85:         B      isysmode;    /* Task operation mode initial value */
   86:         H      sysmode;     /* Task operation mode, quasi task part
   87:                                    call level */
   88:         INT    :0;                /* ### To here, since it might be accessed
   89:                                    from outside of the critical section,
   90:                                    need to be assigned as an independent
   91:                                    word. Also, there is a case where one
   92:                                    word is read from 'reqdct' and is read
   93:                                    all at once from 'reqdct', 'isysmode',
   94:                                    and 'sysmode', so do not change the
   95:                                    order and size. */
   96: 
   97:         UB     ipriority;  /* Priority at task startup */
   98:         UB     bpriority;  /* Base priority */
   99:         UB     priority;   /* Current priority */
  100: 
  101:         UB /*TSTAT*/   state;    /* Task state (Int. expression) */
  102: 
  103:         BOOL   nodiswai:1;       /* TRUE at wait disable
  104:                                    (Valid only for wait state) */
  105:         BOOL   klockwait:1;      /* TRUE at wait kernel lock */
  106:         BOOL   klocked:1;        /* TRUE at hold kernel lock */
  107: 
  108: CONST   WSPEC     *wspec;             /* Wait specification */
  109:         ID     wid;                /* Wait object ID */
  110:         INT    wupcnt;            /* Number of wakeup requests queuing */
  111:         INT    suscnt;            /* Number of SUSPEND request nests */
  112:         ER     *wercd;             /* Wait error code set area */
  113:         WINFO  winfo;           /* Wait information */
  114:         TMEB   wtmeb;            /* Wait timer event block */
  115:         UINT   waitmask; /* Disabled wait factor */
  116: 
  117: #ifdef NUM_PORID
  118:         RNO    wrdvno;            /* For creating rendezvous number */
  119: #endif
  120: #ifdef NUM_MTXID
  121:         MTXCB  *mtxlist;        /* List of hold mutexes */
  122: #endif
  123:         UB     tskevt;             /* Task event occurrence state */
  124: 
  125:         SVCLOCK        svclock;       /* Kernel lock for Extended SVC exclusion */
  126:         SVCLOCK        *svclocked;    /* List of lock */
  127: 
  128:         FP     texhdr;             /* Task exception handler */
  129:         UINT   texmask;  /* Task exception which is enabled */
  130:         UINT   pendtex;  /* Task exception which is now suspended */
  131:         UINT   exectex;  /* Task exception in break processing */
  132: 
  133:         UH     texflg;             /* Task exception control flag */
  134: #define TEX0_RUNNING    0x0001U    /* Task exception code '0' handler
  135:                                    is in execution */
  136: #define TEX1_RUNNING    0x0002U    /* Task exception code '1-31' handler
  137:                                    is in execution */
  138: #define SSFN_RUNNING    0x0004U    /* Subsystem function is in execution
  139:                                    (Task exception is suspended) */
  140: 
  141:         ID     execssid:16;        /* Subsystem ID of extended SVC in
  142:                                    execution (MSB=1 break handler was
  143:                                    already executed) */
  144: #define BREAK_RAN       0x8000U       /* execssid MSB */
  145: 
  146:         RELTIM_U slicetime;    /* Maximum continuous execution time (us) */
  147:         RELTIM_U slicecnt;     /* Continuous execution time counter (us) */
  148: 
  149:         RELTIM_U stime;                /* System execution time (us) */
  150:         RELTIM_U utime;                /* User execution time (us) */
  151: 
  152:         void   *istack;  /* User stack pointer initial value */
  153:         void   *isstack; /* System stack pointer initial value */
  154: #if TA_GP
  155:         void   *gp;              /* Global pointer */
  156: #endif
  157:         _align64               /* alignment for CTXB.ssp */
  158:         CTXB   tskctxb;  /* Task context block */
  159: #if USE_OBJECT_NAME
  160:         UB     name[OBJECT_NAME_LENGTH];   /* name */
  161: #endif
  162: };
  163: 
  164: /*
  165:  * Task dispatch disable state
  166:  *      0 = DDS_ENABLE                : ENABLE
  167:  *      1 = DDS_DISABLE_IMPLICIT : DISABLE with implicit process
  168:  *      2 = DDS_DISABLE               : DISABLE with tk_dis_dsp()
  169:  *      |    |
  170:  *      |    use in *.c
  171:  *      use in *.S
  172:  *        --> Do NOT change these literals, because using in assembler code
  173:  *
  174:  *      'dipatch_disabled' records dispatch disable status set by tk_dis_dsp()
  175:  *      for some CPU, that accepts delayed interrupt.
  176:  *      In this case, you can NOT refer the dispatch disabled status
  177:  *      only by 'dispatch_disabled'.
  178:  *      Use 'in_ddsp()' to refer the task dispatch status.
  179:  *      'in_ddsp()' is a macro definition in CPU-dependent definition files.
  180:  */
  181: #define DDS_ENABLE              (0)
  182: #define DDS_DISABLE_IMPLICIT    (1)        /* set with implicit process */
  183: #define DDS_DISABLE             (2)        /* set by tk_dis_dsp() */
  184: IMPORT INT      dispatch_disabled;
  185: 
  186: /*
  187:  * Task in execution
  188:  *      ctxtsk is a variable that indicates TCB task in execution
  189:  *      (= the task that CPU holds context). During system call processing,
  190:  *      when checking information about the task that requested system call,
  191:  *      use 'ctxtsk'. Only task dispatcher changes 'ctxtsk'.
  192:  */
  193: IMPORT TCB      *ctxtsk;
  194: 
  195: /*
  196:  * Task which should be executed
  197:  *      'schedtsk' is a variable that indicates the task TCB to be executed.
  198:  *      If a dispatch is delayed by the delayed dispatch or dispatch disable,
  199:  *      it does not match with 'ctxtsk.'
  200:  */
  201: IMPORT TCB      *schedtsk;
  202: 
  203: /*
  204:  * Task control information
  205:  */
  206: IMPORT TCB      *tcb_table;  /* Task control block */
  207: IMPORT QUEUE    free_tcb;  /* FreeQue */
  208: 
  209: /*
  210:  * Get TCB from task ID.
  211:  */
  212: #define get_tcb(id)             ( &tcb_table[INDEX_TSK(id)] )
  213: #define get_tcb_self(id)        ( ( (id) == TSK_SELF )? ctxtsk: get_tcb(id) )
  214: 
  215: /*
  216:  * Prepare task execution.
  217:  */
  218: IMPORT void make_dormant( TCB *tcb );
  219: 
  220: /*
  221:  * Make task executable.
  222:  *      If the 'tcb' task priority is higher than the executed task,
  223:  *      make it executable. If the priority is lower, connect the task to the
  224:  *      ready queue.
  225:  */
  226: IMPORT void make_ready( TCB *tcb );
  227: 
  228: /*
  229:  * Make task non-executable.
  230:  *      Change the 'tcb' task state to be a non-executable state (wait state,
  231:  *      forced wait, or dormant state). When calling this function, the
  232:  *      task must be executable. Change 'tcb->state' on the caller side
  233:  *      after returning from this function.
  234:  */
  235: IMPORT void make_non_ready( TCB *tcb );
  236: 
  237: /*
  238:  * Change task priority.
  239:  *      Change 'tcb' task priority to 'priority'.
  240:  *      Then make the required task state transition occur.
  241:  */
  242: IMPORT void change_task_priority( TCB *tcb, INT priority );
  243: 
  244: /*
  245:  * Rotate ready queue.
  246:  *      'rotate_ready_queue' rotates the priority ready queue at 'priority'.
  247:  *      'rotate_ready_queue_run' rotates the ready queue including the highest
  248:  *      priority task in the ready queue.
  249:  */
  250: IMPORT void rotate_ready_queue( INT priority );
  251: IMPORT void rotate_ready_queue_run( void );
  252: 
  253: /*
  254:  * Scheduling by time slice
  255:  */
  256: IMPORT TCB* time_slice_schedule( TCB *tcb );
  257: 
  258: #endif /* _TASK_ */