source: svn/newcon3bcm2_21bu/dst/dhl/src/devices/dtqs22ddp101b/UserDefinedIIC2.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
  • Property svn:executable set to *
File size: 4.7 KB
Line 
1/********************************************************************
2* UserDefinedIIC.c
3* User Defined IIC Function
4* By yooheeyong 2010/02/20
5*********************************************************************/
6#include "DHL_OSAL.h"
7#include "DHL_DEV_Priv.h"
8
9#include "UserDefinedIIC2.h"
10
11#ifdef SEMCO_IIC
12        #include "lpt.h"
13        extern Ciic m_iic;  /* IIC ÀÎÅÍÆäÀ̽º °´Ã¼ ¼±¾ð */
14        extern int EXTERN_LPT_USB;
15    extern int bDisconnect;
16        extern BOOL bCheckUSB;
17
18    #define TRY_CONNECT_CNT   10 // 10¹ø±îÁö ¿¬°á ½Ãµµ
19        //20110810 USB
20        #include "CyAPIUser.h"
21#else
22
23#endif
24
25
26
27/* IIC initialization */
28void I2c_Init(void)
29{
30
31#ifdef SEMCO_IIC
32
33    int nTimeOut;
34    char msg[100]={0,};
35    int nPort,baudrate,data,stop,parity;
36
37        /* Semco IIC initialization */
38
39    if(EXTERN_LPT_USB == SEL_LPT)
40        {
41                if(bCheckUSB == TRUE)
42                {
43                        Cypress_USB_Close();
44                        bCheckUSB = FALSE;
45                }
46
47                #define LPTDELAY    4000
48                m_iic.I2cInit(LPTDELAY);
49        }else{
50                if(bCheckUSB == FALSE)
51                {
52                        double   retdval;
53                        char     rettxtBuffer[256];
54                        char    *rettxt;
55                        rettxt = rettxtBuffer;
56                       
57                        bCheckUSB = TRUE;
58                        //Cypress_USB_Open();
59                        Cypress_Configure("-i2c", "100khz", 0, &retdval, &rettxt);  /* at 400kHz SCL rate     */
60                }
61
62        }
63#else
64
65#endif
66
67}
68
69/* IIC Deinitialization */
70void I2c_DeInit(void)
71{
72#ifdef SEMCO_IIC
73    if(EXTERN_LPT_USB == SEL_USB)
74        {
75                if(bCheckUSB)
76                {
77                        bCheckUSB = FALSE;
78                        Cypress_USB_Close();
79                }
80        }
81
82#else
83
84
85#endif
86}
87
88/* MxL601 IIC Write */
89int MxL601_I2cWrite(unsigned char I2cSlaveAddr, unsigned char RegAddr, unsigned char RegData)
90{
91        int status = 0;//usb purpose
92
93#ifdef SEMCO_IIC
94        /* Semco IIC function */
95         if(EXTERN_LPT_USB == SEL_LPT)
96         {
97                m_iic.Semco_I2c_WriteBytes (I2cSlaveAddr,1,(unsigned int)RegAddr,&RegData,1);
98                status = I2C_OK;
99         }else{
100                //  Sleep(1);//for cypress
101            status =(I2C_RESULT)Cypress_USB_WriteI2C(I2cSlaveAddr>>1, 1, &RegAddr, 1, &RegData);
102         }
103
104#else
105        DHL_RESULT dhr = DHL_OK;
106       
107        DHL_OS_Printf("|%s| addr = %x, data = %x\n", __FUNCTION__, RegAddr, RegData);
108        dhr = dhl_i2c_write2(0, I2cSlaveAddr, RegAddr, &RegData, 1);
109        if (dhr != DHL_OK)
110        {
111                DHL_OS_Printf("|%s| fail to write tuner(chip_addr:0x%x).\n",
112                              __FUNCTION__, I2cSlaveAddr);
113        }
114#endif
115
116        return status;
117}
118
119/* MxL601 IIC Read */
120int MxL601_I2cRead(unsigned char I2cSlaveAddr, unsigned char RegAddr, unsigned char *DataPtr)
121{
122        unsigned char SendDatas[200]={0,};
123        int status = 0;//usb purpose
124        int addr=0;
125
126#ifdef SEMCO_IIC
127    /* Semco IIC function */
128         if(EXTERN_LPT_USB == SEL_LPT)
129         {
130                addr = 0xFB;
131                addr <<= 8;
132                addr |= RegAddr;
133                m_iic.Semco_I2c_ReadBytes(I2cSlaveAddr,2,(unsigned int)addr,DataPtr,1);
134                status = I2C_OK;
135         }else{
136                // Sleep(1);//for cypress
137                SendDatas[0] = 0xFB;
138        SendDatas[1] = RegAddr;
139                status = (I2C_RESULT)Cypress_USB_ReadI2C(I2cSlaveAddr>>1, 2,SendDatas, 1, DataPtr);
140         }
141
142#else
143        DHL_RESULT dhr = DHL_OK;
144        UINT16 SubAddr;
145       
146        SubAddr = 0xfb00 | RegAddr;
147        dhr = dhl_i2c_read3(0, I2cSlaveAddr, SubAddr, DataPtr, 1);
148        if (dhr != DHL_OK)
149        {
150                DHL_OS_Printf("|%s| fail to read tuner(chip_addr:0x%x).\n",
151                              __FUNCTION__, I2cSlaveAddr);
152        }
153#endif
154
155
156
157        return status;
158}
159
160
161
162/* TDA10024IIC Write */
163int TDA10024_I2cWrite(int tUnit,unsigned long AddrSize, unsigned char *pAddr, unsigned long WriteLen, unsigned char *pData)
164{
165        int status = 0;//usb purpose
166        unsigned char ChipAddr;
167       
168        ChipAddr = TDA10024_ADDRESS;
169
170#ifdef SEMCO_IIC
171        /* Semco IIC function */
172         if(EXTERN_LPT_USB == SEL_LPT)
173         {
174                m_iic.Semco_I2c_WriteBytes (ChipAddr,1,(unsigned int)*pAddr,pData,WriteLen);
175                status = I2C_OK;
176         }else{
177                //  Sleep(1);//for cypress
178            status =(I2C_RESULT)Cypress_USB_WriteI2C (ChipAddr>>1, 1, pAddr, WriteLen, pData);
179         }
180
181#else
182
183
184#endif 
185
186        return status;//return 0;
187}
188
189/* TDA10024 IIC Read */
190int TDA10024_I2cRead(int tUnit, unsigned long AddrSize, unsigned char *pAddr,  unsigned long ReadLen, unsigned char *pData)
191{
192        int status = 0;
193        unsigned char ChipAddr;
194       
195        ChipAddr = TDA10024_ADDRESS;
196
197#ifdef SEMCO_IIC
198        unsigned char ReadData;
199    /* Semco IIC function */
200         if(EXTERN_LPT_USB == SEL_LPT)
201         {
202                m_iic.Semco_I2c_ReadBytes(ChipAddr,1,(unsigned int)*pAddr,pData,ReadLen);
203                status = I2C_OK;
204         }else{
205                 // Sleep(1);//for cypress
206                 status = (I2C_RESULT)Cypress_USB_ReadI2C(ChipAddr>>1, 1, pAddr, ReadLen, pData);
207         }
208
209#else
210
211
212#endif
213
214        return status;
215}
216
217/* TDA10024 Wait time*/
218int TDA10024_Wait(int tUnit, unsigned long wTime)
219{
220
221  SemcoSleep(tUnit,wTime);
222
223  return 0;
224}
225
226int SemcoSleep(int tUnit, unsigned long wTime)
227{
228#ifdef SEMCO_IIC
229        Sleep(wTime);
230#else
231        DHL_OS_Delay(wTime);
232#endif
233        return 0;
234}
Note: See TracBrowser for help on using the repository browser.