📄 rda5800_drv.c
字号:
#ifdef RDA5800
#include "l1audio_def.h"
#define READ 1
#define WRITE 0
#define ADRW 0x20
#define ADRR 0x21
/* Serial communication interfaces */
void SerialCommInit(void);
void SerialCommCryClkOn(void);
void SerialCommCryClkOff(void);
void SerialCommRxByte(uint8 *data, uint8 ack);
uint8 SerialCommTxByte(uint8 data);
void SerialCommStop(void);
void SerialCommStart(void);
bool Rda5800_Intialization(void);
int16 Rda5800_Channel_Selection( int32 curFreq);
unsigned char Rda5800_Channel_Seek(void);
unsigned char OperationRda5800_2w(unsigned char operation, unsigned char *data, unsigned char numBytes);
unsigned char Rda5800_initialization_reg[]={
//0x00,0x00,
//0x00,0x00,
0xd8,0x81, //0x02
0x6A,0x00,
0x44,0x00, //0x04
0x0c,0xff, //0x13ff, lilin, 06/22, 0x10f8, //0x05
0x00,0x00,
0x00,0xcd,
0x00,0x96,
0x00,0x20,
0x41,0x63,
0x08,0x06,
0x58,0x00,
0x58,0x00,
0x58,0x00,
0x58,0x00,
0x2c,0x17, //lilin, 08/13, seek_singlestep, 0x4817,
0x20,0xa2,
0x00,0x00,
0x00,0x0f,
0x06,0xde,
0xec,0xc0,
0x02,0x00,
0x53,0x83,
0x95,0xa4,
0xe8,0x48,
0x05,0x00, //0x0500, lilin, 06/22, 0x0500,
0x00,0xa4, //0x00a4, lilin, 06/22, 0x00a4,
0x88,0x9b,
0x0d,0x84,
0x4f,0x04,
0x88,0x32,
0x7f,0x71,
0x06,0x60,
0x40,0x10,
0x60,0x02,
0x18,0x08,
0x64,0x58,
0x78,0x7f,
0x01,0x00,
0xc0,0x40,
0xc0,0x20,
0x00,0x24,
0x04,0x00,
0x00,0x20,
};
void FMDrv_PowerOnReset(void)
{
SerialCommCryClkOn();
SerialCommInit();
kal_sleep_task(20);
Rda5800_Intialization();
}
void FMDrv_PowerOffProc(void)
{
unsigned char Rda5800_poweroff[] ={0x00,0x00};
unsigned char error_ind = 0;
OperationRda5800_2w(WRITE, &(Rda5800_poweroff[0]), 2);
SerialCommCryClkOff();
}
void FMDrv_ChipInit()
{
InitRst();
kal_sleep_task(1);
SerialCommCryClkOn();
kal_sleep_task(1);
SerialCommInit();
Rda5800_Intialization();
FMDrv_PowerOffProc();
// SerialCommCryClkOff();
}
void FMDrv_Mute(uint8 mute)
{
unsigned char Rda5800_Muteon[] ={0x98,0x81};
unsigned char Rda5800_Muteclose[] ={0xd8,0x81};
if(mute)
OperationRda5800_2w(WRITE, &(Rda5800_Muteon[0]), 2);
else
OperationRda5800_2w(WRITE, &(Rda5800_Muteclose[0]), 2);
}
void FMDrv_SetFreq( int16 curf )
{
int32 curFreq = (int32)curf -875;
FMDrv_Mute(1);
Rda5800_Channel_Selection(curFreq );
FMDrv_Mute(0);
}
uint8 FMDrv_ValidStop(int16 freq, int8 signalvl, bool is_step_up) /* 自动搜索时,作为判定条件,再从中选择信号最强的9个台*/
{
int16 rssi_high;
unsigned char Rda5800_reg_data[4]={0};
unsigned char Rda5800_channel_seek_up[] = {0xdb,0x81};
unsigned char Rda5800_channel_seek_down[] = {0xd9,0x81};
unsigned char error_ind = 0;
unsigned char falseStation = 0;
if(is_step_up)
{
if(freq==875)
freq ==1081;
FMDrv_SetFreq(freq-1);
kal_sleep_task(14);
//set seek bit
error_ind = OperationRda5800_2w(WRITE,&(Rda5800_channel_seek_up[0]), 2);
//if(error_ind)
//return 1;
kal_sleep_task(18);
}
else
{
if(freq ==1080)
freq = 874;
FMDrv_SetFreq(freq+1);
kal_sleep_task(14);
//set seek bit
error_ind = OperationRda5800_2w(WRITE,&(Rda5800_channel_seek_down[0]), 2);
//if(error_ind)
//return 1;
kal_sleep_task(18);
}
//read REG0A&0B
error_ind = OperationRda5800_2w(READ,&(Rda5800_reg_data[0]), 4);
//check whether SF=1
if((Rda5800_reg_data[0]&0x20)!=0) falseStation=1;
//check station RSSI again, if RSSI<SEEKTH, then falseStation, continue seek
if(Rda5800_reg_data[2] < Rda5800_initialization_reg[6]) falseStation=1;
if(freq==960) falseStation=1;
if (falseStation==1)
return 0;
else
return 1;
}
uint8 FMDrv_GetSigLvl( int16 curf ) /*当满足rssi 的条件时,将信号记录,再选最强的9个频段*/
{
unsigned char Rda5800_reg_data[4]={0};
OperationRda5800_2w(READ,&(Rda5800_reg_data[0]), 4);
return Rda5800_reg_data[2]; /*返回rssi*/
}
bool FMDrv_IsChipValid(void)
{
bool result;
SerialCommCryClkOn();
SerialCommInit();
result = Rda5800_Intialization();
SerialCommCryClkOff();
return result;
}
void FMDrv_SetVolumeLevel(uint8 level) /*一般不调用,即不用芯片来调节音量。*/
{
/*
void FMDrv_SetVolumeLevel(uint8 level, int32 curFreq)
{
unsigned char Rda5800_volumelevel[] ={0xd8,0x91,0x00,0x00,0x44,0x00,0x0c,0xff};
unsigned char Rda5800_normal[] ={0xd8,0x81};
Rda5800_volumelevel[2]=curFreq;
Rda5800_volumelevel[7]=(level&0x0f)|0xf0;
OperationRda5800_2w(WRITE, &(Rda5800_volumelevel[0]), 8);
kal_sleep_task(2);
OperationRda5800_2w(WRITE, &(Rda5800_normal[0]), 2);
}
*/
}
unsigned char OperationRda5800_2w(unsigned char operation, unsigned char *data, unsigned char numBytes)
{
unsigned char controlWord, j, error = 0;
int i;
int32 acknowledge=0;
/***************************************************
START: make sure here SDIO_DIR =OUT, SCLK = 1, SDIO = 1
****************************************************/
SerialCommStart();
/***************************************************
WRITE CONTROL DATA: make sure here: SLCK = 0; SDIO = 0
****************************************************/
/***************************
CHECK ACK for control word
***************************/
if(operation == READ)
acknowledge = SerialCommTxByte(ADRR);
else
acknowledge = SerialCommTxByte(ADRW);
//kal_prompt_trace(MOD_MED_V,"OperationRda5800_2w lrjaaaaaa acknowledge =%d ",acknowledge);
/***************************************
WRITE or READ data
****************************************/
/******************************
CHECK ACK or SEND ACK=0
*******************************/
for(j = 0; j < numBytes; j++, data++)
{
if(operation == READ)
{
if(j == (numBytes -1))
SerialCommRxByte(data,1);
else
SerialCommRxByte(data, 0);
}
else
acknowledge = SerialCommTxByte(*data);
//kal_prompt_trace(MOD_MED_V,"OperationRda5800_2w numBytes =%d acknowledge=%d,data=%x",numBytes,acknowledge,*data); //lrj add for test 20060522
}
/****************************
STOP: make sure here: SCLK = 0
*****************************/
SerialCommStop();
return acknowledge;
}
/**************************************
Rda5800_Intialization():
***************************************/
bool Rda5800_Intialization(void)
{
unsigned char error_ind = 0;
error_ind = OperationRda5800_2w(WRITE, (unsigned char *)&Rda5800_initialization_reg[0], 86);
kal_sleep_task(20);
if (error_ind )
return 0;
else
return 1;
}
/**************************************
Rda5800_Channel_Selection()
***************************************/
int16 Rda5800_Channel_Selection( int32 curFreq)
{
unsigned short loop_counter = 0;
unsigned char Rda5800_reg_data[32]={0};
unsigned char error_ind = 0;
/* Freq(MHz)=Spacing(kHz)*channel+87.5MHz spacing=100K*/
unsigned char Rda5800_channel_start_tune[] ={0xd8,0x81,0x6a,0x00}; //104.3MHz
Rda5800_channel_start_tune[2]=curFreq;
//set tune bit
error_ind = OperationRda5800_2w(WRITE, &(Rda5800_channel_start_tune[0]), 4);
if(error_ind)
return 0;
kal_sleep_task(20);
//read REG0A&0B
//error_ind = OperationRda5800_2w(READ,&(Rda5800_reg_data[0]), 4);
//if(error_ind)
return 1;
}
/**************************************
Rda5800_Channel_Seek()
return 1: I2C error
return 2: seek fail
***************************************/
unsigned char Rda5800_Channel_Seek(void) /*芯片提供的搜索控制寄存器,但没有用到,因为结合原有的自动搜索机制*/
{
unsigned short loop_counter = 0;
unsigned char Rda5800_reg_data[32];
unsigned char error_ind = 0, seek_error = 0;
unsigned char Rda5800_channel_seek_start[] = {0xdb,0x81};
unsigned char falseStation = 0;
do{
// fStopSeek=0;
falseStation=0;
//set seek bit
error_ind = OperationRda5800_2w(WRITE,&(Rda5800_channel_seek_start[0]), 2);
if(error_ind)
return 1;
kal_sleep_task(18);
error_ind = OperationRda5800_2w(READ,&(Rda5800_reg_data[0]), 4);
if(error_ind)
return 1;
//check whether SF=1
if((Rda5800_reg_data[0]&0x20)!=0) falseStation=1;
//check station RSSI again, if RSSI<SEEKTH, then falseStation, continue seek
if(Rda5800_reg_data[2] < Rda5800_initialization_reg[6]) falseStation=1;
//if(STOPSEEK) fStopSeek=1;
}while(falseStation==1);//&&(fStopSeek==0));
return falseStation;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -