; TASKING TriCore C compiler v1.5r1 Build 322 SN 00090364
; options: -e -A1 -g -O0 -Id:\ctri\include -s -N8 -zTC112_COR1 -zTC112_COR4
;          -zTC112_COR10 -zTC112_COR13 -zTC112_COR14 -zTC112_COR16 -zTC112_COR17
	.name	"i2c_bus"
	.symb	TOOL, "TASKING TriCore C compiler v1.5", 1
	.symb	TYPE, 256, "bit", 'g', 0, 1
	.symb	FILE, "i2c_bus.c"
; file "i2c_bus.c":
;    1 |/* ----- file I2C_BUS.C66 -----                                             */
;    2 |// Angepa�t zum Arbeiten mit 8- und 16- Bit Adressen f�r E�PROMS
;    3 |// SYS TEC Computer GmbH 1998
;    4 |// Dr. Jungandreas
;    5 |
;    6 |// Anpassung Initialisierung -as
;    7 |
;    8 |
;    9 |/* Use it for interfacing the devices connected to the I2C-bus              */
;   10 |
;   11 |#include "main.h"		// Typendefinitionen
	.symb	FILE, "main.h"
	.symb	TYPE, 257, "uword", 'T', #18
	.symb	FILE, "TC1775BRegs.h"
	.symb	ENDF
	.symb	FILE, "IO.H"
	.symb	ENDF
	.symb	FILE, "ASC0.H"
	.symb	TYPE, 258, "ushort", 'T', #5
	.symb	ENDF
	.symb	FILE, "ASC1.H"
	.symb	ENDF
	.symb	FILE, "CAN.H"
	.symb	TYPE, 259, "ubyte", 'T', #3
	.symb	TYPE, 260, 'Z', #3, 7
	.symb	TYPE, 262, 'S', 20,\
		 "usMsgCfg", #5, 0,\
		 "uwID", #18, 2,\
		 "uwMask", #18, 6,\
		 "ubData", #260, 10,\
		 "usCounter", #5, 18
	.symb	TYPE, 263, "TCAN_SWObj", 'T', #262
	.symb	ENDF
	.symb	ENDF
;   12 |#include "I2C_Hard.h"	// I2C Low-Level Routinen
	.symb	FILE, "I2C_Hard.h"
	.symb	ENDF
;   13 |
;   14 |// Defines
;   15 |#define  I2C_SUCCESSFUL                 0x00
;   16 |#define  I2C_CROSSING_PAGE_BOUNDARIES   0xFC
;   17 |#define  I2C_DATA_TO_LONG               0xFD
;   18 |#define  I2C_NO_ACKNOWLEDGE             0xFE
;   19 |#define  I2C_NOT_IMPLEMENTED            0xFF
;   20 |
;   21 |#define ADDR_8BIT  0        // Zugriff �ber 8 Bit Adresse
;   22 |#define ADDR_16BIT 1        // Zugriff �ber 16 Bit Adresse
;   23 |
;   24 |// Typendefinitionen
;   25 | typedef union
;   26 | {
;   27 |   WORD w;
;   28 |   struct
;   29 |     {
;   30 |     BYTE low;	   // 22.03.2002 low und high gedreht Schumann
;   31 |     BYTE high;
;   32 |     } b;
;   33 | }tWORD ;
;   34 |
;   35 |// Prototypen deklarationen
;   36 |void I2CStop(void);
;   37 |void I2CStart(void);
;   38 |BYTE I2CReceiveAck(void);
;   39 |void I2CWriteByte(BYTE TransferData);
;   40 |BYTE I2CReadByte(void);
;   41 |void I2CSendAck(void);
;   42 |void I2CSendBit(BYTE State);
;   43 |BYTE I2CReceiveBit(void);
;   44 |/****************************************************************************/
;   45 |/* drive bus in inactive state, reenable eventually locked SDA-line         */
;   46 |
;   47 |void I2CInit(void) {
	.sdecl	"code.i2c_bus",CODE
	.sect	"code.i2c_bus"
	.align	4
	.symb	LINE, 47
	.symb	TYPE, 264, 'X', 8, #1, 26, 0
	.symb	GFUN, "I2CInit", I2CInit, #264, 0, 0, 0
	.symb	ALAB, I2CInit, #264
I2CInit:
	.symb	SOFF, 0
;   48 |
;   49 |  while (!I2CGetSDA())                /* read SDA state                    */
	.symb	LINE, 49
	j	_18
_17:
;   50 |	{
;   51 |      I2CDelay();
	.symb	LINE, 51
	callg	I2CDelay
;   52 |      I2CPutSCL(0);                       /* release SCL                       */
	.symb	LINE, 52
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;   53 |      I2CDelay();
	.symb	LINE, 53
	callg	I2CDelay
;   54 |      I2CPutSCL(1);                       /* set SCL for the first time        */
	.symb	LINE, 54
	mov16	d4,#1				; 1
	callg	I2CPutSCL
;   55 |      I2CDelay();
	.symb	LINE, 55
	callg	I2CDelay
;   56 |      I2CPutSCL(0);                       /* release SCL                       */
	.symb	LINE, 56
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;   57 |      I2CDelay();
	.symb	LINE, 57
	callg	I2CDelay
	.symb	LINE, 49
_18:
	callg	I2CGetSDA
	jeq	d2,#0,_17
;   58 |	}
;   59 |
;   60 |   I2CStop();
	.symb	LINE, 60
	callg	I2CStop
;   61 |
;   62 |
;   63 |/* re-enable SDA-line                                                       */
;   64 |// Die folgende Sequenzen Unterstuetzen nicht einen 
;   65 |// korrekten Anlauf, wenn w�hrend eines Lesezugriff 
;   66 |// der Master zur�ckgesetzt wurde. SDA kann dann dauerhaft
;   67 |// auf Low bleiben. -as
;   68 |
;   69 |//   I2CDelay();
;   70 |//   I2CPutSCL(0);                       /* preset SCL=0 to avoid accidential */
;   71 |//                                       /* transmission of START condition   */
;   72 |//                                       /* by following SDA-transition       */
;   73 |//   I2CDelay();
;   74 |//   I2CPutSDA(0);                       /* drive SDA to inactive state       */
;   75 |//   I2CDelay();
;   76 |//   I2CPutSCL(1);                       /* set SCL for the first time        */
;   77 |//   I2CDelay();
;   78 |//   I2CPutSCL(0);                       /* release SCL                       */
;   79 |//   I2CDelay();
;   80 |//   I2CPutSCL(1);                       /* set SCL for the second time       */
;   81 |//   I2CDelay();
;   82 |//   I2CPutSCL(0);                       /* release SCL                       */
;   83 |//   I2CDelay();
;   84 |//   I2CPutSCL(1);                       /* set SCL for the third time        */
;   85 |//
;   86 |///* I2C-bus is now going in the inactive state by the following commands     */
;   87 |//
;   88 |//   I2CDelay();
;   89 |//   I2CPutSDA(1);                       /* this is also the state after RESET*/
;   90 |//   I2CDelay();
;   91 |//   I2CPutSDA(1);                       /* setup SCL for START condition     */
;   92 |
;   93 |}
	.symb	LINE, 93
	ret16
	.symb	EFUN
