/** * @(#)Infineon_TUA9001.cpp * * ========================================================== * Version: 2.1 * Date: 2008.10.01 * ========================================================== * * ========================================================== * History: * * Date Author Description * ---------------------------------------------------------- * * 2008.07.02 Tom Lin added tuner version * 2008.10.01 Benny Chen fix a bug of C compile issue * ========================================================== * * Copyright 2005 Afatech, Inc. All rights reserved. * */ //#include // for Linux #include "type.h" #include "error.h" #include "user.h" #include "register.h" #include "standard.h" #include "driver_tua9001.h" #include "Infineon_TUA9001_Script.h" static Demodulator* DemodHandle = NULL; static Byte DemodChip = 0; /*======================================================================================================================== additional needed external funtions ( have to be provided by the user! ) ========================================================================================================================*/ /** * set / reset tuner reset input * @param i_state level * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int setRESETN (unsigned int i_state) { Dword error = Error_NO_ERROR; if (i_state == H_LEVEL) { /* set tuner RXEN pin to "H" */ error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot3_o, reg_top_gpiot3_o_pos, reg_top_gpiot3_o_len, 1); if (error) goto exit; } else { /* set tuner RXEN pin to "L" */ error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot3_o, reg_top_gpiot3_o_pos, reg_top_gpiot3_o_len, 0); if (error) goto exit; } exit: if (error) return (TUNER_ERR); else return (TUNER_OK); } /** * set / reset tuner receive enable input * @param i_state level * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int setRXEN (unsigned int i_state) { Dword error = Error_NO_ERROR; if (i_state == H_LEVEL) { /* set tuner RXEN pin to "H" */ error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot2_o, reg_top_gpiot2_o_pos, reg_top_gpiot2_o_len, 1); if (error) goto exit; } else { /* set tuner RXEN pin to "L" */ error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot2_o, reg_top_gpiot2_o_pos, reg_top_gpiot2_o_len, 0); if (error) goto exit; } exit: if (error) return (TUNER_ERR); else return (TUNER_OK); } /** * set / reset tuner chiop enable input * @param i_state level * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int setCEN (unsigned int i_state) {// wait for H/W design which GPIO to use // if (i_state == H_LEVEL) // /* set tuner CEN pin to "H" */ // // else // /* set tuner CEN pin to "L" */ // return TUNER_OK; } /** * waitloop * @param i_looptime * 1uS * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int waitloop (unsigned int i_looptime) { /* wait time = i_looptime * 1 uS */ User_delay (DemodHandle, i_looptime/1000); return TUNER_OK; } /** * i2cBusWrite * @param deviceAdress chip address * @param registerAdress register address * @param *date pointer to data source * @param length number of bytes to transmit * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int i2cBusWrite (unsigned char deviceAddress, unsigned char registerAddress, char *date, unsigned int length) { /* I2C write data format */ /* STA device_address ACK register_address ACK H_Byte-Data ACK L_Byte-Data !ACK STO */ /* STA = start condition, ACK = Acknowledge, STO = stop condition */ /* *date = pointer to data source */ /* length = number of bytes to write */ Dword error = Error_NO_ERROR; error = Standard_writeTunerRegisters (DemodHandle, DemodChip, (Word)registerAddress, (Byte)length, (Byte*)date); if (error) goto exit; exit: if (error) return (TUNER_ERR); else return (TUNER_OK); } /** * i2cBusRead * @param deviceAdress chip address * @param registerAdress register address * @param *date pointer to data destination * @param length number of bytes to read * @retval TUNER_OK No error * @retval TUNER__ERROR Error */ int i2cBusRead (unsigned char deviceAddress, unsigned char registerAddress, char *date, unsigned int length) { /* I2C read data format */ /* STA device_address ACK register_address ACK STA H_Byte-Data ACK device_address_read ACK H_Byte-Data ACK L_Byte-Data ACKH STO */ /* STA = start condition, ACK = Acknowledge (generated by TUA9001), ACKH = Acknowledge (generated by Host), STO = stop condition */ /* *date = pointer to data destination */ /* length = number of bytes to read */ Dword error = Error_NO_ERROR; error = Standard_readTunerRegisters (DemodHandle, DemodChip, (Word)registerAddress, (Byte)length, (Byte*)date); if (error) goto exit; exit: if (error) return (TUNER_ERR); else return (TUNER_OK); } /*======================================================================================================================== end of additional needed external funtions ========================================================================================================================*/ Dword TUA9001_open ( IN Demodulator* demodulator, IN Byte chip ) { Dword error = Error_NO_ERROR; DemodHandle = demodulator; DemodChip = chip; error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot2_en, reg_top_gpiot2_en_pos, reg_top_gpiot2_en_len, 1); if (error) goto exit; error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot2_on, reg_top_gpiot2_on_pos, reg_top_gpiot2_on_len, 1); if (error) goto exit; error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot3_en, reg_top_gpiot3_en_pos, reg_top_gpiot3_en_len, 1); if (error) goto exit; error = Standard_writeRegisterBits (DemodHandle, DemodChip, Processor_LINK, p_reg_top_gpiot3_on, reg_top_gpiot3_on_pos, reg_top_gpiot3_on_len, 1); if (error) goto exit; error = Standard_writeRegister (DemodHandle, DemodChip, Processor_LINK, p_reg_top_agc_od, 0); if (error) goto exit; error = initializeTua9001(); if (error) { error = Error_WRITE_TUNER_FAIL; goto exit; } exit: return (error); } Dword TUA9001_close ( IN Demodulator* demodulator, IN Byte chip ) { return (Error_NO_ERROR); } Dword TUA9001_set ( IN Demodulator* demodulator, IN Byte chip, IN Word bandwidth, IN Dword frequency ) { Dword error = Error_NO_ERROR; Word bw = 0; DemodChip = chip; if (bandwidth == 8000) bw = TUNER_BANDWIDTH_8MHZ; else if (bandwidth == 7000) bw = TUNER_BANDWIDTH_7MHZ; else if (bandwidth == 6000) bw = TUNER_BANDWIDTH_6MHZ; else bw = TUNER_BANDWIDTH_5MHZ; error = tuneTua9001 (frequency, (tunerDriverBW_t)bw); if (error) { error = Error_WRITE_TUNER_FAIL; goto exit; } exit: return (error); } TunerDescription tuner_TUA9001 = { TUA9001_open, TUA9001_close, TUA9001_set, TUA9001_scripts, TUA9001_scriptSets, TUA9001_ADDRESS, /** tuner i2c address */ 1, /** length of tuner register address */ 0, /** tuner if */ True, /** spectrum inverse */ 0x27, /** tuner id */ };