490 lines
16 KiB
C
Executable File
490 lines
16 KiB
C
Executable File
/*
|
|
Copyright (C) 2010 NXP B.V., All Rights Reserved.
|
|
This source code and any compilation or derivative thereof is the proprietary
|
|
information of NXP B.V. and is confidential in nature. Under no circumstances
|
|
is this software to be exposed to or placed under an Open Source License of
|
|
any type without the expressed written permission of NXP B.V.
|
|
*
|
|
* \file main.c
|
|
*
|
|
* 3
|
|
*
|
|
* \date %2011.5.4%
|
|
*
|
|
* \brief V7 tuner driver
|
|
*
|
|
* REFERENCE DOCUMENTS :
|
|
* OM3912_Driver_User_Guide.pdf
|
|
*
|
|
* Detailed description may be added here.
|
|
*
|
|
* \section info Change Information
|
|
*
|
|
*/
|
|
#include "../inc/config.h"
|
|
|
|
#if USE_TUNER
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Include Standard files
|
|
//*--------------------------------------------------------------------------------------
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include "tmNxTypes.h"
|
|
#include "tmCompId.h"
|
|
#include "tmFrontEnd.h"
|
|
#include "tmbslFrontEndTypes.h"
|
|
#include "../inc/delay.h"
|
|
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Include Driver files
|
|
//*--------------------------------------------------------------------------------------
|
|
#include "tmbslTDA18273.h"
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Tuner I2C device address
|
|
//*--------------------------------------------------------------------------------------
|
|
#define TUN_I2C_ADDR 0xC6 //0xC0
|
|
|
|
uint32 tuner_byte_write(uint32 addr,uint8 data);
|
|
uint8 tuner_byte_read(uint32 addr);
|
|
|
|
/**** Device table. List of device drivers for newlib. ****/
|
|
const struct device_table_entry *device_table[] = {
|
|
0,
|
|
0,
|
|
0,
|
|
0 }; /* end of list */
|
|
|
|
/* It seems that int isatty(int) is no longer provided by the environment, see the
|
|
example lpc2106_hello_rs232_newlib and the various syscalls.c for a workaround if
|
|
the error message "unknown reference to isatty" appears during the link-process.
|
|
(Reason might be the additional configure-option --disable-newlib-supplied-syscalls for
|
|
newlib which had to be added since the build of newlib 1.14.0 failed when the "supplied"
|
|
syscalls were not disabled.) */
|
|
int isatty(int);
|
|
|
|
extern int isatty(int fd)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Prototype of function to be provided by customer
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenWait(tmUnitSelect_t tUnit, UInt32 tms);
|
|
tmErrorCode_t UserWrittenPrint(UInt32 level, const char* format, ...);
|
|
tmErrorCode_t UserWrittenMutexInit(ptmbslFrontEndMutexHandle *ppMutexHandle);
|
|
tmErrorCode_t UserWrittenMutexDeInit( ptmbslFrontEndMutexHandle pMutex);
|
|
tmErrorCode_t UserWrittenMutexAcquire(ptmbslFrontEndMutexHandle pMutex, UInt32 timeOut);
|
|
tmErrorCode_t UserWrittenMutexRelease(ptmbslFrontEndMutexHandle pMutex);
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Template of function to be provided by customer
|
|
//*--------------------------------------------------------------------------------------
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenI2CRead
|
|
//* Object :
|
|
//* Input Parameters : tmUnitSelect_t tUnit
|
|
//* UInt32 AddrSize,
|
|
//* UInt8* pAddr,
|
|
//* UInt32 ReadLen,
|
|
//* UInt8* pData
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
static tmErrorCode_t UserWrittenI2CRead(tmUnitSelect_t tUnit, UInt32 AddrSize, UInt8* pAddr,UInt32 ReadLen, UInt8* pData)
|
|
{
|
|
tmErrorCode_t err = TM_OK;
|
|
#if USE_TUNER_18273
|
|
UInt8 reg_addr;
|
|
|
|
reg_addr = *pAddr;
|
|
|
|
while(ReadLen--)
|
|
{
|
|
*pData++ = tuner_byte_read(reg_addr++);
|
|
}
|
|
#endif
|
|
return err;
|
|
}
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenI2CWrite
|
|
//* Object :
|
|
//* Input Parameters : tmUnitSelect_t tUnit
|
|
//* UInt32 AddrSize,
|
|
//* UInt8* pAddr,
|
|
//* UInt32 WriteLen,
|
|
//* UInt8* pData
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
static tmErrorCode_t UserWrittenI2CWrite (tmUnitSelect_t tUnit,UInt32 AddrSize, UInt8* pAddr,UInt32 WriteLen, UInt8* pData)
|
|
{
|
|
tmErrorCode_t err = TM_OK;
|
|
#if USE_TUNER_18273
|
|
unsigned char reg_addr;
|
|
|
|
reg_addr = *pAddr;
|
|
|
|
while(WriteLen--)
|
|
{
|
|
tuner_byte_write(reg_addr++,*pData++);
|
|
}
|
|
#endif
|
|
return err;
|
|
}
|
|
|
|
//extern uint32 UserWrittenI2CRead(int tUnit,uint32 AddrSize, uint8* pAddr,uint32 ReadLen, uint8* pData);
|
|
//extern uint32 UserWrittenI2CWrite(int tUnit,uint32 AddrSize, uint8* pAddr,uint32 WriteLen, uint8* pData);
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : Main
|
|
//* Object : Software entry point
|
|
//* Input Parameters : none.
|
|
//* Output Parameters : none.
|
|
//* Current Unit is : 0
|
|
//*--------------------------------------------------------------------------------------
|
|
int TunerConf(uint32 conf_rf_freq)
|
|
{//* Begin
|
|
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
tmbslFrontEndDependency_t sSrvTunerFunc;
|
|
#if USE_TUNER_18273
|
|
tmTDA18273StandardMode_t stdMode = tmTDA18273_QAM_6MHz; // modified to Winnetech standard
|
|
#else
|
|
tmTDA18273StandardMode_t stdMode = tmTDA18273_ATSC_6MHz;
|
|
#endif
|
|
UInt32 uRF; // RF frequency in Hz
|
|
tmbslFrontEndState_t PLLLock = tmbslFrontEndStateUnknown;
|
|
UInt32 uIF = 0;
|
|
|
|
uRF = conf_rf_freq;
|
|
|
|
/* Driver layer struct set-up to link with user written functions */
|
|
sSrvTunerFunc.sIo.Write = UserWrittenI2CWrite;
|
|
sSrvTunerFunc.sIo.Read = UserWrittenI2CRead;
|
|
sSrvTunerFunc.sTime.Get = Null;
|
|
sSrvTunerFunc.sTime.Wait = UserWrittenWait;
|
|
sSrvTunerFunc.sDebug.Print = UserWrittenPrint;
|
|
sSrvTunerFunc.sMutex.Init = NULL;
|
|
sSrvTunerFunc.sMutex.DeInit = NULL;
|
|
sSrvTunerFunc.sMutex.Acquire = NULL;
|
|
sSrvTunerFunc.sMutex.Release = NULL;
|
|
sSrvTunerFunc.dwAdditionalDataSize = 0;
|
|
sSrvTunerFunc.pAdditionalData = Null;
|
|
|
|
/*Deinitialize former Instance, if necessary*/
|
|
tmbslTDA18273_Close(0); // or tmbslTDA18273DeInit(0);
|
|
|
|
/* TDA18273 Driver initialization */
|
|
err = tmbslTDA18273_Open(0, &sSrvTunerFunc); // or tmbslTDA18273Init(0, &sSrvTunerFunc);
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/* TDA18273 Hardware initialization */
|
|
err = tmbslTDA18273_HwInit(0); // or tmbslTDA18273Reset(0);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
|
|
|
|
tmbslTDA18273_CheckHWVersion(0);
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/* TDA18273 standard mode selection */
|
|
err = tmbslTDA18273_SetStandardMode(0, stdMode); // or tmbslTDA18273SetStandardMode(0, stdMode);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
//-----<< -----have err on there
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/* TDA18273 RF frequency selection */
|
|
err = tmbslTDA18273_SetRF(0, uRF); // or tmbslTDA18273SetRf(0, uRF);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
if(err == TM_OK)
|
|
{
|
|
/* Get TDA18273 PLL Lock status */
|
|
err = tmbslTDA18273_GetLockStatus(0, &PLLLock); // or tmbslTDA18273GetLockStatus(0, &PLLLock);
|
|
//printf("Tuner Lock State = %d\n",PLLLock);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/* Get TDA18273 IF value */
|
|
err = tmbslTDA18273_GetIF(0, &uIF); // or tmbslTDA18273GetIF(0, &uIF);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/* Put TDA18273 in standby mode: */
|
|
err = tmbslTDA18273_SetPowerState(0, tmPowerOn);
|
|
}//else
|
|
// printf("err.%s %d\n",__FUNCTION__,__LINE__);
|
|
|
|
if(err == TM_OK)
|
|
{
|
|
/*Do not Deinitialize TDA18273 here */
|
|
/* DeInitialize TDA18273 Driver */
|
|
//err = tmbslTDA18273_Close(0); // or tmbslTDA18273DeInit(0);
|
|
}
|
|
|
|
return err;
|
|
}//* End
|
|
|
|
int iic_rx_tun_readstate(void)
|
|
{//Begin
|
|
tmErrorCode_t err = TM_OK;
|
|
unsigned char i2caddr = 0x31;
|
|
unsigned char i2cdata = 0;
|
|
unsigned short temp;
|
|
/*read RSSI*/
|
|
err = tmbslTDA18273_GetPowerLevel(0,&i2cdata);
|
|
//printf("RSSI\t=\t%fdBuV\n", ((float)i2cdata)/2.0);
|
|
/*read RF filter gain*/
|
|
if(err == TM_OK)
|
|
{
|
|
err = UserWrittenI2CRead(0, 1, &i2caddr, 1, &i2cdata);
|
|
}
|
|
if(err == TM_OK)
|
|
{
|
|
temp = (i2cdata & 0x30)>>4;
|
|
switch(temp){
|
|
case 0: printf("RF filter gain\t=\t-11dB(min)\n");break;
|
|
case 1: printf("RF filter gain\t=\t-08dB\n");break;
|
|
case 2: printf("RF filter gain\t=\t-05dB\n");break;
|
|
case 3: printf("RF filter gain\t=\t-02dB(max)\n");break;
|
|
}
|
|
}
|
|
/*read LNA gain*/
|
|
if(err == TM_OK)
|
|
{
|
|
temp = i2cdata & 0x0F;
|
|
switch(temp){
|
|
case 0: printf("LNA gain\t=\t-10dB(min)\n");break;
|
|
case 1: printf("LNA gain\t=\t-07dB\n");break;
|
|
case 2: printf("LNA gain\t=\t-04dB\n");break;
|
|
case 3: printf("LNA gain\t=\t-01dB\n");break;
|
|
case 4: printf("LNA gain\t=\t+02dB\n");break;
|
|
case 5: printf("LNA gain\t=\t+05dB\n");break;
|
|
case 6: printf("LNA gain\t=\t+08dB\n");break;
|
|
case 7: printf("LNA gain\t=\t+11dB\n");break;
|
|
case 8: printf("LNA gain\t=\t+14dB\n");break;
|
|
case 9: printf("LNA gain\t=\t+17dB\n");break;
|
|
case 10: printf("LNA gain\t=\t+20dB(max)\n");break;
|
|
}
|
|
}
|
|
/*read RFAGC gain*/
|
|
if(err == TM_OK)
|
|
{
|
|
i2caddr = 0x34;
|
|
err = UserWrittenI2CRead(0, 1, &i2caddr, 1, &i2cdata);
|
|
}
|
|
if(err == TM_OK)
|
|
{
|
|
temp = i2cdata;
|
|
i2caddr = 0x33;
|
|
err = UserWrittenI2CRead(0, 1, &i2caddr, 1, &i2cdata);
|
|
}
|
|
if(err == TM_OK)
|
|
{
|
|
temp = temp|((i2cdata&0x80)<<1);
|
|
printf("RFAGC Gain\t=\t0x%.3x",temp);
|
|
if(temp == 0)
|
|
printf("(min)\n");
|
|
else if(temp == 0x1FF)
|
|
printf("(max)\n");
|
|
else
|
|
printf("\n");
|
|
}
|
|
/*read IF AGC gain*/
|
|
if(err == TM_OK)
|
|
{
|
|
i2caddr = 0x35;
|
|
err = UserWrittenI2CRead(0, 1, &i2caddr, 1, &i2cdata);
|
|
}
|
|
if(err == TM_OK)
|
|
{
|
|
temp = (i2cdata & 0x38)>>3;
|
|
switch(temp){
|
|
case 0: printf("Lowpass gain\t=\t-06dB(min)\n");break;
|
|
case 1: printf("Lowpass gain\t=\t-03dB\n");break;
|
|
case 2: printf("Lowpass gain\t=\t+00dB\n");break;
|
|
case 3: printf("Lowpass gain\t=\t+03dB\n");break;
|
|
case 4: printf("Lowpass gain\t=\t+06dB\n");break;
|
|
case 5: printf("Lowpass gain\t=\t+09dB\n");break;
|
|
case 6: printf("Lowpass gain\t=\t+12dB\n");break;
|
|
case 7: printf("Lowpass gain\t=\t+15dB(max)\n");break;
|
|
}
|
|
}
|
|
if(err == TM_OK)
|
|
{
|
|
temp = i2cdata & 0x07;
|
|
switch(temp){
|
|
case 0: printf("Mixer gain\t=\t+02dB(min)\n");break;
|
|
case 1: printf("Mixer gain\t=\t+05dB\n");break;
|
|
case 2: printf("Mixer gain\t=\t+08dB\n");break;
|
|
case 3: printf("Mixer gain\t=\t+11dB\n");break;
|
|
case 4: printf("Mixer gain\t=\t+14dB(max)\n");break;
|
|
}
|
|
}
|
|
return err;
|
|
|
|
}//*End
|
|
|
|
int TunerReadRSSI(unsigned char* pRSSI)
|
|
{
|
|
return tmbslTDA18273_GetPowerLevel(0,pRSSI);
|
|
}
|
|
int TunerRead18273lock(void)
|
|
{
|
|
tmbslFrontEndState_t lock;
|
|
|
|
tmbslTDA18273_GetLockStatus(0,&lock);
|
|
return (int)lock;
|
|
}
|
|
|
|
int TunerRead18273mode(void)
|
|
{
|
|
TDA18273StandardMode_t smode;
|
|
|
|
tmbslTDA18273_GetStandardMode(0,&smode);
|
|
return (int)smode;
|
|
}
|
|
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenWait
|
|
//* Object :
|
|
//* Input Parameters : tmUnitSelect_t tUnit
|
|
//* UInt32 tms
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//* Not used in the driver
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenWait(tmUnitSelect_t tUnit, UInt32 tms)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
delay_ms(tms);
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenPrint
|
|
//* Object :
|
|
//* Input Parameters : UInt32 level, const char* format, ...
|
|
//*
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenPrint(UInt32 level, const char* format, ...)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
va_list argp;
|
|
va_start(argp,format);
|
|
printf(format,argp);
|
|
va_end(argp);
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenMutexInit
|
|
//* Object :
|
|
//* Input Parameters : ptmbslFrontEndMutexHandle *ppMutexHandle
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenMutexInit(ptmbslFrontEndMutexHandle *ppMutexHandle)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenMutexDeInit
|
|
//* Object :
|
|
//* Input Parameters : ptmbslFrontEndMutexHandle pMutex
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenMutexDeInit( ptmbslFrontEndMutexHandle pMutex)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenMutexAcquire
|
|
//* Object :
|
|
//* Input Parameters : ptmbslFrontEndMutexHandle pMutex, UInt32 timeOut
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenMutexAcquire(ptmbslFrontEndMutexHandle pMutex, UInt32 timeOut)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
//*--------------------------------------------------------------------------------------
|
|
//* Function Name : UserWrittenMutexRelease
|
|
//* Object :
|
|
//* Input Parameters : ptmbslFrontEndMutexHandle pMutex
|
|
//* Output Parameters : tmErrorCode_t.
|
|
//*--------------------------------------------------------------------------------------
|
|
tmErrorCode_t UserWrittenMutexRelease(ptmbslFrontEndMutexHandle pMutex)
|
|
{
|
|
/* Variable declarations */
|
|
tmErrorCode_t err = TM_OK;
|
|
|
|
/* Customer code here */
|
|
/* ...*/
|
|
|
|
/* ...*/
|
|
/* End of Customer code here */
|
|
|
|
return err;
|
|
}
|
|
|
|
#endif
|