;   94 |
;   95 |/****************************************************************************/
;   96 |/* writes a sequence of bytes to a device on I2C-bus                        */
;   97 |/*                                                                          */
;   98 |/*    *SourcePtr: Sourcepointer from RAM                                    */
;   99 |/*    DestAddr:   destination-address in I2C-device                         */
;  100 |/*    Size:       length of sequence                                        */
;  101 |/*    AddrType:   0 8 Bit Adresse                                           */
;  102 |/*                1 16Bit Adresse                                           */
;  103 |
;  104 |BYTE I2CWrite(BYTE FAR* SourcePtr, BYTE DeviceID, WORD DestAddr, WORD Size, BYTE AddrType)
;  105 |{
	.symb	LINE, 105
	.symb	TYPE, 265, 'S', 2,\
		 "low", #3, 0,\
		 "high", #3, 1
	.symb	TYPE, 266, 'U', 2,\
		 "w", #5, 0,\
		 "b", #265, 0
	.symb	TYPE, 267, "tWORD", 'T', #266
	.symb	TYPE, 270, 'P', #3
	.symb	TYPE, 268, 'X', 8, #3, 26, 5, #270, #3, #5, #5, #3
	.symb	GFUN, "I2CWrite", I2CWrite, #268, 0, 32, 0
	.symb	ALAB, I2CWrite, #268
I2CWrite:
	.symb	SOFF, 32
	.symb	LTIM, "Size", 6, 0, 0x8cd
	.symb	LTIM, "DeviceID", 4, 0, 0x8cd
	.symb	LTIM, "DestAddr", 5, 0, 0x8cd
	.symb	LTIM, "AddrType", 7, 0, 0x8cd
	.symb	LTIM, "SourcePtr", 20, 0, 0x8cd
	.symb	IDEN, "SourcePtr", 20, #270, 0, 0x80d
	.symb	IDEN, "DeviceID", 4, #3, 0, 0x80d
	.symb	IDEN, "DestAddr", 5, #5, 0, 0x80d
	.symb	IDEN, "Size", 6, #5, 0, 0x80d
	.symb	IDEN, "AddrType", 7, #3, 0, 0x80d
	.symb	IDEN, "Result", -12, #3, 131, 0x5
	.symb	IDEN, "lDestAddr", -8, #266, 131, 0x5
	.symb	LTIM, "AddrType", 7, 0, 0x84d
	.symb	LTIM, "AddrType", -32, 131, 0x8c5
	.symb	LTIM, "Size", 6, 0, 0x84d
	.symb	LTIM, "Size", -28, 131, 0x8c5
	.symb	LTIM, "DestAddr", 5, 0, 0x84d
	.symb	LTIM, "DestAddr", -24, 131, 0x8c5
	.symb	LTIM, "DeviceID", 4, 0, 0x84d
	.symb	LTIM, "DeviceID", -20, 131, 0x8c5
	.symb	LTIM, "SourcePtr", 20, 0, 0x84d
	.symb	LTIM, "SourcePtr", -16, 131, 0x8c5
	.symb	LTIM, "DestAddr", -24, 131, 0x845
	.symb	LTIM, "DestAddr", 15, 0, 0x8cd
	.symb	LTIM, "DestAddr", 15, 0, 0x84d
	.symb	LTIM, "Size", -28, 131, 0x845
	.symb	LTIM, "Size", 15, 0, 0x8cd
	nop
	sub16.a	sp,#32
;  106 |   BYTE Result;
;  107 |   tWORD lDestAddr;
	.symb	LINE, 107
	st16.b	[sp],d7				; AddrType
	st.h	[sp]4,d6			; Size
	st.h	[sp]8,d5			; DestAddr
	st.b	[sp]12,d4			; DeviceID
	st.a	[sp]16,a4			; SourcePtr
;  108 |
;  109 |   lDestAddr.w=DestAddr;                 //f.j. neuer Basistyp
	.symb	LINE, 109
	ld.hu	d15,[sp]8			; DestAddr
	st16.h	[sp]24,d15
;  110 |
;  111 |   if(Size==0)
	.symb	LINE, 111
	ld.hu	d15,[sp]4			; Size
	jne	d15,#0,_19			; Size
;  112 |      return I2C_SUCCESSFUL;
	.symb	LINE, 112
	mov16	d2,#0				; 0
	ret16
_19:
	.symb	LTIM, "Size", 15, 0, 0x84d
	.symb	LTIM, "DeviceID", -20, 131, 0x845
	.symb	LTIM, "DeviceID", 4, 0, 0x8cd
	.symb	LTIM, "DeviceID", 4, 0, 0x84d
;  113 |
;  114 |   I2CStart();                         /* send START condition              */
	.symb	LINE, 114
	callg	I2CStart
;  115 |   I2CWriteByte( DeviceID & 0xFE); /* send ID with cleared RD/WR bit    */
	.symb	LINE, 115
	ld.bu	d4,[sp]12			; DeviceID
	and	d4,d4,#254
	extr.u	d4,d4,#0,#8
	callg	I2CWriteByte
;  116 |
;  117 |   if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) {
	.symb	LINE, 117
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_20			; Result
;  118 |                                       /* is device responding ?            */
;  119 |      I2CStop();
	.symb	LINE, 119
	callg	I2CStop
;  120 |      return(Result);
	.symb	LINE, 120
	ld.bu	d2,[sp]20			; Result
	ret16
;  121 |   }
	.symb	LINE, 121
_20:
	.symb	LTIM, "AddrType", -32, 131, 0x845
	.symb	LTIM, "AddrType", 15, 0, 0x8cd
	.symb	LTIM, "AddrType", 15, 0, 0x84d
;  122 |   if (AddrType)
	.symb	LINE, 122
	nop
	ld16.bu	d15,[sp]			; AddrType
	jeq	d15,#0,_23			; AddrType
;  123 |   {                         //f.j. 16-Bit Adresse
;  124 |        I2CWriteByte(lDestAddr.b.high);      /*f.j. write destination address high  */
	.symb	LINE, 124
	ld.bu	d4,[sp]25
	callg	I2CWriteByte
;  125 |
;  126 |        if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) 
	.symb	LINE, 126
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_21			; Result
;  127 |        {
;  128 |            I2CStop();
	.symb	LINE, 128
	callg	I2CStop
;  129 |            return(Result);
	.symb	LINE, 129
	ld.bu	d2,[sp]20			; Result
	ret16
;  130 |        }
	.symb	LINE, 130
_21:
;  131 |        I2CWriteByte(lDestAddr.b.low);             /*f.j. write destination address low   */
	.symb	LINE, 131
	nop
	ld.bu	d4,[sp]24
	callg	I2CWriteByte
;  132 |        if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) 
	.symb	LINE, 132
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_22			; Result
;  133 |        {
;  134 |                I2CStop();
	.symb	LINE, 134
	callg	I2CStop
;  135 |                return(Result);
	.symb	LINE, 135
	ld.bu	d2,[sp]20			; Result
	ret16
;  136 |        }
	.symb	LINE, 136
_22:
;  137 |    }//End if (AddrType)
	.symb	LINE, 137
	j	_25
_23:
;  138 |    else //f.j. 8-Bit Adresse
;  139 |    {
;  140 |        I2CWriteByte(lDestAddr.b.low);             /*f.j. write destination address low   */
	.symb	LINE, 140
	nop
	ld.bu	d4,[sp]24
	callg	I2CWriteByte
;  141 |        if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) 
	.symb	LINE, 141
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_24			; Result
;  142 |        {
;  143 |                I2CStop();
	.symb	LINE, 143
	callg	I2CStop
;  144 |                return(Result);
	.symb	LINE, 144
	ld.bu	d2,[sp]20			; Result
	ret16
;  145 |        }
	.symb	LINE, 145
_24:
;  146 |    
;  147 |    } //End else
	.symb	LINE, 147
_25:
;  148 |    
;  149 |   while(Size--) {                     /* loop until all bytes send         */
	.symb	LINE, 149
	j	_28
_26:
	.symb	LTIM, "SourcePtr", -16, 131, 0x845
	.symb	LTIM, "SourcePtr", 31, 0, 0x8cd
	.symb	LTIM, "SourcePtr", 31, 0, 0x84d
	.symb	LTIM, "SourcePtr", 23, 0, 0x8cd
	.symb	LTIM, "SourcePtr", 23, 0, 0x84d
	.symb	LTIM, "SourcePtr", 23, 0, 0x8cd
	.symb	LTIM, "SourcePtr", 23, 0, 0x84d
	.symb	LTIM, "SourcePtr", -16, 131, 0x8c5
;  150 |      I2CWriteByte( *SourcePtr++ );
	.symb	LINE, 150
	nop
	ld16.a	a15,[sp]16			; SourcePtr
	ld16.bu	d4,[a15]
	callg	I2CWriteByte
	ld.a	a7,[sp]16			; SourcePtr
	add16.a	a7,#1				; SourcePtr
	st.a	[sp]16,a7			; SourcePtr
;  151 |
;  152 |      if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) {
	.symb	LINE, 152
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_27			; Result
;  153 |         I2CStop();
	.symb	LINE, 153
	callg	I2CStop
;  154 |         return(Result);
	.symb	LINE, 154
	ld.bu	d2,[sp]20			; Result
	ret16
;  155 |      }
	.symb	LINE, 155
_27:
	.symb	LINE, 149
_28:
	.symb	LTIM, "Size", 15, 0, 0x8cd
	.symb	LTIM, "Size", 15, 0, 0x84d
	.symb	LTIM, "Size", 15, 0, 0x8cd
	.symb	LTIM, "Size", 15, 0, 0x84d
	.symb	LTIM, "Size", 7, 0, 0x8cd
	.symb	LTIM, "Size", 7, 0, 0x84d
	.symb	LTIM, "Size", -28, 131, 0x8c5
	nop
	ld.hu	d15,[sp]4			; Size
	ld.hu	d7,[sp]4			; Size
	add16	d7,#-1				; Size
	st.h	[sp]4,d7			; Size
	jne	d15,#0,_26			; Size
;  156 |   }
;  157 |
;  158 |   I2CStop();                          /* send STOP condition               */
	.symb	LINE, 158
	callg	I2CStop
;  159 |   return(I2C_SUCCESSFUL);             /* no error occured                  */
	.symb	LINE, 159
	mov16	d2,#0				; 0
;  160 |}
	.symb	LINE, 160
_34:
	ret16
	.symb	LTIM, "Size", -28, 131, 0x845
	.symb	LTIM, "SourcePtr", -16, 131, 0x845
	.symb	EFUN
