gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/clk/src/em1d512_iicspi_svc.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/07/28.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      em1d512_iicspi_svc.c (clkdrv)
   18:         IIC/SPI driver : extended SVC
   19:  *
   20:  */
   21: 
   22: #include "clkdrv.h"
   23: #include "svc/ifem1d512.h"
   24: 
   25: /* IIC driver */
   26: IMPORT  ER       IICup(W ch, BOOL start);
   27: IMPORT  ER       IICXfer(W ch, UH *cmddata, W words);
   28: 
   29: /* SPI driver */
   30: IMPORT  ER       SPIup(W ch, BOOL start);
   31: IMPORT  ER       SPIXfer(W cs, UB *xmit, UB *recv, W len);
   32: 
   33: /* SPI/IIC driver / SVC entries */
   34: LOCAL   INT       em1d512_iicspi_svcentry(void *par, W fn)
   35: {
   36:         H8IO_EM1D512_IICXFER_PARA      *iic;
   37:         H8IO_EM1D512_SPIXFER_PARA      *spi;
   38:         INT    er;
   39: 
   40:         switch (fn) {
   41:         case   H8IO_EM1D512_IICXFER_FN:
   42:                 iic = par;
   43:                 er = IICXfer(iic->ch, iic->cmddat, iic->words);
   44:                 break;
   45:         case   H8IO_EM1D512_SPIXFER_FN:
   46:                 spi = par;
   47:                 er = SPIXfer(spi->cs, spi->xmit, spi->recv, spi->len);
   48:                 break;
   49:         default:
   50:                 er = E_ILUSE;
   51:                 break;
   52:         }
   53: 
   54:         return er;
   55: }
   56: 
   57: /* SPI/IIC driver prolog ends */
   58: EXPORT  ER       em1d512_iicspi_svc(BOOL start)
   59: {
   60:         ER     er;
   61:         T_DSSY dssy;
   62: static  BOOL     initialized = FALSE;
   63: 
   64:         er = E_OK;
   65:         if (!start) {
   66:                 if ( initialized == FALSE ) goto fin0; 
   67:                 goto fin3;
   68:         }
   69:         if ( initialized != FALSE ) goto fin0; 
   70: 
   71:         er  = IICup(0, TRUE);
   72:         er |= IICup(1, TRUE);
   73:         if (er < E_OK) goto fin1;
   74: 
   75:         er  = SPIup(0, TRUE);
   76:         er |= SPIup(1, TRUE);
   77:         er |= SPIup(2, TRUE);
   78:         if (er < E_OK) goto fin2;
   79: 
   80:         /* register extended SVC */
   81:         dssy.ssyatr    = TA_NULL;
   82:         dssy.ssypri    = H8IO_PRI;
   83:         dssy.svchdr    = (FP)em1d512_iicspi_svcentry;
   84:         dssy.breakfn   = NULL;
   85:         dssy.startupfn = NULL;
   86:         dssy.cleanupfn = NULL;
   87:         dssy.eventfn   = NULL;
   88:         dssy.resblksz  = 0;
   89:         er = tk_def_ssy(H8IO_SVC, &dssy);
   90:         if (er < E_OK) goto fin3;
   91: 
   92:         initialized = TRUE;
   93:         er = E_OK;     
   94:         goto fin0;
   95: 
   96: fin3:
   97:         tk_def_ssy(H8IO_SVC, NULL);
   98: fin2:
   99:         SPIup(2, FALSE);
  100:         SPIup(1, FALSE);
  101:         SPIup(0, FALSE);
  102: fin1:
  103:         IICup(1, FALSE);
  104:         IICup(0, FALSE);
  105: fin0:
  106:         return er;
  107: }