gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/clk/src/main.cbare sourcepermlink (0.02 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/03/11.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: 
   17: /*
   18:  *      main.c               Clock driver : main
   19:  *                      System-independent
   20:  */
   21: #include "clkdrv.h"
   22: #include <sys/util.h>
   23: 
   24: 
   25: /* Message buffer for event notification */
   26: LOCAL   ID        evtMbf;
   27: 
   28: /* Driver I/F access handle */
   29: LOCAL   SDI       ClkSdi;
   30: 
   31: /*
   32:  *      Check the parameter
   33:  *              = E_OK : OK (size == 0)
   34:  *              > E_OK : OK (size > 0)
   35:  *              < E_OK : Error
   36:  */
   37: LOCAL   ER        CheckPar(W size, W dsz)
   38: {
   39:         if (size < 0 || (size > 0 && size < dsz)) return E_PAR;
   40:         return size ? (E_OK + 1) : E_OK;
   41: }
   42: 
   43: /*
   44:  *      Input-output request
   45:  */
   46: LOCAL   INT       rwfn(BOOL rd, ID devid, INT start, INT size, void *buf, SDI sdi)
   47: {
   48:         INT    er;
   49:         W      dsz;
   50: 
   51:         switch (start) {
   52:         case DN_CKEVENT:       /* RW: Event notification message buffer ID */
   53:                 er = CheckPar(size, dsz = sizeof(W));
   54:                 if (er > E_OK) {
   55:                         if (rd) {
   56:                                 *(W*)buf = evtMbf;
   57:                         } else {
   58:                                 evtMbf = *(W*)buf;
   59:                         }
   60:                 }
   61:                 break;
   62: 
   63:         case DN_CKDATETIME:    /* RW: Current time */
   64:                 er = CheckPar(size, dsz = sizeof(DATE_TIM));
   65:                 if (er > E_OK) {
   66:                         if (rd) {
   67:                                 er = cdGetDateTime(buf);
   68:                         } else {
   69:                                 er = cdSetDateTime(buf);
   70:                         }
   71:                 }
   72:                 break;
   73: 
   74:         case DN_CKAUTOPWON:    /* RW: Automatic power-ON time     */
   75:                 er = CheckPar(size, dsz = sizeof(DATE_TIM));
   76:                 if (er > E_OK) {
   77:                         if (rd) {
   78:                                 er = cdGetAutoPwOn(buf);
   79:                         } else {
   80:                                 er = cdSetAutoPwOn(buf);
   81:                         }
   82:                 }
   83:                 break;
   84: 
   85:         case DN_CKREGISTER:    /* RW: Unvolatile register */
   86:                 if (rd) {
   87:                         er = cdGetRegister(buf, size);
   88:                 } else {
   89:                         er = cdSetRegister(buf, size);
   90:                 }
   91:                 dsz = er;
   92:                 break;
   93: 
   94:         default:               /* Data number error */
   95:                 dsz = er = E_PAR;
   96:                 break;
   97:         }
   98: 
   99:         if (er >= E_OK) {
  100:                 er = dsz;
  101:         } else {
  102:                 DEBUG_PRINT(("rwData dn:%d err = %d\n", start, er));
  103:         }
  104: 
  105:         return er;
  106: }
  107: 
  108: /*
  109:  *      Input request processing function
  110:  */
  111: LOCAL   INT       readfn(ID devid, INT start, INT size, void *buf, SDI sdi)
  112: {
  113:         return rwfn(TRUE, devid, start, size, buf, sdi);
  114: }
  115: 
  116: /*
  117:  *      Output request processing function
  118:  */
  119: LOCAL   INT       writefn(ID devid, INT start, INT size, void *buf, SDI sdi)
  120: {
  121:         return rwfn(FALSE, devid, start, size, buf, sdi);
  122: }
  123: 
  124: /*
  125:  *      Clock driver entry
  126:  */
  127: EXPORT  ER       ClockDrv(INT ac, UB *av[])
  128: {
  129:         ER     er;
  130:         T_IDEV idev;
  131:         static const SDefDev   ddev = {
  132:                 NULL,         /* exinf */
  133:                 "CLOCK",      /* devnm */
  134:                 0,            /* drvatr */
  135:                 0,            /* devatr */
  136:                 0,            /* nsub */
  137:                 1,            /* blksz */
  138:                 NULL,         /* open */
  139:                 NULL,         /* close */
  140:                 readfn,               /* read */
  141:                 writefn,      /* write */
  142:                 NULL,
  143:         };
  144: 
  145:         /* End processing */
  146:         if (ac < 0) {
  147:                 /* Hardware end processing */
  148:                 cdFinishHardware();
  149: 
  150:                 /* Device deregistrtaion */
  151:                 SDelDevice(ClkSdi);
  152:                 return E_OK;
  153:         }
  154: 
  155:         /* Hardware initial setting */
  156:         er = cdInitHardware();
  157:         if (er < E_OK) goto err_ret;
  158: 
  159:         /* Device registration */
  160:         er = SDefDevice(&ddev, &idev, &ClkSdi);
  161:         if (er < E_OK) goto err_ret;
  162: 
  163:         /* Set the message buffer for event notification to insert the event when the event named "default" occurs */
  164:         evtMbf = idev.evtmbfid;
  165: 
  166: err_ret:
  167:         DEBUG_PRINT(("ClockDriver er = %d\n", er));
  168:         return er;
  169: }