;  161 |
;  162 |/****************************************************************************/
;  163 |/* reads a sequence of bytes from a device on I2C-bus                       */
;  164 |/*                                                                          */
;  165 |/*    *dest:   destination-pointer from RAM                                 */
;  166 |/*    source:  source-address in I2C-device                                 */
;  167 |/*    length:  length of sequence                                           */
;  168 |/*    AddrType:   0 8 Bit Adresse                                           */
;  169 |/*                1 16Bit Adresse                                           */
;  170 |
;  171 |BYTE I2CRead(BYTE FAR* DestPtr, BYTE DeviceID, WORD SourceAddr, WORD Size, BYTE AddrType)
;  172 |{
	.symb	LINE, 172
	.symb	TYPE, 271, 'X', 8, #3, 26, 5, #270, #3, #5, #5, #3
	.symb	GFUN, "I2CRead", I2CRead, #271, 0, 32, 0
	.symb	ALAB, I2CRead, #271
I2CRead:
	.symb	SOFF, 32
	.symb	LTIM, "DeviceID", 4, 0, 0x8cd
	.symb	LTIM, "SourceAddr", 5, 0, 0x8cd
	.symb	LTIM, "AddrType", 7, 0, 0x8cd
	.symb	LTIM, "DestPtr", 20, 0, 0x8cd
	.symb	LTIM, "Size", 6, 0, 0x8cd
	.symb	IDEN, "DestPtr", 20, #270, 0, 0x80d
	.symb	IDEN, "DeviceID", 4, #3, 0, 0x80d
	.symb	IDEN, "SourceAddr", 5, #5, 0, 0x80d
	.symb	IDEN, "Size", 6, #5, 0, 0x80d
	.symb	IDEN, "AddrType", 7, #3, 0, 0x80d
	.symb	IDEN, "Result", -12, #3, 131, 0x5
	.symb	IDEN, "lSourceAddr", -8, #266, 131, 0x5
	.symb	LTIM, "AddrType", 7, 0, 0x84d
	.symb	LTIM, "AddrType", -32, 131, 0x8c5
	.symb	LTIM, "Size", 6, 0, 0x84d
	.symb	LTIM, "Size", -28, 131, 0x8c5
	.symb	LTIM, "SourceAddr", 5, 0, 0x84d
	.symb	LTIM, "SourceAddr", -24, 131, 0x8c5
	.symb	LTIM, "DeviceID", 4, 0, 0x84d
	.symb	LTIM, "DeviceID", -20, 131, 0x8c5
	.symb	LTIM, "DestPtr", 20, 0, 0x84d
	.symb	LTIM, "DestPtr", -16, 131, 0x8c5
	.symb	LTIM, "SourceAddr", -24, 131, 0x845
	.symb	LTIM, "SourceAddr", 15, 0, 0x8cd
	.symb	LTIM, "SourceAddr", 15, 0, 0x84d
	.symb	LTIM, "DeviceID", -20, 131, 0x845
	.symb	LTIM, "DeviceID", 4, 0, 0x8cd
	.symb	LTIM, "DeviceID", 4, 0, 0x84d
	nop
	sub16.a	sp,#32
;  173 |   BYTE Result;
;  174 |   tWORD lSourceAddr;
	.symb	LINE, 174
	st16.b	[sp],d7				; AddrType
	st.h	[sp]4,d6			; Size
	st.h	[sp]8,d5			; SourceAddr
	st.b	[sp]12,d4			; DeviceID
	st.a	[sp]16,a4			; DestPtr
;  175 |
;  176 |   lSourceAddr.w=SourceAddr;                 //f.j. neuer Basistyp
	.symb	LINE, 176
	ld.hu	d15,[sp]8			; SourceAddr
	st16.h	[sp]24,d15
;  177 |
;  178 |   I2CStart();                         /* send START condition              */
	.symb	LINE, 178
	callg	I2CStart
;  179 |   I2CWriteByte( DeviceID&0xFE );      /* send ID with cleared RD/WR bit    */
	.symb	LINE, 179
	ld.bu	d4,[sp]12			; DeviceID
	and	d4,d4,#254
	extr.u	d4,d4,#0,#8
	callg	I2CWriteByte
;  180 |
;  181 |   if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) {
	.symb	LINE, 181
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_35			; Result
;  182 |				       /* is device responding ?            */
;  183 |      I2CStop();
	.symb	LINE, 183
	callg	I2CStop
;  184 |      return(Result);
	.symb	LINE, 184
	ld.bu	d2,[sp]20			; Result
	ret16
;  185 |   }
	.symb	LINE, 185
_35:
	.symb	LTIM, "AddrType", -32, 131, 0x845
	.symb	LTIM, "AddrType", 15, 0, 0x8cd
	.symb	LTIM, "AddrType", 15, 0, 0x84d
;  186 |   if(AddrType) ////f.j. 16-Bit Adressen
	.symb	LINE, 186
	nop
	ld16.bu	d15,[sp]			; AddrType
	jeq	d15,#0,_38			; AddrType
;  187 |   {
;  188 |	I2CWriteByte(lSourceAddr.b.high);           /*f.j. write source address high    */
	.symb	LINE, 188
	ld.bu	d4,[sp]25
	callg	I2CWriteByte
;  189 |	if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL)
	.symb	LINE, 189
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_36			; Result
;  190 |	{
;  191 |	    I2CStop();
	.symb	LINE, 191
	callg	I2CStop
;  192 |	    return(Result);
	.symb	LINE, 192
	ld.bu	d2,[sp]20			; Result
	ret16
;  193 |	}
	.symb	LINE, 193
_36:
;  194 |
;  195 |	I2CWriteByte(lSourceAddr.b.low);           /* write source address low */
	.symb	LINE, 195
	nop
	ld.bu	d4,[sp]24
	callg	I2CWriteByte
;  196 |	if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL)
	.symb	LINE, 196
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_37			; Result
;  197 |	{
;  198 |	    I2CStop();
	.symb	LINE, 198
	callg	I2CStop
;  199 |	    return(Result);
	.symb	LINE, 199
	ld.bu	d2,[sp]20			; Result
	ret16
;  200 |	}
	.symb	LINE, 200
