Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

clib/i2c_api.c

Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 * (C) 2000 by PWR Solutions GbR
00004 *
00005 *  PWR Solutions GbR
00006 *  Euckenstrasse 17
00007 *  D-81369 München
00008 *
00009 *  Phone : (49)-89-726092-30
00010 *  Fax   : (49)-89-726092-59
00011 *
00012 * ---------------------------------------------------------------------------
00013 * Module        : I2C_API.C
00014 * Function      : I2C API
00015 *
00016 * Compiler      : Borland C++ 5.0
00017 * Memorymodel   : Large
00018 *
00019 * Author        : Bernhard Roth
00020 * Date          : 17.07.00
00021 * ---------------------------------------------------------------------------
00022 
00023 $Header: i2c_api.c, 6, 16.01.2002 11:45:04, Christoph Stoidner$
00024 
00025 
00026 $Log:
00027  6    IPC@CHIP  1.5         16.01.2002 11:45:04  Christoph Stoidner add starteam
00028       directives
00029  5    IPC@CHIP  1.4         16.01.2002 11:11:07  Christoph Stoidner add starteam
00030       directives
00031  4    IPC@CHIP  1.3         16.01.2002 11:09:08  Christoph Stoidner add new
00032       functions and comments
00033  3    IPC@CHIP  1.2         13.08.2001 17:06:36  Christoph Stoidner Edit header
00034  2    IPC@CHIP  1.1         13.08.2001 16:29:06  Christoph Stoidner edit
00035  1    IPC@CHIP  1.0         13.08.2001 16:26:59  Christoph Stoidner
00036 $
00037 
00038 *
00039 * History       :
00040 *
00041 *  Vx.yy                   Author                Changes
00042 *
00043 *             17.07.00     roth                  Create
00044 *
00045 *  -------------------------------------------------------------------------
00046 *  Published on the Beck WebSite with kindlier permission of Bernhard Roth.
00047 ****************************************************************************/
00048 
00049 
00050 
00051 /****************************************************************************/
00052 //includes
00053 /****************************************************************************/
00054 
00055 #include <dos.h>
00056 #include <stdio.h>
00057 #include "I2C_API.H"
00058 
00059 
00060 /*************************************************************************/
00061 //Init the I2C Interface
00062 /*************************************************************************/
00063 void I2C_init (void)
00064 {
00065   union  REGS  inregs;
00066   union  REGS  outregs;
00067 
00068 
00069   inregs.h.ah = I2C_INIT;
00070 
00071   int86(I2CINT,&inregs,&outregs);
00072 
00073 }
00074 
00075 /*************************************************************************/
00076 //Release I2C bus
00077 /*************************************************************************/
00078 void I2C_release (void)
00079 {
00080   union  REGS  inregs;
00081   union  REGS  outregs;
00082 
00083 
00084   inregs.h.ah = I2C_RELEASE;
00085   inregs.h.al = 0;
00086   int86(I2CINT,&inregs,&outregs);
00087 
00088 }
00089 
00090 /*************************************************************************/
00091 //Restart I2C
00092 /*************************************************************************/
00093 void I2C_restart (void)
00094 {
00095  union  REGS  inregs;
00096  union  REGS  outregs;
00097 
00098  inregs.h.ah = I2C_RESTART;
00099  inregs.h.al = 0;
00100  int86(I2CINT,&inregs,&outregs);
00101 
00102 }
00103 
00104 
00105 /*************************************************************************/
00106 //Scan for interfaces on I2C
00107 /*************************************************************************/
00108 unsigned char I2C_scan (unsigned char start_addr, unsigned char end_addr)
00109 {
00110  union  REGS  inregs;
00111  union  REGS  outregs;
00112 
00113 
00114  inregs.h.ah = I2C_SCAN;
00115  inregs.h.al = start_addr;
00116  inregs.h.cl = end_addr;
00117  int86(I2CINT,&inregs,&outregs);
00118 
00119  return outregs.h.al;
00120 
00121 }
00122 
00123 /*************************************************************************/
00124 //Transmit Block
00125 /*************************************************************************/
00126 int I2C_transmit_block (unsigned char slave, char far * buffer, int length)
00127 {
00128  union  REGS  inregs;
00129  union  REGS  outregs;
00130  struct SREGS sregs;
00131 
00132  inregs.h.ah = I2C_TRANS_RECV_BLOCK;
00133  inregs.h.al = slave & 0xFE;
00134  inregs.x.cx = length;
00135  sregs.es    = FP_SEG(buffer);
00136  inregs.x.bx = FP_OFF(buffer);
00137  int86x(I2CINT,&inregs,&outregs,&sregs);
00138 
00139  if (outregs.x.flags & 0x01)
00140  {
00141   return outregs.h.al;
00142  }
00143 
00144  return 0;
00145 
00146 }
00147 
00148 /*************************************************************************/
00149 //Receive Block
00150 /*************************************************************************/
00151 int I2C_receive_block (unsigned char slave, char far * buffer, int length)
00152 {
00153  union  REGS  inregs;
00154  union  REGS  outregs;
00155  struct SREGS sregs;
00156 
00157 
00158  inregs.h.ah = I2C_TRANS_RECV_BLOCK;
00159  inregs.h.al = slave | 0x01;
00160  inregs.x.cx = length;
00161  sregs.es    = FP_SEG(buffer);
00162  inregs.x.bx = FP_OFF(buffer);
00163  int86x(I2CINT,&inregs,&outregs,&sregs);
00164 
00165  if (outregs.x.flags & 0x01)
00166  {
00167   return outregs.h.al;
00168  }
00169 
00170  return 0;
00171 
00172 }
00173 
00174 /*************************************************************************/
00175 //Transmit one character
00176 /*************************************************************************/
00177 int I2C_transmit_char (unsigned char slave, char c)
00178 {
00179  union  REGS  inregs;
00180  union  REGS  outregs;
00181 
00182  inregs.h.ah = I2C_TRANS_RECV_CHAR;
00183  inregs.h.al = slave & 0xFE;
00184  inregs.h.cl = c;
00185  int86(I2CINT,&inregs,&outregs);
00186 
00187  if (outregs.x.flags & 0x01)
00188  {
00189   return (int)outregs.h.al & 0x00FF;
00190  }
00191 
00192  return 0;
00193 }
00194 
00195 /*************************************************************************/
00196 //Receive one Character
00197 /*************************************************************************/
00198 int I2C_receive_char (unsigned char slave, char * c, unsigned char lastchar)
00199 {
00200  union  REGS  inregs;
00201  union  REGS  outregs;
00202 
00203  inregs.h.ah = I2C_TRANS_RECV_CHAR;
00204  inregs.h.al = slave | 0x01;
00205  if (lastchar)
00206  {
00207   inregs.h.cl = 1;     //want more characters
00208  }
00209  else
00210  {
00211   inregs.h.cl = 0;     //only one character
00212  }
00213  int86(I2CINT,&inregs,&outregs);
00214 
00215  if (outregs.x.flags & 0x01)
00216  {
00217   *c = 0;
00218   return (int)outregs.h.al & 0x00FF;
00219  }
00220 
00221  *c = (char)outregs.h.ch;
00222  return 0;
00223 }
00224 
00225 /*************************************************************************/
00226 //Select I2C Clock Pin
00227 /*************************************************************************/
00228 void I2C_select_clock_pin(unsigned char pio_no)
00229 {
00230  union  REGS  inregs;
00231  union  REGS  outregs;
00232 
00233  inregs.h.ah = I2C_SELECT_CLK_PIN;
00234  inregs.h.al = pio_no;
00235  int86(I2CINT,&inregs,&outregs);
00236 }
00237 
00238 /*************************************************************************/
00239 //Select I2C data Pin
00240 /*************************************************************************/
00241 void I2C_select_data_pin(unsigned char pio_no)
00242 {
00243  union  REGS  inregs;
00244  union  REGS  outregs;
00245 
00246  inregs.h.ah = I2C_SELECT_DATA_PIN;
00247  inregs.h.al = pio_no;
00248  int86(I2CINT,&inregs,&outregs);
00249 }

Generated on Sun Aug 4 21:47:27 2002 for k/os mp3v2 by doxygen1.2.16