gonzui


Format: Advanced Search

mtkernel_3/kernel/inittask/inittask.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.02
    4:  *
    5:  *    Copyright (C) 2006-2020 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2020/10/21.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      inittask.c
   16:  *      Initial task definition
   17:  */
   18: #include <tk/tkernel.h>
   19: #include <tm/tmonitor.h>
   20: #include <sys/inittask.h>
   21: 
   22: #include "kernel.h"
   23: 
   24: #if !USE_IMALLOC
   25: INT     init_task_stack[INITTASK_STKSZ/sizeof(INT)];
   26: #endif
   27: 
   28: typedef INT     (*MAIN_FP)(INT, UB **);
   29: 
   30: /*
   31:  * Initial task creation parameter
   32:  */
   33: 
   34: LOCAL void init_task_main(void);
   35: 
   36: EXPORT const T_CTSK knl_init_ctsk = {
   37:         (void *)INITTASK_EXINF,                /* exinf */
   38:         INITTASK_TSKATR,               /* tskatr */
   39:         (FP)&init_task_main,           /* task */
   40:         INITTASK_ITSKPRI,              /* itskpri */
   41:         INITTASK_STKSZ,                        /* stksz */
   42: #if USE_OBJECT_NAME
   43:         INITTASK_DSNAME,               /* dsname */
   44: #endif
   45:         INITTASK_STACK,                        /* bufptr */
   46: };
   47: 
   48: /* --------------------------------------------------------------- */
   49: /*
   50:  * Start System
   51:  *      Start each subsystem and each device driver.
   52:  *      Return from function after starting.
   53:  */
   54: LOCAL ER start_system( void )
   55: {
   56:         ER     ercd;
   57: 
   58: #if USE_DEVICE
   59:         /* Initialize Device manager */
   60:         ercd = knl_initialize_devmgr();
   61:         if ( ercd < E_OK ) return ercd;
   62: #endif
   63: 
   64:         /* Start system dependent sequence */
   65:         ercd = knl_start_device();
   66: 
   67:         return ercd;
   68: }
   69: 
   70: /*
   71:  * Stop System
   72:  *      Never return from this function.
   73:  *
   74:  *      fin  =        0 : Power off
   75:  *              -1 : reset and re-start     (Reset -> Boot -> Start)
   76:  *              -2 : fast re-start          (Start)
   77:  *              -3 : Normal re-start                (Boot -> Start)
   78:  *
   79:  *      fin are not always supported.
   80:  */
   81: LOCAL void shutdown_system( INT fin )
   82: {
   83: #if USE_SHUTDOWN
   84:         /* Platform dependent finalize sequence */
   85:         knl_finish_device();
   86: 
   87:         /* Shutdown message output */
   88:         if ( fin >= 0 ) {
   89:                 SYSTEM_MESSAGE("\n<< SYSTEM SHUTDOWN >>\n");
   90:         }
   91: 
   92:         if ( fin < 0 ) {
   93:                 /* Re-start sequence (platform dependent) */
   94:                 knl_restart_hw(fin);
   95:         }
   96: 
   97:         knl_tkernel_exit();            /* Stop system */
   98: #else
   99:         DISABLE_INTERRUPT;
  100:         for(;;) {
  101:                 ;
  102:         }
  103: #endif /* USE_SHUTDOWN */
  104: }
  105: 
  106: 
  107: /*
  108:  * Initial task main
  109:  */
  110: LOCAL void init_task_main(void)
  111: {
  112:         INT    fin = 1;
  113:         ER     ercd;
  114: 
  115:         ercd = start_system();         /* Start Sub-system & device driver */
  116:         if(ercd  >= E_OK) {
  117: 
  118: #if (USE_SYSTEM_MESSAGE && USE_TMONITOR)
  119:                 tm_printf((UB*)"\n\nmicroT-Kernel Version %x.%02x\n\n", VER_MAJOR, VER_MINOR);
  120: #endif
  121: 
  122: #if USE_USERINIT
  123:                 /* Perform user defined initialization sequence */
  124:                 fin = (*(MAIN_FP)RI_USERINIT)(0, NULL);
  125: #endif
  126:                 if ( fin > 0 ) {
  127:                         fin = usermain();    /* User Main Program */
  128:                 }
  129: #if USE_USERINIT
  130:                 /* Perform user defined finalization sequence */
  131:                 (*(MAIN_FP)RI_USERINIT)(-1, NULL);
  132: #endif
  133: 
  134:         } else {
  135:                 SYSTEM_MESSAGE("!ERROR! Init Task start\n");  /* Start message */
  136:         }
  137: 
  138:         shutdown_system(fin);  /* Never return */
  139: }
  140: