; 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_hard"
	.symb	TOOL, "TASKING TriCore C compiler v1.5", 1
	.symb	TYPE, 256, "bit", 'g', 0, 1
	.symb	FILE, "i2c_hard.c"
; file "i2c_hard.c":
;    1 |/* Use it for interfacing the devices connected to the I2C-bus */
;    2 |/* The functions of this file must be adapted to the underlaying hardware */
;    3 |
;    4 |/****************************************************************************
;    5 |
;    6 | Diese Datei ist f�r das Projekt phyCORE konfiguriert.
;    7 | Es werden verwendet:
;    8 |
;    9 |	SCL - I2C-Taktleitung   P8.0
;   10 |	SDA - I2C-Datenleitung	P8.1
;   11 |
;   12 | Es muessen nur noch die 3 folgenden Konstanten angepasst werden. Der
;   13 | Originalsource ist auskommentiert.
;   14 |
;   15 | ***************************************************************************/
;   16 |
;   17 |//#define I2C_PORT	    P1
;   18 |//#define I2C_SCL_MSK     0x40
;   19 |//#define I2C_SDA_MSK     0x80
;   20 |//#define I2C_SCL IO_P8_0
;   21 |//#define I2C_SDA IO_P8_1
;   22 |
;   23 |/***************************************************************************
;   24 |
;   25 | Die Laenge der Bitzeit wird mit Hilfe von zusaetzlich eingefuegten 
;   26 | Dummy-Befehlen generiert. Dadurch wird die Bitzeit jedoch abhaengig
;   27 | von der Quarzfrequenz und von der Ausfuehrungszeit pro Befehl des
;   28 | jeweiligen Microcontrollers. Nach der folgenden Beziehung kann die
;   29 | Bitzeit abgeschaetzt werden.
;   30 |
;   31 | BIT_TIME = (4 + BIT_DELAY) * Maschinenzyklus
;   32 |
;   33 | Die Dauer eines Maschinenzyklus ist abhaengig vom Microcontroller und dem
;   34 | verwendeten Quarz.
;   35 | Bei einem Standard-8051-Controller mit 12MHz-Quarz entspricht dieser
;   36 | Wert 1 Microsekunde. 
;   37 |
;   38 | 8051:      1000ns  bei 12MHz-Quarz
;   39 | C515C:     600ns   bei 10MHz-Quarz
;   40 | 80C591:    375ns   bei 16MHz-Quarz
;   41 |
;   42 | In der Auslieferungsvariante der I2C-Lib ist der Wert f�r die max. 
;   43 | Uebertragungsgeschwindigkeit gewaehlt worden. Fuer eine Reduzierung
;   44 | der Uebertragungsgeschwindigkeit kann die folgende Konstante erhoeht
;   45 | werden.
;   46 |
;   47 |****************************************************************************/
;   48 |#include "Main.h"
	.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
;   49 |#include "TC1775BRegs.h"
	.symb	FILE, "TC1775BRegs.h"
	.symb	ENDF
;   50 |#include "IO.h"
	.symb	FILE, "IO.h"
	.symb	ENDF
;   51 |
;   52 |#define BIT_DELAY    250   // Bereich 0-255      
;   53 |
;   54 |void I2CDelay(void)
;   55 |{
	.sdecl	"code.i2c_hard",CODE
	.sect	"code.i2c_hard"
	.align	4
	.symb	LINE, 55
	.symb	TYPE, 264, 'X', 8, #1, 26, 0
	.symb	GFUN, "I2CDelay", I2CDelay, #264, 0, 16, 0
	.symb	ALAB, I2CDelay, #264
I2CDelay:
	.symb	SOFF, 16
	.symb	IDEN, "Count", -16, #3, 131, 0x5
	nop
	sub16.a	sp,#16
;   56 |  BYTE  Count;                        /* loop-counting variable            */
;   57 |
;   58 |   // Fuer max. Geschwindigkeit leere Funktion definieren
;   59 |   for (Count=0; Count<BIT_DELAY; Count++);
	.symb	LINE, 59
	mov16	d15,#0				; Count
	st16.b	[sp],d15			; Count
	j	_18
_17:
	nop
	ld16.bu	d15,[sp]			; Count
	add16	d15,#1				; Count
	st16.b	[sp],d15			; Count
_18:
	nop
	ld16.bu	d15,[sp]			; Count
	lt	d15,d15,#250
	jne	d15,#0,_17
;   60 |
;   61 |}
	.symb	LINE, 61
	ret16
	.symb	EFUN
;   62 |
;   63 |/****************************************************************************/
;   64 |// End of adjusting area!!!
;   65 |/****************************************************************************/
;   66 |
;   67 |
;   68 |/****************************************************************************/
;   69 |// set SCL-line to desired state                                            
;   70 |
;   71 |void I2CPutSCL(BYTE State) {
	.symb	LINE, 71
	.symb	TYPE, 265, 'g', 0, 1
	.symb	TYPE, 266, 'g', 0, 1
	.symb	TYPE, 267, 'g', 0, 1
	.symb	TYPE, 268, 'g', 0, 1
	.symb	TYPE, 269, 'g', 0, 1
	.symb	TYPE, 270, 'g', 0, 1
	.symb	TYPE, 271, 'g', 0, 1
	.symb	TYPE, 272, 'g', 0, 1
	.symb	TYPE, 273, 'g', 0, 1
	.symb	TYPE, 274, 'g', 0, 1
	.symb	TYPE, 275, 'g', 0, 1
	.symb	TYPE, 276, 'g', 0, 1
	.symb	TYPE, 277, 'g', 0, 1
	.symb	TYPE, 278, 'g', 0, 1
	.symb	TYPE, 279, 'g', 0, 1
	.symb	TYPE, 280, 'g', 0, 1
	.symb	TYPE, 281, 'g', 0, 1
	.symb	TYPE, 282, 'g', 0, 1
	.symb	TYPE, 283, 'g', 0, 1
	.symb	TYPE, 284, 'g', 0, 1
	.symb	TYPE, 285, 'g', 0, 1
	.symb	TYPE, 286, 'g', 0, 1
	.symb	TYPE, 287, 'g', 0, 1
	.symb	TYPE, 288, 'g', 0, 1
	.symb	TYPE, 289, 'g', 0, 1
	.symb	TYPE, 290, 'g', 0, 1
	.symb	TYPE, 291, 'g', 0, 1
	.symb	TYPE, 292, 'g', 0, 1
	.symb	TYPE, 293, 'g', 0, 1
	.symb	TYPE, 294, 'g', 0, 1
	.symb	TYPE, 295, 'g', 0, 1
	.symb	TYPE, 296, 'g', 0, 1
	.symb	TYPE, 297, 'S', 4,\
		 "bit0", #265, 0,\
		 "bit1", #266, 1,\
		 "bit2", #267, 2,\
		 "bit3", #268, 3,\
		 "bit4", #269, 4,\
		 "bit5", #270, 5,\
		 "bit6", #271, 6,\
		 "bit7", #272, 7,\
		 "bit8", #273, 8,\
		 "bit9", #274, 9,\
		 "bit10", #275, 10,\
		 "bit11", #276, 11,\
		 "bit12", #277, 12,\
		 "bit13", #278, 13,\
		 "bit14", #279, 14,\
		 "bit15", #280, 15,\
		 "bit16", #281, 16,\
		 "bit17", #282, 17,\
		 "bit18", #283, 18,\
		 "bit19", #284, 19,\
		 "bit20", #285, 20,\
		 "bit21", #286, 21,\
		 "bit22", #287, 22,\
		 "bit23", #288, 23,\
		 "bit24", #289, 24,\
		 "bit25", #290, 25,\
		 "bit26", #291, 26,\
		 "bit27", #292, 27,\
		 "bit28", #293, 28,\
		 "bit29", #294, 29,\
		 "bit30", #295, 30,\
		 "bit31", #296, 31
	.symb	TYPE, 298, "T_Reg32", 'T', #297
	.symb	TYPE, 299, 'X', 8, #1, 26, 1, #3
	.symb	GFUN, "I2CPutSCL", I2CPutSCL, #299, 0, 16, 0
	.symb	ALAB, I2CPutSCL, #299
I2CPutSCL:
	.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", 15, 0, 0x8cd
	nop
	sub16.a	sp,#16
	st16.b	[sp],d4				; State
;   72 |
;   73 |
;   74 |   if(!State) {
	.symb	LINE, 74
	ld16.bu	d15,[sp]			; State
	jne	d15,#0,_19			; State
;   75 |
;   76 |//      I2C_PORT &= ~I2C_SCL_MSK;
;   77 |		IO_vResetPin(IO_P8_0);
	.symb	LINE, 77
	st.t	-268423152,#0,#0
;   78 |		IO_vSetPinOut(IO_P8_0);
	.symb	LINE, 78
	st.t	-268423144,#0,#1
;   79 |
;   80 |				       // enable output AFTER setting of    
;   81 |                       // correct level to avoid '1'-level  
;   82 |                       // spikes                            
;   83 |				       // set SCL-line to 0               
;   84 |
;   85 |   }
	.symb	LINE, 85
	ret16
_19:
;   86 |   else {
;   87 |                                       // this is possible because of the   
;   88 |                                       // external pull-up resistor !       
;   89 |	                                   // set SCL-line to 1               
;   90 |//	I2C_PORT |= I2C_SCL_MSK;
;   91 |//	IO_vSetPin(IO_P8_0);
;   92 |	IO_vSetPinIn(IO_P8_0);
	.symb	LINE, 92
	st.t	-268423144,#0,#0
;   93 |
;   94 |
;   95 |   }
	.symb	LINE, 95
_20:
;   96 |}
	.symb	LINE, 96
	ret16
	.symb	LTIM, "State", 15, 0, 0x84d
	.symb	EFUN
