Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/drivers/i2c/i2cd.h

Go to the documentation of this file.
00001 /*  src_experimental/drivers/i2c/i2cd.h
00002     CubeOS Version 0.4.90 experimental
00003     Copyright (C) 1999,2000 Holger Kenn
00004 
00005     CubeOS is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or any later version.
00009 
00010     CubeOS is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015 */  
00016 
00017 #ifndef _I2CD_H
00018 #define _I2CD_H
00019 
00024 #include <ssem.h> /* for semaphores */
00025 
00026 #define I2C_MASTER 0
00027 #define I2C_SLAVE  1
00028 
00029 #define I2CA 0x41
00030 #define I2CB 0x42
00031 
00032 #define I2C_TIMEOUT_VAL 1000
00033 #define I2CA_SLAVE_ADDR 0x55
00034 #define I2CB_SLAVE_ADDR 0x56
00035 #define I2C_SPEED 0x1c
00036 
00037 #define I2C_MASTER_MODE 0
00038 #define I2C_SLAVE_MODE  1
00039 
00040 /* States in Master Mode */
00041 
00042 #define MASTER_IDLE              0
00043 #define MASTER_SEND              1
00044 #define MASTER_WAIT_ACK          2
00045 #define MASTER_RECV              3
00046 #define MASTER_RECV_LAST         4
00047 
00048 /* States in Slave Mode */
00049 
00050 #define SLAVE_IDLE           0
00051 #define SLAVE_SEND           1
00052 #define SLAVE_RECV           2
00053 
00054 
00055 #define MBUFLEN 10              /* num. mess. in master queue   */
00056 #define SBUFLEN 10              /* num. char in slave buffer    */
00057 
00058 /* Mnemonics for the return messages of the driver */
00059 
00060 #define I2C_NOT_PROCESSED       0        /* so far unprocessed messages    */
00061 #define I2C_OK                  1        /* transfer ended No Errors       */
00062 #define I2C_BUSY                2        /* transfer busy                  */
00063 #define I2C_ERR                 3        /* err: general error             */
00064 #define I2C_NACK_ON_DATA        4        /* err: No ack on data            */
00065 #define I2C_NACK_ON_ADDRESS     5        /* err: No ack on address         */
00066 #define I2C_ARBITRATION_LOST    6        /* err: Arbitration lost          */
00067 #define I2C_TIME_OUT            7        /* err: Time out occurred         */
00068 #define I2C_NO_BUS              8        /* err: No such i2c bus           */
00069 
00070 /* Flags for execeptions in slave handler */
00071 
00072 #define I2C_SLAVE_OBUF_EMPTY         1
00073 #define I2C_SLAVE_IBUF_OVERFLOW      2
00074 #define I2C_SLAVE_ERR                4
00075 
00080 struct i2cmess {
00081   unsigned char address;     
00082   unsigned char nrBytes;     
00083   unsigned char procBytes;   
00084   unsigned char *buf;        
00085   unsigned char status;      
00086 };
00087 
00088 
00093 struct  i2c {
00094   struct i2c_device *ioaddr;               
00095   int  mode;                               
00096   int  m_head;                             
00097   int  m_tail;                             
00098   struct i2cmess* m_buff[MBUFLEN];         
00099   ssem_t  m_sem;                           
00100   int  m_cnt;                              
00101   int  m_dcnt;                             
00102   void (*m_state_handler)(struct i2c *ptr);
00103   int  m_state;                            
00104   int  s_iptr;                             
00105   int  s_icnt;                             
00106   ssem_t  s_isem;                          
00107   char s_ibuff[SBUFLEN];                   
00108   int  s_optr;                             
00109   int  s_ocnt;                             
00110   ssem_t  s_osem;                          
00111   char s_obuff[SBUFLEN];                   
00112   void (*s_state_handler)(struct i2c *ptr);
00113   int  s_state;                            
00114   char s_status;                           
00115 };
00116 
00117 /* Interface functions */
00118 
00119 void I2C_inthandler(unsigned long minor);
00120 void _I2C_master_handler(struct i2c *p);
00121 void _I2C_slave_handler(struct i2c *p);
00122 int I2C_init(int which, unsigned long ioaddr);
00123 int I2C_process(unsigned char whichBus, unsigned char whichQueue, struct i2cmess *msg);
00124 int I2C_messagestatus(struct i2cmess * msg);
00125 int I2C_scanbus(unsigned char whichBus);
00126 extern struct i2c i2c[];
00127 
00128 /* externally defined assembler functions */
00129 
00130 void I2C_int_a(void);
00131 void I2C_int_b(void);
00132 #endif

Generated on Thu Feb 20 15:38:43 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002