gonzui


Format: Advanced Search

tkernel_2/include/device/em1d512_iic.hbare sourcepermlink (0.00 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_iic.h
   18:  *
   19:         IIC I/O interface definitions for EM1-D512
   20:  */
   21: 
   22: #ifndef __DEVICE_EM1D512_IIC_H__
   23: #define __DEVICE_EM1D512_IIC_H__
   24: 
   25: #include <basic.h>
   26: 
   27: #ifdef __cplusplus
   28: extern "C" {
   29: #endif
   30: 
   31: /*
   32:         IIC I/O
   33: 
   34: IMPORT  ER       em1d512_iicxfer(W ch, UH *cmddat, W words);
   35: 
   36:         send/receive data to/from IIC device
   37: 
   38:                 ch:     IIC Channel Number (0, 1)
   39:                 cmddat: pointer to the area to store command and sent/received data
   40:                 words:  word counts of command / data
   41: 
   42:                 return value:    E_OK or errors (E_IO, E_TMOUT, E_PAR)
   43: 
   44:         this should not be called from interrupt handler, or from state where interrupt is disabled.
   45: 
   46: 
   47:         command / data is described as follows.
   48: 
   49:         example 1)     one byte data is sent
   50:                 {
   51:                         IIC_START | (address << 1) | 0x00,   // R/W# = 0
   52:                         IIC_SEND  | IIC_TOPDATA  | IIC_LASTDATA | txdata0,
   53:                         IIC_STOP,
   54:                 }
   55: 
   56:                 data to be sent is stored in the lower 8 bits of the word that specifies IIC_SEND.
   57: 
   58: 
   59:         example 2) multiple bytes are sent
   60:                 {
   61:                         IIC_START | (address << 1) | 0x00,   // R/W# = 0
   62:                         IIC_SEND  | IIC_TOPDATA  | txdata0,
   63:                         IIC_SEND  |                txdata1
   64:                                 :
   65:                         IIC_SEND  | IIC_LASTDATA | txdataN,
   66:                         IIC_STOP,
   67:                 }
   68: 
   69:         example 3) send and receive is switched
   70:                 {
   71:                         IIC_START | (address << 1) | 0x00,   // R/W# = 0
   72:                         IIC_SEND  | IIC_TOPDATA  | IIC_LASTDATA | txdata0,
   73:                         IIC_START | (address << 1) | 0x01,   // R/W# = 1
   74:                         IIC_RECV  | IIC_TOPDATA,             // rxdata0
   75:                         IIC_RECV,                            // rxdata1
   76:                                 :
   77:                         IIC_RECV  | IIC_LASTDATA,            // rxdataN
   78:                         IIC_STOP,
   79:                 }
   80: 
   81:                 received data is stored into the lower 8 bits of the word that specifies IIC_RECV.
   82:                 (upper 8 bits remain the same.)
   83: */
   84: /*
   85:         SPI I/O
   86: 
   87: IMPORT  ER       em1d512_spixfer(W cs, UB *xmit, UB *recv, W len);
   88: 
   89:         perform send and/or receive to devices connected to SPI.
   90:         sending and receiving proceed concurrently.
   91: 
   92:                 cs:     communication target device (0 - 3)
   93:                         used SPI channel is specified by ORing the following values.
   94: 
   95:                                 SP0: 0x0000
   96:                                 SP1: 0x0100
   97:                                 SP2: 0x0200
   98:                 xmit:   pointer to the area which stores the data to be sent
   99:                 recv:   pointer to the area that stores the received data.
  100:                 len:    length of sent/received data (byte)
  101: 
  102:                 return value:    E_OK or errors (E_IO, E_TMOUT, E_PAR)
  103: 
  104:         this should not be called from interrupt handler, or from state where interrupt is disabled.
  105: 
  106: */
  107: 
  108: /*
  109:         definitions for automatic generation of interface library (mkiflib)
  110: */
  111: /*** DEFINE_IFLIB
  112: [INCLUDE FILE]
  113: <device/em1d512_iic.h>
  114: 
  115: [PREFIX]
  116: H8IO
  117: ***/
  118: 
  119: /*
  120:         service functions for IIC I/O
  121: */
  122: /* [BEGIN SYSCALLS] */
  123: 
  124: /* ORIGIN_NO 0x10 */
  125: IMPORT  ER       em1d512_iicxfer(W ch, UH *cmddat, W words);
  126: IMPORT  ER       em1d512_spixfer(W cs, UB *xmit, UB *recv, W len);
  127: /* [END SYSCALLS] */
  128: 
  129: #define IIC_START       (1 << 15)     // send START condition
  130: #define IIC_STOP        (1 << 14)      // send STOP condition
  131: #define IIC_SEND        (1 << 13)      // send data
  132: #define IIC_RECV        (1 << 12)      // receive data
  133: #define IIC_TOPDATA     (1 << 11)   // beginning of sent/received data
  134: #define IIC_LASTDATA    (1 << 10)  // end of sent/received data
  135: 
  136: /* Initailize service functions */
  137: IMPORT  ER       em1d512_iicspi_svc(BOOL start);
  138: 
  139: #ifdef __cplusplus
  140: }
  141: #endif
  142: #endif /* __DEVICE_EM1D512_IIC_H__ */