;   97 |
;   98 |/****************************************************************************/
;   99 |// read state of  SCL-line                                                  
;  100 |// WARNING: This function should be used only if SCL-line is in High-level !
;  101 |// (This function is for used only for realizing the Slow-Down-Mode)        
;  102 |
;  103 |BYTE I2CGetSCL(void) {
	.symb	LINE, 103
	.symb	TYPE, 300, 'X', 8, #3, 26, 0
	.symb	GFUN, "I2CGetSCL", I2CGetSCL, #300, 0, 0, 0
	.symb	ALAB, I2CGetSCL, #300
I2CGetSCL:
	.symb	SOFF, 0
;  104 |
;  105 |IO_vSetPinIn(IO_P8_0);
	.symb	LINE, 105
	st.t	-268423144,#0,#0
;  106 |//     if( I2C_PORT&I2C_SCL_MSK)
;  107 |	 if (IO_ubReadPin(IO_P8_0))
	.symb	LINE, 107
	ld.bu	d15,-268423148
	extr.u	d15,d15,#0,#1
	jeq	d15,#0,_21
;  108 |      return(1);                       // read SCL-line status              
	.symb	LINE, 108
	mov16	d2,#1				; 1
	ret16
_21:
;  109 |     else
;  110 |      return(0);
	.symb	LINE, 110
	mov16	d2,#0				; 0
;  111 |}
	.symb	LINE, 111
_22:
	ret16
	.symb	EFUN
;  112 |
;  113 |/****************************************************************************/
;  114 |/* set SDA-line to desired state                                            */
;  115 |
;  116 |void I2CPutSDA(BYTE State) {
	.symb	LINE, 116
	.symb	TYPE, 301, 'X', 8, #1, 26, 1, #3
	.symb	GFUN, "I2CPutSDA", I2CPutSDA, #301, 0, 16, 0
	.symb	ALAB, I2CPutSDA, #301
I2CPutSDA:
	.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", 15, 0, 0x8cd
	nop
	sub16.a	sp,#16
	st16.b	[sp],d4				; State
;  117 |
;  118 |   if(!State) {
	.symb	LINE, 118
	ld16.bu	d15,[sp]			; State
	jne	d15,#0,_23			; State
;  119 |                    /* set SDA-line to ZERO              */
;  120 |//      I2C_PORT &= ~I2C_SDA_MSK;
;  121 |		IO_vResetPin(IO_P8_1);
	.symb	LINE, 121
	st.t	-268423152,#1,#0
;  122 |		IO_vSetPinOut(IO_P8_1);
	.symb	LINE, 122
	st.t	-268423144,#1,#1
;  123 |				       /* enable output AFTER setting of    */
;  124 |				       /* correct level to avoid '1'-level  */
;  125 |				       /* spikes                            */
;  126 |   }
	.symb	LINE, 126
	ret16
_23:
;  127 |   else {
;  128 |				       /* this is possible because of the   */
;  129 |				       /* external pull-up resistor !       */
;  130 |                   /* set SDA-line to ONE               */
;  131 |//      I2C_PORT |= I2C_SDA_MSK;
;  132 |//		IO_vSetPin(IO_P8_1);
;  133 |		IO_vSetPinIn(IO_P8_1);
	.symb	LINE, 133
	st.t	-268423144,#1,#0
;  134 |
;  135 |   }
	.symb	LINE, 135
_24:
;  136 |}
	.symb	LINE, 136
	ret16
	.symb	LTIM, "State", 15, 0, 0x84d
	.symb	EFUN
;  137 |
;  138 |
;  139 |/****************************************************************************/
;  140 |/* read state of SDA-line                                                   */
;  141 |
;  142 |BYTE I2CGetSDA(void) {
	.symb	LINE, 142
	.symb	TYPE, 302, 'X', 8, #3, 26, 0
	.symb	GFUN, "I2CGetSDA", I2CGetSDA, #302, 0, 0, 0
	.symb	ALAB, I2CGetSDA, #302
I2CGetSDA:
	.symb	SOFF, 0
;  143 |
;  144 |IO_vSetPinIn(IO_P8_1);
	.symb	LINE, 144
	st.t	-268423144,#1,#0
;  145 |
;  146 |	 if (IO_ubReadPin(IO_P8_1))
	.symb	LINE, 146
	ld.bu	d15,-268423148
	extr.u	d15,d15,#1,#1
	jeq	d15,#0,_25
;  147 |       return(1);                      /* read SDA-line status              */
	.symb	LINE, 147
	mov16	d2,#1				; 1
	ret16
_25:
;  148 |     else
;  149 |       return(0);
	.symb	LINE, 149
	mov16	d2,#0				; 0
;  150 |}
	.symb	LINE, 150
_26:
	ret16
	.symb	EFUN
;  151 |/* ----- end I2C_HARD.C ----- */
	.symb	ENDF
	.global	I2CDelay
	.global	I2CGetSCL
	.global	I2CGetSDA
	.global	I2CPutSCL
	.global	I2CPutSDA
