gonzui


Format: Advanced Search

tkernel_2/kernel/sysmain/src/usermain.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 2014/09/10.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      usermain.c (usermain)
   18:  *      User Main for debug with device drivers
   19:  */
   20: 
   21: #include <basic.h>
   22: #include <tk/tkernel.h>
   23: #include <tm/tmonitor.h>
   24: #include <libstr.h>
   25: 
   26: /* Device drivers */
   27: IMPORT ER ConsoleIO( INT ac, UB *av[] );
   28: IMPORT ER ClockDrv( INT ac, UB *av[] );
   29: IMPORT ER SysDiskDrv( INT ac, UB *av[] );
   30: IMPORT ER ScreenDrv( INT ac, UB *av[] );
   31: IMPORT ER KbPdDrv( INT ac, UB *av[] );
   32: IMPORT ER LowKbPdDrv( INT ac, UB *av[] );
   33: 
   34: #ifdef DEBUG_SAMPLE
   35: /*-----------------------------------------------------------------------------
   36:         debug sample
   37: -----------------------------------------------------------------------------*/
   38: /*
   39:  *  debug sample - task
   40:  */
   41: LOCAL void test_tsk( INT stacd, void *exinf )
   42: {
   43:         INT    i;
   44: 
   45:         tm_printf("3 - Sample task started (tid=%d).\n", tk_get_tid());
   46: 
   47:         for (i = 0; i < 3; i++) {
   48:                 tk_dly_tsk(1000);
   49:                 tm_printf("%d - Delay 1000 msec.\n", 4 + i);
   50:         }
   51: 
   52:         tm_printf("7 - Wakeup main task.\n");
   53: 
   54:         /* Wake up calling task */
   55:         tk_wup_tsk(stacd);
   56: 
   57:         tm_printf("9 - Sample task finished.\n");
   58: 
   59:         /* Exit and delete myself */
   60:         tk_exd_tsk();
   61: }
   62: /*
   63:  *  debug sample - main
   64:  */
   65: LOCAL   void      debug_sample(void)
   66: {
   67:         ER     er;
   68:         ID     ttskid;
   69:         T_CTSK ctsk;
   70:         T_RTSK rtsk;
   71: 
   72:         tm_printf("1 - Debug sample started.\n");
   73: 
   74:         /* Create task */
   75:         MEMSET(&ctsk, 0, sizeof(ctsk));
   76: 
   77:         ctsk.tskatr = TA_HLNG | TA_RNG0;/* Task attribute              */
   78:         ctsk.task = test_tsk;          /* Task startup address         */
   79:         ctsk.itskpri = 140;            /* Priority at task startup       */
   80:         ctsk.stksz = 2 * 1024;         /* User stack size (byte)      */
   81: 
   82:         ttskid = tk_cre_tsk(&ctsk);
   83:         if ( ttskid < E_OK ) {
   84:                 tm_printf("ERROR: tk_cre_tsk [%#x].\n", ttskid);
   85:                 goto err_ret;
   86:         }
   87: 
   88:         /* Start task */
   89:         er = tk_sta_tsk(ttskid, tk_get_tid());
   90:         if ( er < E_OK ) {
   91:                 tk_del_tsk(ttskid);
   92:                 tm_printf("ERROR: tk_sta_tsk [%#x].\n", er);
   93:                 goto err_ret;
   94:         }
   95: 
   96:         tm_printf("2 - Start sample task (tid=%d) and wait.\n", ttskid);
   97: 
   98:         /* Wait for wake-up */
   99:         tk_slp_tsk(TMO_FEVR);
  100: 
  101:         tm_printf("8 - Wakeup from sample task.\n");
  102: 
  103:         /* Confirm deletion of task */
  104:         while(1) {
  105:                 er = tk_ref_tsk(ttskid, &rtsk);
  106:                 if ( er == E_NOEXS ) break;
  107:                 tk_slp_tsk(50);
  108:         }
  109:         tm_printf("10 - Debug sample finished.\n");
  110: 
  111: err_ret:
  112:         return;
  113: }
  114: #endif  /* DEBUG_SAMPLE */
  115: 
  116: /*
  117:  * Entry routine for the user application.
  118:  * At this point, Initialize and start the user application.
  119:  *
  120:  * Entry routine is called from the initial task for Kernel,
  121:  * so system call for stopping the task should not be issued
  122:  * from the contexts of entry routine.
  123:  * We recommend that:
  124:  * (1)'usermain()' only generates the user initial task.
  125:  * (2)initialize and start the user application by the user
  126:  * initial task.
  127:  */
  128: EXPORT  INT      usermain( void )
  129: {
  130:         ER     ercd;
  131: 
  132:         /* Start the device drivers */
  133: #ifdef DRV_CONSOLE
  134:         ercd = ConsoleIO(0, NULL);
  135:         tm_putstring(ercd >= E_OK ? "ConsoleIO - OK\n" : "ConsoleIO - ERR\n");
  136: #endif
  137: #ifdef DRV_CLOCK
  138:         ercd = ClockDrv(0, NULL);
  139:         tm_putstring(ercd >= E_OK ? "ClockDrv - OK\n" : "ClockDrv - ERR\n");
  140: #endif
  141: #ifdef DRV_SYSDISK
  142:         ercd = SysDiskDrv(0, NULL);
  143:         tm_putstring(ercd >= E_OK ? "SysDiskDrv - OK\n" : "SysDiskDrv - ERR\n");
  144: #endif
  145: #ifdef DRV_SCREEN
  146:         ercd = ScreenDrv(0, NULL);
  147:         tm_putstring(ercd >= E_OK ? "ScreenDrv - OK\n" : "ScreenDrv - ERR\n");
  148: #endif
  149: #ifdef DRV_KBPD
  150:         ercd = KbPdDrv(0, NULL);
  151:         tm_putstring(ercd >= E_OK ? "KbPdDrv - OK\n" : "KbPdDrv - ERR\n");
  152: #endif
  153: #ifdef DRV_LOWKBPD
  154:         ercd = LowKbPdDrv(0, NULL);
  155:         tm_putstring(ercd >= E_OK ? "LowKbPdDrv - OK\n" : "LowKbPdDrv - ERR\n");
  156: #endif
  157: 
  158: #ifdef DEBUG_SAMPLE
  159:         /* Debug sample */
  160:         debug_sample();
  161: #endif
  162: 
  163:         /* System shutdown */
  164:         tm_putstring((UB*)"Push any key to shutdown the T-Kernel.\n");
  165:         tm_getchar(-1);
  166: 
  167:         /* Stop the device drivers */
  168: #ifdef DRV_LOWKBPD
  169:         LowKbPdDrv(-1, NULL);
  170: #endif
  171: #ifdef DRV_KBPD
  172:         KbPdDrv(-1, NULL);
  173: #endif
  174: #ifdef DRV_SCREEN
  175:         ScreenDrv(-1, NULL);
  176: #endif
  177: #ifdef DRV_SYSDISK
  178:         SysDiskDrv(-1, NULL);
  179: #endif
  180: #ifdef DRV_CLOCK
  181:         ClockDrv(-1, NULL);
  182: #endif
  183: #ifdef DRV_CONSOLE
  184:         ConsoleIO(-1, NULL);
  185: #endif
  186: 
  187:         return 0;
  188: }