gonzui


Format: Advanced Search

mtkernel_3/app_sample/app_main.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.05
    4:  *
    5:  *    Copyright (C) 2006-2021 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 2021/11.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: #include <tk/tkernel.h>
   15: #include <tm/tmonitor.h>
   16: 
   17: /* ---------------------------------------------------------
   18:  * Sample User Program
   19:  * ---------------------------------------------------------
   20:  * 
   21:  * Entry routine for the user application.
   22:  * At this point, Initialize and start the user application.
   23:  *
   24:  * Entry routine is called from the initial task for Kernel,
   25:  * so system call for stopping the task should not be issued 
   26:  * from the contexts of entry routine.
   27:  * We recommend that:
   28:  * (1)'usermain()' only generates the user initial task.
   29:  * (2)initialize and start the user application by the user
   30:  * initial task.
   31:  */
   32: 
   33: #if USE_TMONITOR
   34: #define TM_PUTSTRING(a) tm_putstring(a)
   35: 
   36: void print_err( UB* str, ER err)
   37: {
   38:         tm_printf(str, err);
   39: }
   40: 
   41: #else
   42: #define TM_PUTSTRING(a)
   43: 
   44: void print_err( UB* str, INT par) {}
   45: 
   46: #endif /* USE_TMONITOR */
   47: 
   48: /* ----------------------------------------------------------
   49:  *
   50:  * User Task-1 Definition
   51:  *
   52:  */
   53: void tsk1(INT stacd, void *exinf)
   54: {
   55:         TM_PUTSTRING((UB*)"Start Task-1\n");
   56: 
   57:         tk_exd_tsk();  /* Exit task */
   58: }
   59: 
   60: /* ---------------------------------------------------------
   61:  *
   62:  * User Task-2 Definition
   63:  *
   64:  */
   65: void tsk2(INT stacd, void *exinf)
   66: {
   67:         TM_PUTSTRING((UB*)"Start Task-2\n");
   68: 
   69:         tk_exd_tsk();  /* Exit Task */
   70: }
   71: 
   72: const T_CTSK    ctsk1      = {0, (TA_HLNG | TA_RNG3), &tsk1, 10, 1024, 0};
   73: const T_CTSK    ctsk2      = {0, (TA_HLNG | TA_RNG3), &tsk2, 11, 1024, 0};
   74: 
   75: /* ----------------------------------------------------------
   76:  *
   77:  * User-Main Definition (Run on initial task)
   78:  *
   79:  */
   80: 
   81: EXPORT INT usermain( void )
   82: {
   83:         T_RVER rver;
   84:         ID     id1, id2;
   85: 
   86:         TM_PUTSTRING((UB*)"Start User-main program.\n");
   87: 
   88:         tk_ref_ver(&rver);             /* Get the OS Version. */
   89: 
   90: #if USE_TMONITOR
   91:         tm_printf((UB*)"Make Code: %04x  Product ID: %04x\n", rver.maker, rver.prid);
   92:         tm_printf((UB*)"Product Ver. %04x\nProduct Num. %04x %04x %04x %04x\n", 
   93:                         rver.prver, rver.prno[0],rver.prno[1],rver.prno[2],rver.prno[3]);
   94: #endif
   95: 
   96:         id1 = tk_cre_tsk(&ctsk1);
   97:         tk_sta_tsk(id1, 0);
   98: 
   99:         id2 = tk_cre_tsk(&ctsk2);
  100:         tk_sta_tsk(id2, 0);
  101: 
  102:         tk_slp_tsk(TMO_FEVR);
  103: 
  104:         return 0;
  105: }