_37:
;  201 |   }//End if (AddrType)
	.symb	LINE, 201
	j	_40
_38:
;  202 |   else //f.j. 8-Bit Adressen
;  203 |   {
;  204 |	I2CWriteByte(lSourceAddr.b.low);           /* write source address low */
	.symb	LINE, 204
	nop
	ld.bu	d4,[sp]24
	callg	I2CWriteByte
;  205 |	if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL)
	.symb	LINE, 205
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_39			; Result
;  206 |	{
;  207 |	    I2CStop();
	.symb	LINE, 207
	callg	I2CStop
;  208 |	    return(Result);
	.symb	LINE, 208
	ld.bu	d2,[sp]20			; Result
	ret16
;  209 |	}
	.symb	LINE, 209
_39:
;  210 |   }//End else
	.symb	LINE, 210
_40:
	.symb	LTIM, "DeviceID", 4, 0, 0x8cd
	.symb	LTIM, "DeviceID", 4, 0, 0x84d
;  211 |
;  212 |
;  213 |   I2CStart();                         /* send START condition              */
	.symb	LINE, 213
	callg	I2CStart
;  214 |   I2CWriteByte( DeviceID|0x01);       /* send ID with set RD/WR bit        */
	.symb	LINE, 214
	ld.bu	d4,[sp]12			; DeviceID
	or	d4,d4,#1
	extr.u	d4,d4,#0,#8
	callg	I2CWriteByte
;  215 |
;  216 |   if((Result = I2CReceiveAck()) != I2C_SUCCESSFUL) {
	.symb	LINE, 216
	callg	I2CReceiveAck
	st.b	[sp]20,d2			; Result
	jeq	d2,#0,_41			; Result
;  217 |      I2CStop();
	.symb	LINE, 217
	callg	I2CStop
;  218 |      return(Result);
	.symb	LINE, 218
	ld.bu	d2,[sp]20			; Result
	ret16
;  219 |   }
	.symb	LINE, 219
_41:
;  220 |
;  221 |   while(Size--) {                     /* loop until all data received      */
	.symb	LINE, 221
	j	_44
_42:
	.symb	LTIM, "DestPtr", -16, 131, 0x845
	.symb	LTIM, "DestPtr", 23, 0, 0x8cd
	.symb	LTIM, "DestPtr", 23, 0, 0x84d
	.symb	LTIM, "DestPtr", 23, 0, 0x8cd
	.symb	LTIM, "DestPtr", 23, 0, 0x84d
	.symb	LTIM, "DestPtr", 23, 0, 0x8cd
	.symb	LTIM, "DestPtr", 23, 0, 0x84d
	.symb	LTIM, "DestPtr", -16, 131, 0x8c5
	.symb	LTIM, "Size", -28, 131, 0x845
	.symb	LTIM, "Size", 15, 0, 0x8cd
	.symb	LTIM, "Size", 15, 0, 0x84d
;  222 |      *DestPtr++ = I2CReadByte();      /* read data                         */
	.symb	LINE, 222
	callg	I2CReadByte
	ld.a	a7,[sp]16			; DestPtr
	st16.b	[a7],d2				; DestPtr
	ld.a	a7,[sp]16			; DestPtr
	add16.a	a7,#1				; DestPtr
	st.a	[sp]16,a7			; DestPtr
;  223 |
;  224 |      if(Size)                         /* send ACK to slave except last time*/
	.symb	LINE, 224
	ld.hu	d15,[sp]4			; Size
	jeq	d15,#0,_43			; Size
;  225 |         I2CSendAck();
	.symb	LINE, 225
	callg	I2CSendAck
_43:
	.symb	LINE, 221
_44:
	.symb	LTIM, "Size", 15, 0, 0x8cd
	.symb	LTIM, "Size", 15, 0, 0x84d
	.symb	LTIM, "Size", 15, 0, 0x8cd
	.symb	LTIM, "Size", 15, 0, 0x84d
	.symb	LTIM, "Size", 7, 0, 0x8cd
	.symb	LTIM, "Size", 7, 0, 0x84d
	.symb	LTIM, "Size", -28, 131, 0x8c5
	nop
	ld.hu	d15,[sp]4			; Size
	ld.hu	d7,[sp]4			; Size
	add16	d7,#-1				; Size
	st.h	[sp]4,d7			; Size
	jne	d15,#0,_42			; Size
;  226 |   }
;  227 |
;  228 |   I2CStop();                          /* send STOP condition               */
	.symb	LINE, 228
	callg	I2CStop
;  229 |   return(I2C_SUCCESSFUL);             /* no error occured                  */
	.symb	LINE, 229
	mov16	d2,#0				; 0
;  230 |}
	.symb	LINE, 230
_49:
	ret16
	.symb	LTIM, "Size", -28, 131, 0x845
	.symb	LTIM, "DestPtr", -16, 131, 0x845
	.symb	EFUN
;  231 |
;  232 |/****************************************************************************/
;  233 |/* sends START condition on I2C-bus                                         */
;  234 |
;  235 |void I2CStart(void) {
	.symb	LINE, 235
	.symb	TYPE, 272, 'X', 8, #1, 26, 0
	.symb	GFUN, "I2CStart", I2CStart, #272, 0, 0, 0
	.symb	ALAB, I2CStart, #272
I2CStart:
	.symb	SOFF, 0
;  236 |
;  237 |   I2CDelay();
	.symb	LINE, 237
	callg	I2CDelay
;  238 |   I2CPutSDA(1);                       /* this is also the idle bus state   */
	.symb	LINE, 238
	mov16	d4,#1				; 1
	callg	I2CPutSDA
;  239 |   I2CDelay();
	.symb	LINE, 239
	callg	I2CDelay
;  240 |   I2CPutSCL(1);                       /* this is also the idle bus state   */
	.symb	LINE, 240
	mov16	d4,#1				; 1
	callg	I2CPutSCL
;  241 |   I2CDelay();
	.symb	LINE, 241
	callg	I2CDelay
;  242 |   I2CPutSDA(0);                       /* generate START condition          */
	.symb	LINE, 242
	mov16	d4,#0				; 0
	callg	I2CPutSDA
;  243 |   I2CDelay();
	.symb	LINE, 243
	callg	I2CDelay
;  244 |   I2CPutSCL(0);                       /* drive SCL to inactive             */
	.symb	LINE, 244
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  245 |}
	.symb	LINE, 245
	ret16
	.symb	EFUN
