gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/lowkbpd/src/main.cbare sourcepermlink (0.01 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:         main.C  KB/PD real I/O driver: main
   18:  *
   19:  */
   20: #include        "kbpd.h"
   21: #include        <device/devconf.h>
   22: 
   23: /* Get "DEVCONF" entry */
   24: IMPORT W GetDevConf( UB *name, W *val );
   25: 
   26: EXPORT  ID       CmdTsk;                       /* command processing task ID */
   27: EXPORT  ID       CmdFlg;                       /* event flag ID for sending command */
   28: EXPORT  ID       EvtMbx;                       /* MBOX ID for sending event                */
   29: EXPORT  ID       InpMbf;                       /* input MBUF ID                    */
   30:  
   31: EXPORT  BOOL     Suspended;          /* suspended                        */
   32: 
   33: EXPORT  UW       InpMode;              /* input mode                        */
   34: EXPORT  UW       KbdId;                        /* keyboard ID              */
   35: EXPORT  W        PdSense;               /* sensitivity (0-15), acceleration(0-7) */
   36: 
   37: EXPORT  PRI      TaskPri;             /* task priority */
   38: 
   39: #define devkbpd "kbpd"                  /* KB/PD device name  */
   40:  
   41: /*
   42:         create & start task
   43: */
   44: EXPORT  INT      kpCreTask(W name, FP entry)
   45: {
   46:         T_CTSK ctsk;
   47:         ID     tskid;
   48:         INT    er;
   49: 
   50:         /* task creation */
   51:         ctsk.exinf = (void*)name;
   52:         ctsk.task = entry;
   53:         ctsk.itskpri = TaskPri;
   54:         ctsk.stksz = TASK_STKSZ;
   55:         ctsk.tskatr = TA_HLNG | TA_RNG0;
   56: 
   57:         tskid = er = tk_cre_tsk(&ctsk);
   58:         if (er >= E_OK) {      /* start task */
   59:                 er = tk_sta_tsk(tskid, 0);
   60:                 if (er < E_OK) tk_del_tsk(tskid);
   61:         }
   62:         return (er >= E_OK) ? tskid : er;
   63: }
   64: /*
   65:         initial setting at driver start up time
   66: */
   67: LOCAL   ER        kpStartUp(void)
   68: {
   69:         W      w[L_DEVCONF_VAL];
   70:         W      dd, n;
   71:         ER     er;
   72:         RawEvt evt;
   73:         T_CMBF cmbf;
   74:         T_CFLG cflg;
   75:         ID     datatsk;
   76:         void*  name;
   77:         union {
   78:                 FlgInStat     stat;
   79:                 UW            uw;
   80:         } u;
   81: 
   82:         /* extract ID of the mailbox for event notification to KB/PD driver */
   83:         dd = er = tk_opn_dev(devkbpd, TD_READ);
   84:         if (er >= E_OK) {
   85:                 er = tk_srea_dev(dd, DN_KPINPUT, (VB*)&EvtMbx,
   86:                                                 sizeof(EvtMbx), &n);
   87:                 tk_cls_dev(dd, 0);
   88:         }
   89:         if (er < E_OK) goto EEXIT1;
   90: 
   91:         /* KBID is extracted from DEVCONF parameter */
   92:         KbdId = (GetDevConf("KBTYPE", w) == 1) ? w[0] : KID_IBM_JP;
   93: 
   94:         /* input message buffer creation */
   95:         SetOBJNAME(cmbf.exinf, "lkbM");
   96:         cmbf.mbfatr = TA_TFIFO;
   97:         cmbf.bufsz  = sizeof(InMsg) * MAX_INMSG;
   98:         cmbf.maxmsz = sizeof(InMsg);
   99:         if ((er = tk_cre_mbf(&cmbf)) < E_OK) goto EEXIT1;
  100:         InpMbf = er;
  101: 
  102:         /* creating the event flag for command */
  103:         SetOBJNAME(cflg.exinf, "lkbC");
  104:         cflg.flgatr  = TA_WMUL;
  105:         cflg.iflgptn = 0;
  106:         if ((er = tk_cre_flg(&cflg)) < E_OK) goto EEXIT2;
  107:         CmdFlg = (ID)er;
  108: 
  109:         /* create and start data processing task */
  110:         SetOBJNAME(name, "lkbD");
  111:         er = kpCreTask((W)name, kpDataTask);
  112:         if (er < E_OK) goto EEXIT3;
  113:         datatsk = (ID)er;
  114: 
  115:         /* create and start command processing task */
  116:         SetOBJNAME(name, "lkbC");
  117:         er = kpCreTask((W)name, kpCmdTask);
  118:         if (er < E_OK) goto EEXIT4;
  119:         CmdTsk = (ID)er;
  120: 
  121:         /* registering event flag for commands */
  122:         u.uw = 0;
  123:         evt.f.stat = u.stat;
  124:         evt.f.stat.cmd = INP_FLG;
  125:         evt.f.stat.kb = 1;
  126:         evt.f.stat.kbid = KbdId;
  127:         evt.f.stat.reg = 1;
  128:         evt.f.flgid = CmdFlg;
  129:         if ((er = kpSendMsg(&evt)) < E_OK) goto EEXIT5;
  130: 
  131:         /* device initialization processing */
  132:         er = hwInit(DC_OPEN);
  133:         if (er < E_OK) goto EEXIT5;
  134: 
  135:         return E_OK;
  136: 
  137: EEXIT5:
  138:         tk_ter_tsk(CmdTsk);
  139:         tk_del_tsk(CmdTsk);
  140: EEXIT4:
  141:         tk_ter_tsk(datatsk);
  142:         tk_del_tsk(datatsk);
  143: EEXIT3:
  144:         tk_del_flg(CmdFlg);
  145: EEXIT2:
  146:         tk_del_mbf(InpMbf);
  147: EEXIT1:
  148:         DP(("kpStartUp: err=%#x\n", er));
  149:         return er;
  150: }
  151: /*
  152:         KBPD keyboard/ PD real I/O driver entry
  153: */
  154: EXPORT  ER       LowKbPdDrv(INT ac, UB *av[])
  155: {
  156:         char   *arg;
  157:         W      v[L_DEVCONF_VAL];
  158: 
  159:         /* effective? */
  160:         if (GetDevConf("LowKbPdDrvEnable", v) > 0 && !v[0]) return E_NOSPT;
  161: 
  162:         if (ac < 0) return E_OK;       /* no special epilog processor event */
  163: 
  164:         /* obtain start parameter */
  165:         TaskPri = DEF_PRIORITY;
  166:         if (ac > 1 && (arg = av[1]) != NULL) {
  167:                 switch (*arg++) {
  168:                 case '!':     /* priority */
  169:                         TaskPri = STRTOUL(arg, &arg, 0);
  170:                         break;
  171:                 default:
  172:                         return E_PAR;
  173:                 }
  174:         }
  175: 
  176:         /* driver initialization */
  177:         return kpStartUp();
  178: }