#include "8035.h"
extern UINT8 QND_ReadReg(UINT8 adr);
extern UINT8 QND_WriteReg(UINT8 adr, UINT8 value);
#define R_TXRX_MASK 0x30
uint32_t qnd_Crystal = QND_CRYSTAL_DEFAULT;
UINT8 qnd_PrevMode;
UINT8 qnd_Country = COUNTRY_CHINA ;
UINT16 qnd_CH_START = 7600;
UINT16 qnd_CH_STOP = 10800;
UINT8 qnd_CH_STEP = 1;
UINT8 qnd_AutoScanAll = 0;
UINT8 qnd_IsStereo;
UINT8 qnd_ChCount;
UINT8 qnd_R16;
UINT8 qnd_R17;
UINT8 qnd_R46;
UINT16 qnd_ChList[QN_CCA_MAX_CH];
UINT8 qnd_StepTbl[3]={5,10,20};
QND_SeekCallBack qnd_CallBackFunc = 0;
/**********************************************************************
void QNF_RXInit()
**********************************************************************
Description: set to SNR based MPX control. Call this function before
tune to one specific channel
Parameters:
None
Return Value:
None
**********************************************************************/
void QNF_RXInit()
{
QNF_SetRegBit(0x1B,0x08,0x00); //Let NFILT adjust freely
QNF_SetRegBit(0x2C,0x3F,0x12); //When SNR<ccth31, ccfilt3 will work
QNF_SetRegBit(0x1D,0x40,0x00);//Let ccfilter3 adjust freely
QNF_SetRegBit(0x41,0x0F,0x0A);//Set a hcc index to trig ccfilter3's adjust
QND_WriteReg(0x45,0x50);//Set aud_thrd will affect ccfilter3's tap number
QNF_SetRegBit(0x40,0x70,0x70); //snc/hcc/sm snr_rssi_sel; snc_start=0x40; hcc_start=0x30; sm_start=0x20
QNF_SetRegBit(0x19,0x80,0x80); //Use SNR for ccfilter selection criterion
QNF_SetRegBit(0x3E,0x80,0x80); //it is decided by programming this register
QNF_SetRegBit(0x41,0xE0,0xC0);//DC notching High pass filter bandwidth; remove low freqency dc signals
QNF_SetRegBit(0x42,0x10,0x10);//disable the vtune monitor
QNF_SetRegBit(0x34, 0x7F,SMSTART_VAL); //set SNCSTART
QNF_SetRegBit(0x35,0x7F,SNCSTART_VAL); //set SNCSTART
QNF_SetRegBit(0x36,0x7F,HCCSTART_VAL); //set HCCSTART
}
/**********************************************************************
void QNF_SetMute(UINT8 On)
**********************************************************************
Description: set register specified bit
Parameters:
On: 1: mute, 0: unmute
Return Value:
None
**********************************************************************/
void QNF_SetMute(UINT8 On)
{
if(On)
{
QNF_SetRegBit(0x4C, 0x0B, 0x0B);
}
else
{
QND_Delay(QND_DELAY_BEFORE_UNMUTE);
QNF_SetRegBit(0x4C, 0x0B, 0x00);
}
}
/**********************************************************************
void QNF_SetRegBit(UINT8 reg, UINT8 bitMask, UINT8 data_val)
**********************************************************************
Description: set register specified bit
Parameters:
reg: register that will be set
bitMask: mask specified bit of register
data_val: data will be set for specified bit
Return Value:
None
**********************************************************************/
void QNF_SetRegBit(UINT8 reg, UINT8 bitMask, UINT8 data_val)
{
UINT8 temp;
temp = QND_ReadReg(reg);
temp &= (UINT8)(~bitMask);
temp |= data_val & bitMask;
// temp |= data_val;
QND_WriteReg(reg, temp);
}
/**********************************************************************
UINT16 QNF_GetCh()
**********************************************************************
Description: get current channel frequency
Parameters:
None
Return Value:
channel frequency
**********************************************************************/
UINT16 QNF_GetCh()
{
UINT8 tCh;
UINT8 tStep;
UINT16 ch = 0;
// set to reg: CH_STEP
tStep = QND_ReadReg(CH_STEP);
tStep &= CH_CH;
ch = tStep ;
tCh= QND_ReadReg(CH);
ch = (ch<<8)+tCh;
return CHREG2FREQ(ch);
}
/**********************************************************************
UINT8 QNF_SetCh(UINT16 freq)
**********************************************************************
Description: set channel frequency
Parameters:
freq: channel frequency to be set
Return Value:
1: success
**********************************************************************/
UINT8 QNF_SetCh(UINT16 freq)
{
// calculate ch parameter used for register setting
UINT8 tStep;
UINT8 tCh;
UINT16 f;
UINT16 pll_dlt;
//this is a software patch for improving sensitivity at 85.4M,85.5M and 85.6M frequency
if(freq == 8540 || freq == 8550 || freq == 8560)
{
pll_dlt = (UINT16)qnd_R16 >> 3; //getting the pll_dlt lower 5 bits.
pll_dlt |=(UINT16)qnd_R17 << 5; //getting the pll_dlt higher 8 bits.
pll_dlt -= 1039;
QND_WriteReg(0x16, (UINT8)pll_dlt << 3);
QND_WriteReg(0x17, (UINT8)(pll_dlt >> 5));
if(freq == 8540) QND_WriteReg(0x46, 0x9D);
else if(freq == 8550) QND_WriteReg(0x46, 0x69);
else QND_WriteReg(0x46, 0x34);
freq = 8570;
}
else
{
QND_WriteReg(0x16, qnd_R16);
QND_WriteReg(0x17, qnd_R17);
QND_WriteReg(0x46, qnd_R46);
}
f = FREQ2CHREG(freq);
// set to reg: CH
tCh = (UINT8) f;
QND_WriteReg(CH, tCh);
// set to reg: CH_STEP
tStep = QND_ReadReg(CH_STEP);
tStep &= ~CH_CH;
tStep |= ((UINT8) (f >> 8) & CH_CH);
QND_WriteReg(CH_STEP, tStep);
return 1;
}
/**********************************************************************
void QNF_ConfigScan(UINT16 start,UINT16 stop, UINT8 step)
**********************************************************************
Description: config start, stop, step register for FM/AM CCA or CCS
Parameters:
start
Set the frequency (10kHz) where scan to be started,
eg: 7600 for 76.00MHz.
stop
Set the frequency (10kHz) where scan to be stopped,
eg: 10800 for 108.00MHz
step
1: set leap step to (FM)100kHz / 10kHz(AM)
2: set leap step to (FM)200kHz / 1kHz(AM)
0: set leap step to (FM)50kHz / 9kHz(AM)
Return Value:
None
**********************************************************************/
void QNF_ConfigScan(UINT16 start,UINT16 stop, UINT8 step)
{
// calculate ch para
UINT8 tStep = 0;
UINT8 tS;
UINT16 fStart;
UINT16 fStop;
fStart = FREQ2CHREG(start);
fStop = FREQ2CHREG(stop);
// set to reg: CH_START
tS = (UINT8) fStart;
QND_WriteReg(CH_START, tS);
tStep |= ((UINT8) (fStart >> 6) & CH_CH_START);
// set to reg: CH_STOP
tS = (UINT8) fStop;
QND_WriteReg(CH_STOP, tS);
tStep |= ((UINT8) (fStop >> 4) & CH_CH_STOP);
// set to reg: CH_STEP
tStep |= step << 6;
QND_WriteReg(CH_STEP, tStep);
}
/**********************************************************************
void QNF_SetAudioMono(UINT8 modemask, UINT8 mode)
**********************************************************************
Description: Set audio output to mono.
Parameters:
modemask: mask register specified bit
mode
QND_RX_AUDIO_MONO: RX audio to mono
QND_RX_AUDIO_STEREO: RX audio to stereo
QND_TX_AUDIO_MONO: TX audio to mono
QND_TX_AUDIO_STEREO: TX audio to stereo
Return Value:
None
**********************************************************************/
void QNF_SetAudioMono(UINT8 modemask, UINT8 mode)
{
if (mode == QND_RX_AUDIO_MONO)
QNF_SetRegBit(SYSTEM1,modemask, 0x04);
else
QNF_SetRegBit(SYSTEM1,modemask, mode);
}
/**********************************************************************
int QND_Delay()
**********************************************************************
Description: Delay for some ms, to be customized according to user
application platform
Parameters:
ms: ms counts
Ret
- 1
- 2
前往页