;  246 |
;  247 |/****************************************************************************/
;  248 |/* sends STOP condition on I2C-bus                                          */
;  249 |
;  250 |void I2CStop(void) {
	.symb	LINE, 250
	.symb	TYPE, 273, 'X', 8, #1, 26, 0
	.symb	GFUN, "I2CStop", I2CStop, #273, 0, 0, 0
	.symb	ALAB, I2CStop, #273
I2CStop:
	.symb	SOFF, 0
;  251 |   I2CDelay();
	.symb	LINE, 251
	callg	I2CDelay
;  252 |   I2CPutSCL(0);                       /* setup SCL (redundant)             */
	.symb	LINE, 252
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  253 |   I2CDelay();
	.symb	LINE, 253
	callg	I2CDelay
;  254 |   I2CPutSDA(0);                       /* setup SDA (redundant)             */
	.symb	LINE, 254
	mov16	d4,#0				; 0
	callg	I2CPutSDA
;  255 |   I2CDelay();
	.symb	LINE, 255
	callg	I2CDelay
;  256 |   I2CPutSCL(1);                       /* setup SCL for STOP condition      */
	.symb	LINE, 256
	mov16	d4,#1				; 1
	callg	I2CPutSCL
;  257 |   I2CDelay();
	.symb	LINE, 257
	callg	I2CDelay
;  258 |   I2CPutSDA(1);                       /* generate STOP condition           */
	.symb	LINE, 258
	mov16	d4,#1				; 1
	callg	I2CPutSDA
;  259 |}
	.symb	LINE, 259
	ret16
	.symb	EFUN
;  260 |
;  261 |/****************************************************************************/
;  262 |/* sends ACKNOWLEDGE condition, i.e. sends an bit-value=0                   */
;  263 |
;  264 |void I2CSendAck(void) {
	.symb	LINE, 264
	.symb	TYPE, 274, 'X', 8, #1, 26, 0
	.symb	GFUN, "I2CSendAck", I2CSendAck, #274, 0, 0, 0
	.symb	ALAB, I2CSendAck, #274
I2CSendAck:
	.symb	SOFF, 0
;  265 |   I2CSendBit(0);
	.symb	LINE, 265
	mov16	d4,#0				; 0
	callg	I2CSendBit
;  266 |}
	.symb	LINE, 266
	ret16
	.symb	EFUN
;  267 |
;  268 |/****************************************************************************/
;  269 |/* receives ACKNOWLEDGE condition, i.e. receives an bit-value=0             */
;  270 |
;  271 |BYTE I2CReceiveAck(void) {
	.symb	LINE, 271
	.symb	TYPE, 275, 'X', 8, #3, 26, 0
	.symb	GFUN, "I2CReceiveAck", I2CReceiveAck, #275, 0, 0, 0
	.symb	ALAB, I2CReceiveAck, #275
I2CReceiveAck:
	.symb	SOFF, 0
;  272 |
;  273 |
;  274 |
;  275 |   if (I2CReceiveBit() == 0)
	.symb	LINE, 275
	callg	I2CReceiveBit
	jne	d2,#0,_50
;  276 |      return(I2C_SUCCESSFUL);          /* must be 0 if device responds      */
	.symb	LINE, 276
	mov16	d2,#0				; 0
	ret16
_50:
;  277 |   else
;  278 |      return(I2C_NO_ACKNOWLEDGE);
	.symb	LINE, 278
	mov	d2,#254				; 254
;  279 |}
	.symb	LINE, 279
_51:
	ret16
	.symb	EFUN
;  280 |
;  281 |/****************************************************************************/
;  282 |/* sends one bit to I2C-bus, also used for sending ACKNOWLEDGE condition    */
;  283 |
;  284 |void I2CSendBit(BYTE State) {
	.symb	LINE, 284
	.symb	TYPE, 276, 'X', 8, #1, 26, 1, #3
	.symb	GFUN, "I2CSendBit", I2CSendBit, #276, 0, 16, 0
	.symb	ALAB, I2CSendBit, #276
I2CSendBit:
	.symb	SOFF, 16
	.symb	LTIM, "State", 4, 0, 0x8cd
	.symb	IDEN, "State", 4, #3, 0, 0x80d
	.symb	LTIM, "State", 4, 0, 0x84d
	.symb	LTIM, "State", -16, 131, 0x8c5
	.symb	LTIM, "State", -16, 131, 0x845
	.symb	LTIM, "State", 4, 0, 0x8cd
	.symb	LTIM, "State", 4, 0, 0x84d
	nop
	sub16.a	sp,#16
	st16.b	[sp],d4				; State
;  285 |   I2CDelay();
	.symb	LINE, 285
	callg	I2CDelay
;  286 |   I2CPutSCL(0);                       /* setup SCL (redundant)             */
	.symb	LINE, 286
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  287 |   I2CDelay();
	.symb	LINE, 287
	callg	I2CDelay
;  288 |   I2CPutSDA(State);                   /* setup SDA                         */
	.symb	LINE, 288
	ld16.bu	d4,[sp]				; State
	callg	I2CPutSDA
;  289 |   I2CDelay();
	.symb	LINE, 289
	callg	I2CDelay
;  290 |   I2CPutSCL(1);                       /* enable SDA writing                */
	.symb	LINE, 290
	mov16	d4,#1				; 1
	callg	I2CPutSCL
;  291 |
;  292 |   I2CDelay();                         /* let SCL get stabilized High       */
	.symb	LINE, 292
	callg	I2CDelay
;  293 |
;  294 |   while(!I2CGetSCL());                /* wait until SCL-line is released   */
	.symb	LINE, 294
	j	_53
_52:
_53:
_54:
	callg	I2CGetSCL
	jeq	d2,#0,_54
;  295 |
;  296 |   I2CDelay();
	.symb	LINE, 296
	callg	I2CDelay
;  297 |   I2CPutSCL(0);                       /* disable SDA writing (SDA is now   */
	.symb	LINE, 297
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  298 |                                       /* clocked)                          */
;  299 |   I2CDelay();
	.symb	LINE, 299
	callg	I2CDelay
;  300 |   I2CPutSDA(1);                       /* release SDA */
	.symb	LINE, 300
	mov16	d4,#1				; 1
	callg	I2CPutSDA
;  301 |}
	.symb	LINE, 301
	ret16
	.symb	EFUN
