📄 radiodrv.c
字号:
return RADIODRV_SI4701;
else if ((wRADIODRVTunerReg[1] & 0x03C0)==0x0240)
return RADIODRV_SI4703;
else
return RADIODRV_SIFAIL;
}
//*********************************************************************************************************
// @summary This function be used to get frequency
// @param None
// @return Frequency of current station
// @retval frequency value
// @description
// This function be used to get frequency of current station
// @bug None
// @history
//*********************************************************************************************************
WORD RADIODRV_GetFreq(void)
{
//get current tuned channel
// printf("\n @ Get Freq :%x:",(_RADIODRV_ChanToFreq(wRADIODRVTunerReg[0x0B]&0x3FF)));
return (_RADIODRV_ChanToFreq(wRADIODRVTunerReg[0x0B]&0x3FF)) ;
}
//*********************************************************************************************************
// @summary This function be used to get RSSI value
// @param None
// @return Get RSSI of current station
// @retval RSSI value
// @description
// This function be used to get RSSI(Received Signal Strength Indicator) value of current station
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_GetRSSI(void)
{
_RADIODRV_ReadReg(0x0A, wRADIODRVTunerReg);
printf("\n @ Get RSSI :%x:",wRADIODRVTunerReg[0x0A]);
return ((BYTE)wRADIODRVTunerReg[0x0A]&0xFF);;
}
//*********************************************************************************************************
// @summary This function be used to get volume value
// @param None
// @return Get volume of current setting value
// @retval Volume value
// @description
// This function be used to get volume of current setting value
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_GetVol(void)
{
_RADIODRV_ReadReg(0x05, wRADIODRVTunerReg);
printf("\n @@ Vol = %x",((BYTE)(wRADIODRVTunerReg[5] & 0x000F)));
return ((BYTE)(wRADIODRVTunerReg[5] & 0x000F));
}
//*********************************************************************************************************
// @summary This function be used to get mute status of volume
// @param None
// @return Get mute status of volume
// @retval TRUE Enalbe Mute function
// @retval FALSE DISABLE Mute function
// @description
// This function be used to get mute status of volume
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_GetMute(void)
{
_RADIODRV_ReadReg(0x02, wRADIODRVTunerReg);
if((wRADIODRVTunerReg[2] & 0x4000))
{
// printf("\n @@ dis mute %lx",wRADIODRVTunerReg[2]);
return FALSE; //disable mute
}
else
{
//printf("\n @@ mute %lx",wRADIODRVTunerReg[2]);
return TRUE; //enable mute
}
}
//*********************************************************************************************************
// @summary This function be used to get band value
// @param None
// @return Get band value which current setting radio system
// @retval 0x00 Band range from 87.5~108Mhz
// @retval 0x01 Band range from 76~108Mhz
// @retval 0x02 Band range from 76~90Mhz
// @description
// This function be used to get band value for current radio system
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_GetBand(void)
{
_RADIODRV_ReadReg(0x05, wRADIODRVTunerReg);
if((wRADIODRVTunerReg[5] & 0x00C0)==0x0000)
return RADIODRV_BS_USA; //87.5 -108
else if ((wRADIODRVTunerReg[5] & 0x00C0)==0x0040)
return RADIODRV_BS_JapWide; //76-108
else
return RADIODRV_BS_Jap; //76-90
}
//*********************************************************************************************************
// @summary This function be used to get channel space
// @param None
// @return Get current space for current radio system
// @retval 0x00 space for 200khz
// @retval 0x01 space for 100khz
// @retval 0x02 space for 50khz
// @description
// This function be used to get current channle space setting
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_GetChanSpace(void)
{
_RADIODRV_ReadReg(0x05, wRADIODRVTunerReg);
if((wRADIODRVTunerReg[5] & 0x0030)==0x0000)
return RADIODRV_CS_USA; //200k hz
else if ((wRADIODRVTunerReg[5] & 0x0030)==0x0010)
return RADIODRV_CS_JAP; // 100 khz
else
return RADIODRV_CS_Non; // 50khz
}
//*********************************************************************************************************
// @summary This function be used to set band
// @param bRADIODRVband Desire to set band value. 0x00 for 87.5~108Mhz, 0x01 for 76~108Mhz and 0x02 for 76~90Mhz
// @return None
// @retval None
// @description
// This function be used to set band
// @bug None
// @history
//*********************************************************************************************************
void RADIODRV_SETBand(BYTE bRADIODRVband)
{
wRADIODRVTunerReg[5]|=(bRADIODRVband<<6)&0x00C0; //setting band
// printf("\n @Band_1: %x",wRADIODRVTunerReg[5]);
_RADIODRV_WriteReg(0x05,wRADIODRVTunerReg);
}
//*********************************************************************************************************
// @summary This function be used to set channel space
// @param bChanSpace Desire to set channel space. 0x00 for 200KHZ, 0x01 for 100KHZ and 0x02 for 50KHZ
// @return None
// @retval None
// @description
// This function be used to set channel space
// @bug None
// @history
//*********************************************************************************************************
void RADIODRV_SETChanSpace(BYTE bChanSpace)
{
wRADIODRVTunerReg[5]|=(bChanSpace<<4)&0x0030;
// printf("\n @space_1:%x",wRADIODRVTunerReg[5]);
_RADIODRV_WriteReg(0x05,wRADIODRVTunerReg);
}
//*********************************************************************************************************
// @summary This function be used to seek station for radio tuner control
// @param _bSeekDir if _bSeekDir as TRUN, the seek up direction, else _bSeekDir as FALSE, the seek down direction
// @return Get the seek status
// @retval TRUE Seek station successfully
// @retval FALSE Seek station fail
// @description
// This function be used to seek station for radio tuner control
// @bug None
// @history
//*********************************************************************************************************
BYTE _RADIODRV_SEEKAction(BYTE _bSeekDir)
{
//[step 1] :select the seek direction
if(_bSeekDir)
wRADIODRVTunerReg[0x02]|=0x0200;// seek up set 1
else
wRADIODRVTunerReg[0x02]&=~(0x0200);// seek down set 0
//[step 2]: Start to seek
wRADIODRVTunerReg[0x02]|=0x0100;
_RADIODRV_WriteReg(0x02,wRADIODRVTunerReg);
// [step3] :wait for the stc bit set (seek complete)
//added time-out method to avoid radio system hang
dwRadioDrvTime=OS_GetSysTimer();
do{
_RADIODRV_ReadReg(0x0A, wRADIODRVTunerReg);
if((OS_GetSysTimer()-dwRadioDrvTime)>COUNT_2_SEC )
{
//printf("\n @@SF1");
return RADIODRV_SEEK_ERR;
}
} while ((wRADIODRVTunerReg[0x0A] & 0x4000) == 0x0000);
//[step4 ]:clear the stc bit and wait for the STC bit be cleared
wRADIODRVTunerReg[ 0x02] &= ~(0x0100);
_RADIODRV_WriteReg(0x02,wRADIODRVTunerReg);
//added time-out method to avoid radio system hang
dwRadioDrvTime=OS_GetSysTimer();
do{
_RADIODRV_ReadReg(0x0A, wRADIODRVTunerReg);
if((OS_GetSysTimer()-dwRadioDrvTime)>COUNT_2_SEC )
{
// printf("\n @@SF2");
return RADIODRV_SEEK_ERR;
}
} while ((wRADIODRVTunerReg[0x0A] & 0x4000) != 0x0000);
//[step5]: Read the channel number
_RADIODRV_ReadReg(0x0B, wRADIODRVTunerReg);
//[step6 ]: return the seek status
//return 0 is successful and 1 is fail
if((wRADIODRVTunerReg[0x0A] & 0x2000))
{
printf("\n @seek error");
return RADIODRV_SEEK_ERR;
}
else
{
// printf("\n @seek ok");
return RADIODRV_SEEK_NOERR;
}
}
//*********************************************************************************************************
// @summary This function be used to seek station
// @param bSeekDIR if _bSeekDir as TRUN, the seek up direction, else _bSeekDir as FALSE, the seek down direction
// @return Get the seek status
// @retval TRUE Seek station successfully
// @retval FALSE Seek station fail
// @description
// This function be used to seek station
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_Seek(BYTE bSeekDIR) //seek up as 1 / seek down 0
{
if(!_RADIODRV_SEEKAction(bSeekDIR)) //seek ok
{
if((RADIODRV_GetBand()==RADIODRV_BS_USA)|(RADIODRV_GetBand()==RADIODRV_BS_JapWide))
{
if(RADIODRV_GetFreq()==10800) //usa max frequency 108Mhz
{
// printf("\n @@ SEEK MAX");
if(!_RADIODRV_SEEKAction(bSeekDIR))
return RADIODRV_SEEK_NOERR;
else
return RADIODRV_SEEK_ERR;
}
}
else // japan
{
if(RADIODRV_GetFreq()==9000) //japan max frequency 90Mhz
{
if(!_RADIODRV_SEEKAction(bSeekDIR))
return RADIODRV_SEEK_NOERR;
else
return RADIODRV_SEEK_ERR;
}
}
return RADIODRV_SEEK_NOERR;
}
else
{
return RADIODRV_SEEK_ERR;
}
}
//*********************************************************************************************************
// @summary This function be used to auto scan
// @param wFreq Desired frequency which start auto scan
// @param wPreSetArray Be used to record the preset stations.
// @param bCount Desired total auto scan stations
// @param bFlag Force to stop auto scan
// @return Get the auto scan status
// @retval TRUE Get the auto scan successfully
// @retval FALSE Get the auto scan fail
// @description
// This function be used to auto scan stations
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_AutoScan(WORD wFreq,WORD* wPreSetArray, BYTE bCount, BYTE bFLAG)
{
BYTE bIndex;
BYTE bRADIODRVStauts; //record seek status
WORD wRADIODRV_CurrentFreq;
wRADIODRV_CurrentFreq=0;
bRADIODRVStauts=0;
// printf("\n@@ start auto scan");
RADIODRV_SetMute(1); //dis-able mute
//Step 1: initial preset array
for (bIndex=0; bIndex<bCount; bIndex++)
{
wPreSetArray[bIndex] = 0xFFFF;
}
//step 2: auto scan from setting of frequency
RADIODRV_tune(wFreq);
//step3 : loop to do auto scan from setting frequency to couter station
for(bIndex=0; bIndex<bCount;bIndex++)
{ //[step4.1] : check error condition or force break
if(bFLAG) break;
//[step3.2]: store frequency for current station
//[step3.3]: To do next station
bRADIODRVStauts=RADIODRV_Seek(1);
wRADIODRV_CurrentFreq=RADIODRV_GetFreq();
if(!bRADIODRVStauts)
{
wPreSetArray[bIndex]=wRADIODRV_CurrentFreq;
}
else
{
break;
}
if(wRADIODRV_CurrentFreq>=wFreq) break; //don't loop to seek
}
if(bRADIODRVStauts)
{
return RADIODRV_ERR;
}
else
{
return RADIODRV_NOERR;
}
RADIODRV_SetMute(0); //enable mute
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -