亚洲春色中文字幕久久久-三上亚,91精品国产亚一区二区三区,久久久九色综合亚洲成色777,涩涩视频下载,国产午夜亚洲精品午夜鲁丝片,国产精品A一区二区三区腾讯导航,影音先锋色情AV在线看片,蜜臀国产在线视频,极品少妇高潮啪啪无码吴梦梦 ,精品人妻无码一区二区三区手机版
標(biāo)題:
QN8027代碼
[打印本頁(yè)]
作者:
cxl888
時(shí)間:
2026-4-14 14:42
標(biāo)題:
QN8027代碼
#include "qndriver.h"
extern UINT8 QND_ReadReg(UINT8 adr);
extern UINT8 QND_WriteReg(UINT8 adr, UINT8 value);
#define RSSINTHRESHOLD 4
UINT8 clearscanflag = 0;
UINT16 clearchannel = 0;
UINT8 firstscan = 1;
#define R_TXRX_MASK 0x20
#define R_FMAM_MASK 0xc0
UINT8 S_XDATA RSSIn = 255;
UINT8 S_XDATA Rssinarray[4];
UINT8 S_XDATA qnd_Country = COUNTRY_CHINA ;
UINT16 S_XDATA QND_CH_START = 7600;
UINT16 S_XDATA QND_CH_STOP = 10800;
UINT8 S_XDATA QND_CH_STEP = 1;
UINT8 S_XDATA qnd_Band;
/**********************************************************************
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;
QND_WriteReg(reg, temp);
}
/**********************************************************************
UINT16 QNF_GetCh()
**********************************************************************
Description: get channel frequency of CCS
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 specified frequency
Parameters:
freq: specified frequency that is set
Return Value:
1: set success
**********************************************************************/
UINT8 QNF_SetCh(UINT16 freq)
{
// calculate ch para
UINT8 tStep;
UINT8 tCh;
UINT16 f;
f = FREQ2CHREG(freq);
// set to reg: CH
tCh = (UINT8) f;
printk("cj+++tCh = %d \r\n",tCh);
QND_WriteReg(CH, tCh);
// set to reg: CH_STEP
tStep = QND_ReadReg(CH_STEP);
tStep &= ~CH_CH;
tStep |= ((UINT8) (f >> 8) & CH_CH);
printk("cj+++tStep = %d \r\n",tStep);
QND_WriteReg(CH_STEP, tStep);
return 1;
}
/**********************************************************************
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)
{
QNF_SetRegBit(SYSTEM2,modemask, mode);
}
/**********************************************************************
int QND_Delay()
**********************************************************************
Description: Delay for some ms, to be customized according to user
application platform
Parameters:
ms: ms counts
Return Value:
None
**********************************************************************/
void QND_Delay(UINT16 ms)
{
UINT16 i,k;
for(i=0; i<3000;i++)
{
for(k=0; k<ms; k++)
{
}
}
}
/**********************************************************************
UINT8 QND_GetRSSI(UINT16 ch)
**********************************************************************
Description: Get the RSSI value, call QND_TuneToCH to set specify CH
Parameters:
Return Value:
RSSI value of the channel setted
**********************************************************************/
void QN_ChipInitialization()
{
//24M初始化
QND_WriteReg(0x00,0x81);// reset all registers to the default value
QND_Delay(20);
//to be customized: change the crystal setting(register 0x03 and 0x04) according to HW design
//Had better set Reg0x04 bit1~0=11(40Kohm input impedance) and bit6~4=011
QND_WriteReg(0x03,0x10);// 如果使用無(wú)源晶體,0x03寄存器[7:6]為00,
QND_WriteReg(0x04,0xb2);// 如果是24M,0x04寫(xiě)0xb2,如果是12M,0x04寫(xiě)0x32
QNF_SetRegBit(0x00,0x40,0x40);//recalibration
QNF_SetRegBit(0x00,0x40,0x00);//recalibration
QND_Delay(20); //delay 20 ms
QND_WriteReg(0x18,0xe4); //SNR improve
QND_WriteReg(0x1b,0xf0); //Increase RF power output
/***********/
QND_WriteReg(0x01, 0x7e);
QND_WriteReg(0x02, 0xb9);
/************/
//Done chip recalibration
}
void QN_ChipInitialization_12M()
{
QND_WriteReg(0x00,0x81);// reset all registers to the default value
QND_Delay(20);
//to be customized: change the crystal setting(register 0x03 and 0x04) according to HW design
//Had better set Reg0x04 bit1~0=11(40Kohm input impedance) and bit6~4=011
QND_WriteReg(0x03,0x10);// 使用無(wú)源晶體,設(shè)置為0x10
QND_WriteReg(0x04,0x32);// 晶體為12M,如果是24M,設(shè)置為0xb2
QNF_SetRegBit(0x00,0x40,0x40);//recalibration
QNF_SetRegBit(0x00,0x40,0x00);//recalibration
QND_Delay(20); //delay 20 ms
QND_WriteReg(0x18,0xe4); //SNR improve
QND_WriteReg(0x1b,0xf0); //Increase RF power output
/***********/
QND_WriteReg(0x01, 0x7e);
QND_WriteReg(0x02, 0xb9);
/************/
//Done chip recalibration
}
/**********************************************************************
int QND_Init()
**********************************************************************
Description: Initialize device to make it ready to have all functionality ready for use.
Parameters:
None
Return Value:
1: Device is ready to use.
0: Device is not ready to serve function.
**********************************************************************/
UINT8 QND_Init()
{
QN_ChipInitialization();
QND_WriteReg(00, 0x22); //resume original status of chip /* 2008 06 13 */
qnd_Band = BAND_FM;
return 1;
}
UINT8 QND_Shutdown()
{
QND_WriteReg(00, 0x01);
return 1;
}
/**********************************************************************
void QND_SetSysMode(UINT16 mode)
***********************************************************************
Description: Set device system mode(like: sleep ,wakeup etc)
Parameters:
mode:
set the system mode , it will be set by some macro define usually:
SLEEP: it will set device system work on sleep mode
WAKEUP: it will wakeup device system
TX: it will set device system work on TX mode
RX: it will set device system work on RX mode
FM: it will set device system work on FM mode
AM: it will set device system work on AM mode
TX|FM: it will set device system work on FM,TX mode
RX|AM; it will set device system work on AM,RX mode
RX|FM: it will set device system work on FM,RX mode
Return Value:
None
**********************************************************************/
void QND_SetSysMode(UINT16 mode)
{
UINT8 val;
switch(mode)
{
default:
val = (UINT8)(mode >> 8);
if (val)
{
val = val >> 1;
if (val & 0x20)
{
QNF_SetRegBit(SYSTEM1, 0x20, val);
}
qnd_Band = BAND_FM;
}
break;
}
}
/**********************************************************************
void QND_TuneToCH(UINT16 ch)
**********************************************************************
Description: Tune to the specified channel. Before use this function
make sure the QND_SetSysMode() has been called. If system is working
on FM&TX mode,it will turn FM to ch, and start Transmit; If system is
working on FM&RX mode,it will turn FM to ch, and start FM play.
Parameters:
ch
Set the frequency (10kHz) to be tuned,
eg: 101.30MHz will be set to 10130.
Return Value:
None
**********************************************************************/
void QND_TuneToCH(UINT16 ch)
{
UINT8 rssi;
UINT8 minrssi;
QNF_SetCh(ch);
QND_Delay(150);
}
/**********************************************************************
void QND_SetCountry(UINT8 country)
***********************************************************************
Description: Set start, stop, step for RX and TX based on different
country
Parameters:
country:
Set the chip used in specified country:
CHINA:
USA:
JAPAN:
Return Value:
None
**********************************************************************/
void QND_SetCountry(UINT8 country)
{
qnd_Country = country;
switch(country)
{
case COUNTRY_CHINA:
QND_CH_START = 7600;
QND_CH_STOP = 10800;
QND_CH_STEP = 1;
break;
case COUNTRY_USA:
QND_CH_START = 8810;
QND_CH_STOP = 10790;
QND_CH_STEP = 2;
break;
case COUNTRY_JAPAN:
break;
}
}
/**********************************************************************
UINT8 QND_TXSetPower( UINT8 gain)
**********************************************************************
Description: Sets FM transmit power attenuation.
Parameters:
attenuation :The transmission power attenuation value, for example,
setting the gain = 0x13, TX attenuation will be -6db
gain:Look Up Table (see below)
// db: maximum is -34.5db -(12 + 124-101.5)
// input unit: 0.1db, eg: -110.5 => 1105
//
//
//
/*
BIT[5:4]
00 0db
01 -6db
10 -12db
11 -18db
BIT[3:0] unit: db
0000 124
0001 122.5
0010 121
0011 119.5
0100 118
0101 116.5
0110 115
0111 113.5
1000 112
1001 110.5
1010 109
1011 107.5
1100 106
1101 104.5
1110 103
1111 101.5
for example:
0x2f, //111111 89.5
0x2e, //111110 91
0x2d, //111101 92.5
0x2c, //111100 94
0x1f, //111011 95.5
0x1e, //111010 97
0x1d, //111001 98.5
0x1c, //111000 100
0x0f, //001111 101.5
0x0e, //001110 103
0x0d, //001101 104.5
0x0c, //001100 106
0x0b, //001011 107.5
0x0a, //001010 109
0x09, //001001 110.5
0x08, //001000 112
0x07, //000111 113.5
0x06, //000110 115
0x05, //000101 116.5
0x04, //000100 118
0x03, //000011 119.5
0x02, //000010 121
0x01, //000001 122.5
0x00 //000000 124
*/
void QND_TXSetPower( UINT8 gain)
{
UINT8 value = 0;
value |= 0x40;
value |= gain;
QND_WriteReg(PAG_CAL, value);
}
/**********************************************************************
Description: Config the Rx Audio performance like volume adjust,
mute set:
Parameters:
optiontype:
It indicates what you want to config, it can use some marco define to control:
eg: AGCGAINCONFIG, SOFTCLIPCONFIG, MONOCONFIG, OUTPUTFORMATCONFIG
option:
set the configuration value;
if (optiontype== QND_CONFIG_AUTOAGC) : ‘option’ will control agc,
0:disable agc function, 1:enable function.
if (optiontype== QND_CONFIG_SOFTCLIP); ‘option’ will control softclip,
0:disable soft clip, 1:enable softclip.
if (optiontype== QND_CONFIG_MONO); ‘option’ will control mono,
0: QND_AUDIO_STEREO, 1: QND_AUDIO_STEREO
if (optiontype == QND_CONFIG_AGCGAIN); ‘option’ will control AGC value:0000~1111
Return Value:
none
**********************************************************************/
void QND_TXConfigAudio(UINT8 optiontype, UINT8 option )
{
switch(optiontype)
{
case QND_CONFIG_MONO:
if (option)
QNF_SetAudioMono(0x10, QND_TX_AUDIO_MONO);
else
QNF_SetAudioMono(0x10, QND_TX_AUDIO_STEREO);
break;
case QND_CONFIG_MUTE:
if (option)
QNF_SetRegBit(23, 0x30,0);
else
QNF_SetRegBit(23, 0x30,0x30);
break;
case QND_CONFIG_AGCGAIN:
QNF_SetRegBit(0x04, 0x70,(UINT8)(option<<4));
break;
default:
break;
}
}
/**********************************************************************
UINT8 QND_SetRDSMode(UINT8 mode)
**********************************************************************
Description: Enable or disable chip to work with RDS related functions.
Parameters:
on: QND_RDS_ON: Enable chip to receive/transmit RDS data.
QND_RDS_OFF: Disable chip to receive/transmit RDS data.
Return Value:
QND_SUCCESS: function executed
**********************************************************************/
UINT8 QND_RDSEnable(UINT8 on)
{
UINT8 val;
QND_LOG("=== QND_SetRDSMode === ");
// get last setting
val = QND_ReadReg(0x12);
if (on == QND_RDS_ON)
{
val |= RDSEN;
}
else if (on == QND_RDS_OFF)
{
val &= ~RDSEN;
}
else
{
return 0;
}
QND_WriteReg(0x12, val);
return 1;
}
/**********************************************************************
UINT8 QND_LoadRDSData( UINT8 *buf)
**********************************************************************
Description: Load (TX) or unload (RX) RDS data to on-chip RDS buffer.
Before calling this function, always make sure to call the
QND_RDSBufferReady function to check that the RDS is capable
to load/unload RDS data.
Parameters:
rdsRawData : 8 bytes data buffer to load (on TX mode) or unload (on RX
mode) to chip RDS buffer.
Upload: 1-upload, 0--download
Return Value:
QND_SUCCESS: function executed
**********************************************************************/
void QND_RDSLoadData(UINT8 *rdsRawData, UINT8 upload)
{
UINT8 i;
UINT8 temp;
if (upload)
{ //TX MODE
for (i = 0; i <= 7; i++)
{
QND_WriteReg(RDSD0 + i, rdsRawData[i]);
}
}
else
{
//RX MODE
for (i = 0; i <= 7; i++)
{
temp = QND_ReadReg(RDSD0 + i);
rdsRawData[i] = temp;
}
}
}
/**********************************************************************
UINT8 QND_RDSBufferReady(void)
**********************************************************************
Description: Check chip RDS register buffer status before doing load/unload of
RDS data.
Parameters:
None
Return Value:
QND_RDS_BUFFER_NOT_READY: RDS register buffer is not ready to use.
QND_RDS_BUFFER_READY: RDS register buffer is ready to use. You can now
load (for TX) or unload (for RX) data
from/to RDS buffer
**********************************************************************/
UINT8 QND_RDSCheckBufferReady(void)
{
// get last setting
UINT8 ret = QND_RDS_BUFFER_NOT_READY;
UINT8 val;
UINT8 temp;
UINT8 rdsUpdated;
if (QND_ReadReg(SYSTEM1) & TXREQ)
{ //TX MODE
val = QND_ReadReg(SYSTEM2);
rdsUpdated = val&RDSTXRDY ? 0 : 1;
if (rdsUpdated == 0)
{
QND_WriteReg(SYSTEM2,val & 0xfb); //write 0
ret = QND_RDS_BUFFER_READY;
}
else
{
QND_WriteReg(SYSTEM2,val | 0x04);
ret = QND_RDS_BUFFER_READY; //wirte 1
}
}
else
{ //for RX mode
}
return ret;
}
復(fù)制代碼
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1