;  302 |
;  303 |/****************************************************************************/
;  304 |/* receives one bit from I2C-bus, also used for receiving an ACKNOWLEDGE    */
;  305 |/* condition                                                                */
;  306 |
;  307 |BYTE I2CReceiveBit(void) {
	.symb	LINE, 307
	.symb	TYPE, 277, 'X', 8, #3, 26, 0
	.symb	GFUN, "I2CReceiveBit", I2CReceiveBit, #277, 0, 16, 0
	.symb	ALAB, I2CReceiveBit, #277
I2CReceiveBit:
	.symb	SOFF, 16
	.symb	IDEN, "State", -16, #3, 131, 0x5
	nop
	sub16.a	sp,#16
;  308 |   BYTE State;
;  309 |
;  310 |   I2CDelay();
	.symb	LINE, 310
	callg	I2CDelay
;  311 |   I2CPutSCL(0);                       /* setup SCL (redundant)             */
	.symb	LINE, 311
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  312 |   I2CDelay();
	.symb	LINE, 312
	callg	I2CDelay
;  313 |   I2CPutSDA(1);                       /* setup SDA for input (TRISTATE)    */
	.symb	LINE, 313
	mov16	d4,#1				; 1
	callg	I2CPutSDA
;  314 |   I2CDelay();
	.symb	LINE, 314
	callg	I2CDelay
;  315 |   I2CPutSCL(1);                       /* enable SDA reading                */
	.symb	LINE, 315
	mov16	d4,#1				; 1
	callg	I2CPutSCL
;  316 |
;  317 |   I2CDelay();                         /* let SCL get stabilized High       */
	.symb	LINE, 317
	callg	I2CDelay
;  318 |
;  319 |   while(!I2CGetSCL());                /* wait until SCL-line is released   */
	.symb	LINE, 319
	j	_56
_55:
_56:
_57:
	callg	I2CGetSCL
	jeq	d2,#0,_57
;  320 |
;  321 |   I2CDelay();
	.symb	LINE, 321
	callg	I2CDelay
;  322 |   State = I2CGetSDA();                /* read SDA state                    */
	.symb	LINE, 322
	callg	I2CGetSDA
	st16.b	[sp],d2				; State
;  323 |   I2CPutSCL(0);                       /* disable SDA reading (SDA is now   */
	.symb	LINE, 323
	mov16	d4,#0				; 0
	callg	I2CPutSCL
;  324 |                                       /* clocked)                          */
;  325 |   I2CDelay();
	.symb	LINE, 325
	callg	I2CDelay
;  326 |   return(State);                      /* return state */
	.symb	LINE, 326
	ld16.bu	d2,[sp]				; State
;  327 |}
	.symb	LINE, 327
_58:
	ret16
	.symb	EFUN
;  328 |
;  329 |/****************************************************************************/
;  330 |/* sends a byte to I2C-device                                               */
;  331 |
;  332 |void I2CWriteByte(BYTE TransferData) {
	.symb	LINE, 332
	.symb	TYPE, 278, 'X', 8, #1, 26, 1, #3
	.symb	GFUN, "I2CWriteByte", I2CWriteByte, #278, 0, 16, 0
	.symb	ALAB, I2CWriteByte, #278
I2CWriteByte:
	.symb	SOFF, 16
	.symb	LTIM, "TransferData", 4, 0, 0x8cd
	.symb	IDEN, "TransferData", 4, #3, 0, 0x80d
	.symb	IDEN, "Loop", -12, #3, 131, 0x5
	.symb	LTIM, "TransferData", 4, 0, 0x84d
	.symb	LTIM, "TransferData", -16, 131, 0x8c5
	nop
	sub16.a	sp,#16
;  333 |   BYTE Loop;
	.symb	LINE, 333
	st16.b	[sp],d4				; TransferData
;  334 |
;  335 |   for(Loop = 0; Loop <= 7; Loop++) {
	.symb	LINE, 335
	mov16	d15,#0				; Loop
	st16.b	[sp]4,d15			; Loop
	j	_60
_59:
	.symb	LTIM, "TransferData", -16, 131, 0x845
	.symb	LTIM, "TransferData", 4, 0, 0x8cd
	.symb	LTIM, "TransferData", 4, 0, 0x84d
	.symb	LTIM, "TransferData", 15, 0, 0x8cd
	.symb	LTIM, "TransferData", 15, 0, 0x84d
	.symb	LTIM, "TransferData", -16, 131, 0x8c5
;  336 |      I2CSendBit((TransferData & 0x80) == 0x80);
	.symb	LINE, 336
	nop
	ld16.bu	d4,[sp]				; TransferData
	and	d4,d4,#128
	eq	d4,d4,#0
	eq	d4,d4,#0
	extr.u	d4,d4,#0,#8
	callg	I2CSendBit
;  337 |      TransferData = (TransferData << 1);
	.symb	LINE, 337
	ld16.bu	d15,[sp]			; TransferData
	sh16	d15,#1				; TransferData
	st16.b	[sp],d15			; TransferData
	.symb	LINE, 335
	ld16.bu	d15,[sp]4			; Loop
	add16	d15,#1				; Loop
	st16.b	[sp]4,d15			; Loop
_60:
	nop
	ld16.bu	d15,[sp]4			; Loop
	lt	d15,d15,#8
	jne	d15,#0,_59
;  338 |   }
;  339 |}
	.symb	LINE, 339
	ret16
	.symb	LTIM, "TransferData", -16, 131, 0x845
	.symb	EFUN
