/*---------------------------------------------------------------------------*/
tmErrorCode_t UserWrittenI2CWrite (tmUnitSelect_t tUnit,     UInt32 AddrSize, UInt8* pAddr,
UInt32 WriteLen, UInt8* pData)
{
   /* Variable declarations */
   tmErrorCode_t err = TM_OK;

/* Customer code here */
/* ...*/
	ptmOM3971Object_t  pObj = Null;
    Int      errI2C = 0;
    //Bool               bIncSubAddress = True;
    UInt8              uSubAddress = 0;
    UInt16             uSubAddress16 = 0;
    UInt32             uCounter = 0;
    UInt8              WriteBuffer[I2C_BUFFER_SIZE+1] = {0};
    UInt32             count = 0;
    UInt32             remain = 0;
    tmUnitSelect_t     tUnitOM3949 = GET_SYSTEM_TUNIT(tUnit);
	struct i2c_msg 					msgs[2];
	struct i2c_rdwr_ioctl_data 		ioctl_data;

    if(GET_XFER_DISABLED_FLAG_TUNIT(tUnit) == False)
    {
        err = OM3971GetInstance(tUnitOM3949, &pObj);
        tmASSERTExT(err, TM_OK, (DEBUGLVL_ERROR, "OM3971GetInstance(0x%08X) failed.", tUnit));

        if(err == TM_OK)
        {
            //if(pObj->uHwAddress[UNIT_PATH_TYPE_GET(tUnit)] != OM3949_INVALID_DEVICE_ADDRESS)
            {
	            switch(AddrSize)
	            {
		            default:
		            case 0:
		                uSubAddress = 0;
		                break;
		            case 1:
		                //uSubAddress = (*pAddr)&0xFF;//pAddr[0];
		                //WriteBuffer[0] = (*pAddr)&0xFF;
		                break;
		            case 2:
		                //uSubAddress16 = pAddr[1]<<8 | pAddr[0];
		                WriteBuffer[0] = pAddr[1];
						WriteBuffer[1] = pAddr[0];
		                break;
            	}
                for(count=0; count<WriteLen; count += remain)
                {
                    //remain = min(WriteLen-count, I2C_BUFFER_SIZE);
					if ( (WriteLen - count) > 127 )
					    remain = 127;
					else
						remain = WriteLen - count;
                    switch(AddrSize)
                    {
	                    default:
	                    case 0:
	                    case 1:
	                        /* copy I2CMap data in WriteBuffer */
	                        for (uCounter = 0; uCounter < remain; uCounter++)
	                        {
	                            WriteBuffer[uCounter] = pData[count+uCounter];
	                        }
	                        break;
	                    case 2:
	                        /* copy I2CMap data in WriteBuffer */
	                        for (uCounter = 0; uCounter < remain; uCounter+=2)
	                        {
	                            WriteBuffer[uCounter+2] = pData[count+uCounter+1];
	                            WriteBuffer[uCounter+3] = pData[count+uCounter];
	                        }
	                        break;
                    }

                    switch(UNIT_PATH_TYPE_GET(tUnit))
                    {
                        case tmOM3971UnitDeviceTypeTDA18250:
							errI2C = DRV_I2C_Write( DeviceTDA18250Addr, pAddr, AddrSize, WriteBuffer, remain);
                            break;

                        case tmOM3971UnitDeviceTypeTDA10025:							
							errI2C = DRV_I2C_Write( DeviceTDA10025Addr, pAddr, 0, WriteBuffer, (remain + AddrSize));
                            break;
                        default:
                            tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3971I2CWrite(0x%08X) failed. Unknown Device Type.", tUnit);
                            err = OM3971_ERR_BAD_PARAMETER;
                            break;
                    }

                    if( errI2C != 0 )
                    {
                        tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3949I2CWrite(0x%08X, [sub@0x%02x] %d/%d) failed.", tUnit, (pAddr[1] << 8)|pAddr[0], count, WriteLen);
                        err = OM3971_ERR_HW;
                    }

                    if(err != TM_OK)
                        break;
                    #if  0
                    if(bIncSubAddress)
                    {
                        uSubAddress = (UInt8)(uSubAddress+remain);
                        uSubAddress16 = (UInt16)(uSubAddress16+remain);
                    }
					#endif /* #if 0 */
                }
            }
        }
    }
/* ...*/
/* End of Customer code here */

   return err;
}
Beispiel #2
0
tmErrorCode_t tmsysOM3912I2CWrite(tmUnitSelect_t tUnit, UInt32 AddrSize, UInt8* pAddr, UInt32 WriteLen, UInt8* pData)
{
    ptmOM3912Object_t    pObj = Null;
    tmErrorCode_t           err = TM_OK;
    tmErrorCode_t           errI2C = TM_OK;
    Bool                    bIncSubAddress = True;
    UInt8                   uSubAddress = 0;
    UInt32                  uCounter = 0;
    UInt8                   WriteBuffer[I2C_BUFFER_SIZE+1] = {0};
    UInt32                  count = 0;
    UInt32                  remain = 0;
    tmUnitSelect_t          tUnitOM3912 = GET_SYSTEM_TUNIT(tUnit);

    if(GET_XFER_DISABLED_FLAG_TUNIT(tUnit) == False)
    {
        err = OM3912GetInstance(tUnitOM3912, &pObj);
        tmASSERTExT(err, TM_OK, (DEBUGLVL_ERROR, "OM3912GetInstance(0x%08X) failed.", tUnit));

        if(err == TM_OK)
        {
            if(pObj->uHwAddress[UNIT_PATH_TYPE_GET(tUnit)] != OM3912_INVALID_DEVICE_ADDRESS)
            {
                switch(AddrSize)
                {
                default:
                case 0:
                    uSubAddress = 0;
                    break;

                case 1:
                    uSubAddress = (*pAddr)&0xFF;
                    break;
                }

                /* Copy uSubAddress to first data byte */
                WriteBuffer[0] = uSubAddress;

                for(count=0; count<WriteLen; count += remain)
                {
                    remain = min(WriteLen-count, I2C_BUFFER_SIZE);

                    /* copy I2CMap data in WriteBuffer */
                    for (uCounter = 0; uCounter < remain; uCounter++)
                    {
                        WriteBuffer[uCounter+1] = pData[count+uCounter];
                    }

                    switch(UNIT_PATH_TYPE_GET(tUnit))
                    {
                    case tmOM3912UnitDeviceTypeTDA18273:
                        errI2C = tmdlI2CWrite(tUnit, pObj->uHwAddress[UNIT_PATH_TYPE_GET(tUnit)], AddrSize, &uSubAddress, remain, WriteBuffer+1);
                        break;

                    default:
                        tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3912I2CWrite(0x%08X) failed. Unknown Device Type.", tUnit);
                        err = OM3912_ERR_BAD_PARAMETER;
                        break;
                    }

                    if(errI2C != TM_OK)
                    {
                        tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3912I2CWrite(0x%08X, [sub@0x%02x] %d/%d) failed.", tUnit, uSubAddress, count, WriteLen);
                        err = OM3912_ERR_HW;
                    }

                    if(err != TM_OK)
                        break;

                    if(bIncSubAddress)
                    {
                        uSubAddress = (UInt8)(uSubAddress+remain);
                        WriteBuffer[0] = uSubAddress;
                    }
                }
            }
        }
    }

    return err;
}
/*----------------------------------------------------------------------------*/
tmErrorCode_t UserWrittenI2CRead
				(
					tmUnitSelect_t tUnit,    
					UInt32 AddrSize, 
					UInt8* pAddr,
					UInt32 ReadLen, 
					UInt8* pData
				)
{
   /* Variable declarations */
   tmErrorCode_t err = TM_OK;

/* Customer code here */
/* ...*/
    ptmOM3971Object_t  				pObj = Null;
	tmErrorCode_t      				errI2C = TM_OK;
	UInt8							i = 0;
    UInt8              				uBytesBuffer[I2C_BUFFER_SIZE];
    UInt8              				uSubAddress16[2] = {0,0};
	tmUnitSelect_t     				tUnitOM3971 = GET_SYSTEM_TUNIT(tUnit);
	struct i2c_msg 					msgs[2];
	struct i2c_rdwr_ioctl_data 		ioctl_data; 

    err = OM3971GetInstance(tUnitOM3971, &pObj);
    tmASSERTExT(err, TM_OK, (DEBUGLVL_ERROR, "OM3949GetInstance(0x%08X) failed.\n", tUnit));
	if(err == TM_OK)
	{
		switch ( AddrSize )
		{
		    case 1 :
		        uSubAddress16[0] = *pAddr&0xFF;
		        break;
		    case 2 :
		        uSubAddress16[0] = pAddr[1];
				uSubAddress16[1] = pAddr[0];
		        break;
		    case 0 :
		    default:
		        uSubAddress16[0] = 0; 
		}

		if ( ReadLen > I2C_BUFFER_SIZE )
		{
		    err = OM3971_ERR_BAD_PARAMETER;
		}
		else
		{
			switch(UNIT_PATH_TYPE_GET(tUnit))
			{
				case tmOM3971UnitDeviceTypeTDA18250:
					//errI2C = HI_UNF_I2C_Read( 0, DeviceTDA18250Addr, uSubAddress, AddrSize, uBytesBuffer, ReadLen );
					errI2C = DRV_I2C_Read( DeviceTDA18250Addr, uSubAddress16, AddrSize, uBytesBuffer, ReadLen);
				break;

				case tmOM3971UnitDeviceTypeTDA10025:
					//errI2C = HI_UNF_I2C_Read( 0, DeviceTDA10025Addr, uSubAddress16, AddrSize, uBytesBuffer, ReadLen );
					errI2C = DRV_I2C_Read( DeviceTDA10025Addr, uSubAddress16, AddrSize, uBytesBuffer, ReadLen);			
				break;
				default:
					tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3949I2CRead(%08X) failed. Unknown Device Type.", tUnit);
					err = OM3971_ERR_BAD_PARAMETER;
				break;
			}
		}
	    if(errI2C == 0 && err == TM_OK)
	    {
	        switch(AddrSize)
	        {
		        default:
		        case 0:
		        case 1:						
		            for ( i = 0; i < ReadLen ; i++ ) 
		            {
		                *(pData + i) = (UInt8)uBytesBuffer[i];
		            }
		            break;

		        case 2:
		            for ( i= 0 ; i < ReadLen ; i += 2 ) 
		            {
		                *(pData + i) = (UInt8)uBytesBuffer[i+1];
		                *(pData + i + 1) = (UInt8)uBytesBuffer[i];
		            }
		            break;
	        }
	    }
	    else
	    {
	        tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3949I2CRead (0x%08X, [sub@0x%02x] %d) failed.", tUnit, (uSubAddress16[1] << 8)|uSubAddress16[0], ReadLen);
	        err = OM3971_ERR_HW;
	    }
	}
/* ...*/
/* End of Customer code here */

   return err;
}
Beispiel #4
0
tmErrorCode_t tmsysOM3912I2CRead(tmUnitSelect_t tUnit, UInt32 AddrSize, UInt8* pAddr, UInt32 ReadLen, UInt8* pData)
{
    ptmOM3912Object_t    pObj = Null;
    tmErrorCode_t           err = TM_OK;
    tmErrorCode_t           errI2C = TM_OK;
    UInt8                   uBytesBuffer[I2C_BUFFER_SIZE];
    UInt8                   uSubAddress = 0;
    UInt32                  i = 0;
    tmUnitSelect_t          tUnitOM3912 = GET_SYSTEM_TUNIT(tUnit);

    if(GET_XFER_DISABLED_FLAG_TUNIT(tUnit) == False)
    {
        err = OM3912GetInstance(tUnitOM3912, &pObj);
        tmASSERTExT(err, TM_OK, (DEBUGLVL_ERROR, "OM3912GetInstance(0x%08X) failed.", tUnit));

        if(err == TM_OK)
        {
            if(pObj->uHwAddress[UNIT_PATH_TYPE_GET(tUnit)] != OM3912_INVALID_DEVICE_ADDRESS)
            {          
                switch(AddrSize)
                {
                default:
                case 0:
                    uSubAddress = 0;
                    break;

                case 1:
                    uSubAddress = (*pAddr)&0xFF;
                    break;
                }

                if (ReadLen > I2C_BUFFER_SIZE)
                {
                    err = OM3912_ERR_BAD_PARAMETER;
                }
                else
                {
                    switch(UNIT_PATH_TYPE_GET(tUnit))
                    {
                    case tmOM3912UnitDeviceTypeTDA18273:
                        errI2C = tmdlI2CRead(tUnit, pObj->uHwAddress[UNIT_PATH_TYPE_GET(tUnit)], AddrSize, &uSubAddress, ReadLen, uBytesBuffer);
                        break;

                    default:
                        tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3912I2CRead(%08X) failed. Unknown Device Type.", tUnit);
                        err = OM3912_ERR_BAD_PARAMETER;
                        break;
                    }
                }

                if(errI2C == TM_OK && err == TM_OK)
                {
                    for (i=0 ; i<ReadLen ; i++) 
                    {
                        *(pData + i) = (UInt8)uBytesBuffer[i];
                    }
                }
                else
                {
                    tmDBGPRINTEx(DEBUGLVL_ERROR, "tmsysOM3912I2CRead(0x%08X, [sub@0x%02x] %d) failed.", tUnit, uSubAddress, ReadLen);
                    err = OM3912_ERR_HW;
                }
            }
        }
    }

    return err;
}