gonzui


Format: Advanced Search

tkernel_2/kernel/tkernel/src/tkstart.cbare sourcepermlink (0.03 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 2013/01/12.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      tkstart.c (T-Kernel/OS)
   18:  *      T-Kernel Startup / Finalization
   19:  */
   20: 
   21: #include "kernel.h"
   22: #include "timer.h"
   23: #include "task.h"
   24: #include <tm/tmonitor.h>
   25: 
   26: /*
   27:  * Start initial task
   28:  */
   29: LOCAL void init_task_startup( T_CTSK *ctsk )
   30: {
   31:         ER     ercd;
   32: 
   33: #if TA_GP
   34:         extern int _gp;
   35:         ercd = _tk_cre_tsk(ctsk, 0,0,0,0,&_gp);
   36: #else
   37:         ercd = _tk_cre_tsk(ctsk);
   38: #endif
   39:         if ( ercd < E_OK ) {
   40:                 goto err_exit;
   41:         }
   42: 
   43:         ercd = _tk_sta_tsk((ID)ercd, 0);
   44:         if ( ercd < E_OK ) {
   45:                 goto err_exit;
   46:         }
   47: 
   48:         return;
   49: 
   50: err_exit:
   51: #if USE_KERNEL_MESSAGE
   52:         tm_putstring((UB*)"init_task can not started\n");
   53: #endif
   54:         tm_monitor();
   55: }
   56: 
   57: /*
   58:  * Call module initialization
   59:  */
   60: LOCAL void init_module( ER (*initfunc)( void ), UB *name )
   61: {
   62:         ER     ercd;
   63: 
   64:         ercd = (*initfunc)();
   65:         if ( ercd < E_OK ) {
   66: #if USE_KERNEL_MESSAGE
   67:                 tm_putstring(name);
   68:                 tm_putstring((UB*)" : module initialize error\n");
   69: #endif
   70:                 tm_monitor();
   71:         }
   72: }
   73: #define InitModule(name)        init_module( name##_initialize, (UB*) #name )
   74: 
   75: /*
   76:  * Initialize kernel and create/start initial task
   77:  */
   78: EXPORT void t_kernel_main( T_CTSK *inittask )
   79: {
   80: IMPORT  void DispProgress( W n );        /* sysinit */
   81: 
   82:         DISABLE_INTERRUPT;
   83: 
   84:         /*
   85:          * Target-dependent initialization
   86:          */
   87:         DispProgress(0x20);
   88:         InitModule(cpu);
   89:         InitModule(tkdev);
   90: 
   91:         /*
   92:          * Each module initialization
   93:          */
   94:         DispProgress(0x21);
   95:         InitModule(task);
   96: #ifdef NUM_SEMID
   97:         InitModule(semaphore);
   98: #endif
   99: #ifdef NUM_FLGID
  100:         InitModule(eventflag);
  101: #endif
  102: #ifdef NUM_MBXID
  103:         InitModule(mailbox);
  104: #endif
  105: #ifdef NUM_MBFID
  106:         InitModule(messagebuffer);
  107: #endif
  108: #ifdef NUM_PORID
  109:         InitModule(rendezvous);
  110: #endif
  111: #ifdef NUM_MTXID
  112:         InitModule(mutex);
  113: #endif
  114: #ifdef NUM_MPLID
  115:         InitModule(memorypool);
  116: #endif
  117: #ifdef NUM_MPFID
  118:         InitModule(fix_memorypool);
  119: #endif
  120: #ifdef NUM_CYCID
  121:         InitModule(cyclichandler);
  122: #endif
  123: #ifdef NUM_ALMID
  124:         InitModule(alarmhandler);
  125: #endif
  126:         InitModule(subsystem);
  127:         InitModule(resource_group);
  128:         InitModule(timer);
  129: 
  130:         /*
  131:          * Create/start initial task
  132:          */
  133:         DispProgress(0x22);
  134:         init_task_startup(inittask);
  135: 
  136:         /*
  137:          * Dispatch to initial task and start kernel operation.
  138:          */
  139:         DispProgress(0x23);
  140:         force_dispatch();
  141:         /* No return */
  142: }
  143: 
  144: /*
  145:  * Finalization
  146:  */
  147: EXPORT void t_kernel_shutdown( void )
  148: {
  149:         timer_shutdown();
  150:         cpu_shutdown();
  151: }
  152: 
  153: /*
  154:  * Execute finalization and stop
  155:  */
  156: EXPORT void t_kernel_exit( void )
  157: {
  158:         t_kernel_shutdown();
  159:         tkdev_exit();
  160:         /* No return */
  161: }