;  340 |
;  341 |/****************************************************************************/
;  342 |/* reads a byte from I2C-device                                             */
;  343 |
;  344 |BYTE I2CReadByte(void) {
	.symb	LINE, 344
	.symb	TYPE, 279, 'X', 8, #3, 26, 0
	.symb	GFUN, "I2CReadByte", I2CReadByte, #279, 0, 16, 0
	.symb	ALAB, I2CReadByte, #279
I2CReadByte:
	.symb	SOFF, 16
	.symb	IDEN, "Value", -16, #3, 131, 0x5
	.symb	IDEN, "Loop", -12, #3, 131, 0x5
	nop
	sub16.a	sp,#16
;  345 |   BYTE Value, Loop;
;  346 |
;  347 |
;  348 |
;  349 |   Value = 0;
	.symb	LINE, 349
	mov16	d15,#0				; Value
	st16.b	[sp],d15			; Value
;  350 |
;  351 |   for(Loop = 0; Loop <= 7; Loop++) {
	.symb	LINE, 351
	mov16	d15,#0				; Loop
	st16.b	[sp]4,d15			; Loop
	j	_62
_61:
;  352 |      Value = (Value << 1);            /* 1. shift doesn't affect (value=0) */
	.symb	LINE, 352
	nop
	ld16.bu	d15,[sp]			; Value
	sh16	d15,#1				; Value
	st16.b	[sp],d15			; Value
;  353 |      Value = Value | I2CReceiveBit();
	.symb	LINE, 353
	ld16.bu	d14,[sp]			; Value
	callg	I2CReceiveBit
	or16	d14,d2				; Value
	st16.b	[sp],d14			; Value
	.symb	LINE, 351
	ld16.bu	d15,[sp]4			; Loop
	add16	d15,#1				; Loop
	st16.b	[sp]4,d15			; Loop
_62:
	nop
	ld16.bu	d15,[sp]4			; Loop
	lt	d15,d15,#8
	jne	d15,#0,_61
;  354 |   }
;  355 |
;  356 |   return(Value);                      /* return byte read                  */
	.symb	LINE, 356
	ld16.bu	d2,[sp]				; Value
;  357 |}
	.symb	LINE, 357
_63:
	ret16
	.symb	EFUN
;  358 |
;  359 |/****************************************************************************/
;  360 |
;  361 |
;  362 |
;  363 |// EOF
;  364 |
	.symb	ENDF
	.symb	TYPE, 280, 'X', 8, #3, 26, 0
	.symb	ALAB, I2CGetSCL, #280
	.symb	TYPE, 281, 'X', 8, #1, 26, 1, #3
	.symb	ALAB, I2CPutSDA, #281
	.symb	TYPE, 282, 'X', 8, #1, 26, 0
	.symb	ALAB, I2CDelay, #282
	.symb	TYPE, 283, 'X', 8, #3, 26, 0
	.symb	ALAB, I2CGetSDA, #283
	.symb	TYPE, 284, 'X', 8, #1, 26, 1, #3
	.symb	ALAB, I2CPutSCL, #284
	.global	I2CInit
	.global	I2CRead
	.global	I2CReadByte
	.global	I2CReceiveAck
	.global	I2CReceiveBit
	.global	I2CSendAck
	.global	I2CSendBit
	.global	I2CStart
	.global	I2CStop
	.global	I2CWrite
	.global	I2CWriteByte
	.extern	(CODE) I2CDelay
	.extern	(CODE) I2CGetSCL
	.extern	(CODE) I2CGetSDA
	.extern	(CODE) I2CPutSCL
	.extern	(CODE) I2CPutSDA
	.calls	"I2CInit", "I2CDelay"
	.calls	"I2CInit", "I2CGetSDA"
	.calls	"I2CInit", "I2CPutSCL"
	.calls	"I2CInit", "I2CStop"
	.calls	"I2CRead", "I2CReadByte"
	.calls	"I2CRead", "I2CReceiveAck"
	.calls	"I2CRead", "I2CSendAck"
	.calls	"I2CRead", "I2CStart"
	.calls	"I2CRead", "I2CStop"
	.calls	"I2CRead", "I2CWriteByte"
	.calls	"I2CReadByte", "I2CReceiveBit"
	.calls	"I2CReceiveAck", "I2CReceiveBit"
	.calls	"I2CReceiveBit", "I2CDelay"
	.calls	"I2CReceiveBit", "I2CGetSCL"
	.calls	"I2CReceiveBit", "I2CGetSDA"
	.calls	"I2CReceiveBit", "I2CPutSCL"
	.calls	"I2CReceiveBit", "I2CPutSDA"
	.calls	"I2CSendAck", "I2CSendBit"
	.calls	"I2CSendBit", "I2CDelay"
	.calls	"I2CSendBit", "I2CGetSCL"
	.calls	"I2CSendBit", "I2CPutSCL"
	.calls	"I2CSendBit", "I2CPutSDA"
	.calls	"I2CStart", "I2CDelay"
	.calls	"I2CStart", "I2CPutSCL"
	.calls	"I2CStart", "I2CPutSDA"
	.calls	"I2CStop", "I2CDelay"
	.calls	"I2CStop", "I2CPutSCL"
	.calls	"I2CStop", "I2CPutSDA"
	.calls	"I2CWrite", "I2CReceiveAck"
	.calls	"I2CWrite", "I2CStart"
	.calls	"I2CWrite", "I2CStop"
	.calls	"I2CWrite", "I2CWriteByte"
	.calls	"I2CWriteByte", "I2CSendBit"
