//1.0 , 04/16/2007, lilin, RDA
#define FMRDA5800_GLOBALS
#include "FMRDA5800.h"
//Globals
XWORD FMshadowReg[45];
XWORD FMseekChannels[FMCHANNELSMAX];
CWORD cwFMDefault[]={
0x0000,
0x0000,
0xd881, //0x02
0x6300,
0x4400, //0x04
0x10f8, //0x05
0x0000,
0x00cd,
0x0096,
0x0020,
0x4163,
0x0806,
0x5800,
0x5800,
0x5800,
0x5800,
0x4817,
0x20a2,
0x0000,
0x000f,
0x06de,
0xecc0,
0x0200,
0x5383,
0x95a4,
0xe848,
0x0500,
0x00a4,
0x889b,
0x0d84,
0x4f04,
0x8832,
0x7f71,
0x0660,
0x4010,
0x6002,
0x1808,
0x6458,
0x787f,
0x0100,
0xc040,
0xc020,
0x0024,
0x0400,
0x0020,
};
//================================================================
WORD FmChanToFreq(BYTE channel) large
{
WORD channelSpacing;
WORD bottomOfBand;
WORD frequency;
if ((FMshadowReg[3] & 0x0002) == 0x0000)
bottomOfBand = 875;
else
bottomOfBand = 760;
if ((FMshadowReg[3] & 0x0001) == 0x0000)
channelSpacing = 1;
else if ((FMshadowReg[5] & 0x0001) == 0x0001)
channelSpacing = 2;
else
channelSpacing = 1;
frequency = (bottomOfBand + channelSpacing * channel);
return (frequency);
}
//================================================================
WORD FmFreqToChan(WORD frequency) large
{
WORD channelSpacing;
WORD bottomOfBand;
WORD channel;
if ((FMshadowReg[3] & 0x0002) == 0x0000)
bottomOfBand = 875;
else
bottomOfBand = 760;
if ((FMshadowReg[3] & 0x0001) == 0x0000)
channelSpacing = 1;
else if ((FMshadowReg[5] & 0x0001) == 0x0001)
channelSpacing = 2;
else
channelSpacing = 1;
channel = (frequency - bottomOfBand) / channelSpacing;
return (channel);
}
//================================================================
BYTE FmWaitSTC1(void) large
{
#if(WAITGPIO2)
WORD i;
WAIT_FOR_GPIO2();
for(i=0x2000;i>0;i--);
return(1);
#else
BYTE readData8[2];
do
{
if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,2,readData8)==0) return(0);
}
while((readData8[0]&0x40)==0)
return(1);
#endif
}
//================================================================
BYTE FmWaitSTC0(void) large
{
WORD i;
for(i=0x2000;i>0;i--) ; //lilin note, 07/03/27, this timer should longer than 50ms
return(1);
}
//================================================================
BYTE FmInit(void) large
{
WORD i,j;
XBYTE writeData8[86],xbTemp;
I2C_FM_SEN_1();
I2C_FM_RST_0();
_nop_();
_nop_();
_nop_();
I2C_FM_RST_1();
_nop_();
_nop_();
_nop_();
for(xbTemp = 0; xbTemp < 45; xbTemp++)
FMshadowReg[xbTemp] = cwFMDefault[xbTemp];
//lilin, for wait 0.5s after enable RCLK
writeData8[0] = 0xd8; //0x02 0xd881
writeData8[1] = 0x81; //0x81;
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
#if(DCXO)
//wait 500ms for RCLK stable,
for(i=0x500;i>0;i--)
for(j=0x500;j>0;j--) ; //wait 500ms for RCLK stable
#endif
for(xbTemp = 0; xbTemp < 43; xbTemp++)
{
writeData8[xbTemp*2] = (FMshadowReg[xbTemp+2] >> 8);
writeData8[xbTemp*2+1] = (FMshadowReg[xbTemp+2]);
}
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,86,writeData8))
{
}
else
return (0);
//lilin, Tune caused by write REG 03H just now
//wait STC==1
if(FmWaitSTC1()==0) return(0);
//clear STC and lab_mode at the same time, from now only could access register 00H~0FH
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81; //0x81;
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
//guarantee STC=0
if(FmWaitSTC0()==0) return(0);
}
//================================================================
BYTE FmTune(WORD channel) large
{
BYTE readData8[32];
BYTE writeData8[4];
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81;
writeData8[2] = channel; //0x03
writeData8[3] = 0x00;
if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
//wait STC=1
if(FmWaitSTC1()==0) return(0);
//read REG0A&0B
#if(FMTEST)
if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,32,readData8)==0) return(0);
#else
if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
#endif
FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
#if(FMTEST)
FMshadowReg[12] = readData8[4]*0x100 + readData8[5];
FMshadowReg[13] = readData8[6]*0x100 + readData8[7];
FMshadowReg[14] = readData8[8]*0x100 + readData8[9];
FMshadowReg[15] = readData8[10]*0x100 + readData8[11];
FMshadowReg[0] = readData8[12]*0x100 + readData8[13];
FMshadowReg[1] = readData8[14]*0x100 + readData8[15];
FMshadowReg[2] = readData8[16]*0x100 + readData8[17];
FMshadowReg[3] = readData8[18]*0x100 + readData8[19];
FMshadowReg[4] = readData8[20]*0x100 + readData8[21];
FMshadowReg[5] = readData8[22]*0x100 + readData8[23];
FMshadowReg[6] = readData8[24]*0x100 + readData8[25];
FMshadowReg[7] = readData8[26]*0x100 + readData8[27];
FMshadowReg[8] = readData8[28]*0x100 + readData8[29];
FMshadowReg[9] = readData8[30]*0x100 + readData8[31];
#endif
//clear STC
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81; //0x81;
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
//wait STC=0
if(FmWaitSTC0()==0) return(0);
return(1);
}
//================================================================
BYTE FmSeek(BYTE seekDirection) large
{
BYTE readData8[4];
BYTE writeData8[2];
BOOL fTemp=0;
//set seek bit
if(seekDirection == 0)
writeData8[0] = ((FMshadowReg[2]>>8) | 0x01); // seek down
else
writeData8[0] = ((FMshadowReg[2]>>8) | 0x03); // seek up
writeData8[1] = FMshadowReg[2];
if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
//wait STC=1
if(FmWaitSTC1()==0) return(0);
//read REG0A&0B
if(i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
//check whether SF=1
if((readData8[0]&0x20)!=0) fTemp=1;
//clear STC
writeData8[0] = (FMshadowReg[2] >> 8);
writeData8[1] = (FMshadowReg[2]);
if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
//wait STC=0
if(FmWaitSTC0()==0) return(0);
if(fTemp) return(0);
else return(1);
}
//================================================================
BYTE FmEnterSleep(void) large
{
BYTE writeData8[2];
FMshadowReg[2] = 0xd080; //ENABLE = 0
writeData8[0] = (FMshadowReg[2] >> 8);
writeData8[1] = (FMshadowReg[2]);
if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
}
//================================================================
BYTE FmExitSleep(void) large
{
BYTE readData8[4];
BYTE writeData8[4];
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81;
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
#if(DCXO)
//wait 500ms for RCLK stable,
for(i=0x500;i>0;i--)
for(j=0x500;j>0;j--) ; //wait 500ms for RCLK stable
#endif
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81;
//tune to orginal channel
writeData8[2] = channel; //0x03
writeData8[3] = 0x00;
if(i2c_wr(I2C_FM,I2C_FM_WR_DATA,4,writeData8)==0) return(0);
//wait STC=1
if(FmWaitSTC1()==0) return(0);
if (i2c_rd(I2C_FM,I2C_FM_RD_DATA,4,readData8)==0) return(0);
FMshadowReg[10] = readData8[0]*0x100 + readData8[1];
FMshadowReg[11] = readData8[2]*0x100 + readData8[3];
//clear STC
writeData8[0] = 0xd0; //0x02 0xd081
writeData8[1] = 0x81; //0x81;
if (i2c_wr(I2C_FM,I2C_FM_WR_DATA,2,writeData8)==0) return(0);
//wait STC=0
if(FmWaitSTC0()==0) return(0);
return(1);
}
//================================================================
BYTE FmSetMute(void)
{
BYTE writeData8[2];
FMshadowReg[2] = 0x9881; // MUTE ENABLE = 1
FM.rar_FM_rda5800
版权申诉
3 浏览量
2022-09-21
04:31:42
上传
评论
收藏 3KB RAR 举报
局外狗
- 粉丝: 67
- 资源: 1万+
最新资源
- 知识蒸馏-基于Pytorch通过匹配训练轨迹进行数据集蒸馏-附项目源码+流程教程-优质项目实战.zip
- 儿童节 python庆祝代码简要介绍-20240601.docx
- 知识蒸馏-基于Pytorch实现的语义分割结构化知识蒸馏算法-附项目源码+流程教程-优质项目实战.zip
- 小白物联网智能家居毕设参考STM32+ESP8266/MQTT+OneNet+UniApp
- BeanUtil.java,对象属性拷贝工具
- 糖尿病肾病检测数据集VOC+YOLO格式4122张5类别.7z
- win10/11 更新禁用/开启
- IMG_3534.CR2.cr2
- FileZilla客户端
- 删除win10/11安全中心
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