gonzui


Format: Advanced Search

mtkernel_3/kernel/sysinit/sysinit.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.01
    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/05/29.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      sysinit.c
   16:  *      micro T-Kernel Startup / Finalization
   17:  */
   18: #include "kernel.h"
   19: #include <tm/tmonitor.h>
   20: 
   21: /*
   22:  * Start micro T-Kernel
   23:  *    Initialize sequence before micro T-Kernel start.
   24:  *    Perform preparation necessary to start micro T-Kernel.
   25:  */
   26: EXPORT INT main( void )
   27: {
   28:         ER     ercd;
   29: 
   30:         DISABLE_INTERRUPT;
   31: 
   32: #if USE_TMONITOR
   33:         /* Initialize T-Monitor Compatible Library */
   34:         libtm_init();
   35: #endif
   36: 
   37: #if USE_IMALLOC
   38:         /* Initialize Internal memory allocation (Imalloc) */
   39:         ercd = knl_init_Imalloc();
   40:         if ( ercd < E_OK ) {
   41:                 SYSTEM_MESSAGE("!ERROR! init_Imalloc\n");
   42:                 goto err_ret;
   43:         }
   44: #endif /* USE_IMALLOC */
   45: 
   46:         /* Initialize Device before micro T-Kernel starts */
   47:         ercd = knl_init_device();
   48:         if ( ercd < E_OK ) {
   49:                 SYSTEM_MESSAGE("!ERROR! init_device\n");
   50:                 goto err_ret;
   51:         }
   52: 
   53:         /* Interrupt initialize */
   54:         ercd = knl_init_interrupt();
   55:         if ( ercd < E_OK ) {
   56:                 SYSTEM_MESSAGE("!ERROR! init_initialize\n");
   57:                 goto err_ret;
   58:         }
   59: 
   60:         /* Initialize Kernel-objects  */
   61:         ercd = knl_init_object();
   62:         if ( ercd < E_OK ) {
   63:                 SYSTEM_MESSAGE("!ERROR! kernel object initialize\n");
   64:                 goto err_ret1;
   65:         }
   66: 
   67:         /* Start System Timer */
   68:         ercd = knl_timer_startup();
   69:         if ( ercd < E_OK ) {
   70:                 SYSTEM_MESSAGE("!ERROR! System timer startup\n");
   71:                 goto err_ret1;
   72:         }
   73: 
   74:         /* Create & start initial task */
   75:         ercd = tk_cre_tsk((CONST T_CTSK *)&knl_init_ctsk);
   76:         if ( ercd >= E_OK ) {
   77:                 ercd = tk_sta_tsk((ID)ercd, 0);
   78:                 if ( ercd >= E_OK ) {
   79:                         knl_force_dispatch();
   80:                         /**** Start Initial Task. ****/
   81:                         /**** No return ****/
   82:                 } else {
   83:                         SYSTEM_MESSAGE("!ERROR! Initial Task can not start\n");
   84:                 }
   85:         } else {
   86:                 SYSTEM_MESSAGE("!ERROR! Initial Task can not creat\n");
   87:         }
   88: 
   89:         /* After this, Error handling */
   90: 
   91: #if USE_SHUTDOWN
   92:         knl_timer_shutdown();  /* Stop System timer */
   93: err_ret1:
   94:         knl_shutdown_hw();     /* Hardware-dependent Finalization */
   95:         /**** No return ****/
   96: #else
   97: err_ret1:
   98: #endif /* USE_SHUTDOWN */
   99: 
  100: err_ret:
  101:         while(1);
  102:         return 0;
  103: }
  104: 
  105: /*
  106:  * Exit micro T-Kernel from Initial Task.
  107:  */
  108: #if USE_SHUTDOWN
  109: EXPORT void knl_tkernel_exit( void )
  110: {
  111:         knl_timer_shutdown();  /* Stop System timer */
  112:         knl_shutdown_hw();     /* Hardware-dependent Finalization */
  113:         /**** No return ****/
  114: 
  115:         while(1);
  116: }
  117: #endif /* USE_SHUTDOWN */