📄 radiodrv.c
字号:
bRDS_GRP=(BYTE)(wRADIODRVTunerReg[0x0D]>>11);
//step[2]: needs more time to check actual ECC code
if(bRDS_GRP==RDS_TYPE_1A)
{
if((wRADIODRVTunerReg[0x0E]&0x7000)==0x0000) //check the variant code
{
if(bRADIODRV_ECC==(wRADIODRVTunerReg[0x0E]&0x000F))
{
bRADIODRV_ECC=(wRADIODRVTunerReg[0x0E]&0x000F);
bRADIODRV_CountECC=bRADIODRV_CountECC+1;
}
else
{
bRADIODRV_ECC=(wRADIODRVTunerReg[0x0E]&0x000F);
}
//if get the ECC code count more than RDS_VALIDATE_LIMIT, then get the ECC value
if(bRADIODRV_CountECC>=RDS_VALIDATE_LIMIT)
{
pbRDS_ECC[0]=0x01;
pbRDS_ECC[1]=(wRADIODRVTunerReg[0x0E]&0x000F);
bRADIODRV_CountECC=0x00;
return RADIODRV_NOERR; //True
}
return RADIODRV_ERR;//false
}
return RADIODRV_ERR;//false
}
return RADIODRV_ERR;//false
}
//*********************************************************************************************************
// @summary This function be used to access PTY info. from the broadcasting
// @param pbRDS_ECC User needs to access PTY info. from the broadcasting
// @return Get the status of the PTY info.
// @retval TRUE Get the PTY code successfully
// @retval FALSE Get the PTY code fail
// @description
// This function be used to access PTY code from the broadcasting
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_RDS_PTY(BYTE* pbRDS_PTY)
{
BYTE bIndex;
BYTE bRDS_PTY;
//Needs more time to get the PTY code, The purpose is that get correct PTY value
if(bRADIODRV_PTY==(BYTE)((wRADIODRVTunerReg[0xD]>>5) & 0x1f))
{
bRADIODRV_PTY=(BYTE)((wRADIODRVTunerReg[0xD]>>5) & 0x1f); //pty code
bRADIODRV_CountPTY+=1;
}
else
{
bRADIODRV_PTY=(BYTE)((wRADIODRVTunerReg[0xD]>>5) & 0x1f);
return FALSE;
}
if(bRADIODRV_CountPTY>=RDS_VALIDATE_LIMIT)
{
// printf("\n @@ PTY_1");
if(strcmp(pbRDS_PTY,bRADIODRV_RDS_PTY)) //pty code string
{
bRDS_PTY=(BYTE)((wRADIODRVTunerReg[0xD]>>5) & 0x1f);//get the PTY
for(bIndex=0;bIndex<9;bIndex++)
pbRDS_PTY[bIndex]= 0x20; //clear the array
// printf("\n @@ PTY_2");
switch(bRDS_PTY)
{
case RDS_PTY_NONE:
strcpy(pbRDS_PTY+1,"None\0");
break;
case RDS_PTY_NEWS:
strcpy(pbRDS_PTY+1,"News\0");
break;
case RDS_PTY_AFFAIRS:
strcpy(pbRDS_PTY,"Affairs\0");
break;
case RDS_PTY_INFO:
strcpy(pbRDS_PTY+1,"Info\0");
break;
case RDS_PTY_SPORT:
strcpy(pbRDS_PTY+1,"Sport\0");
break;
case RDS_PTY_EDUCATE:
strcpy(pbRDS_PTY+1,"Educate\0");
break;
case RDS_PTY_DRAMA:
strcpy(pbRDS_PTY+1,"Drama\0");
break;
case RDS_PTY_CULTURE:
strcpy(pbRDS_PTY+1,"Culture\0");
break;
case RDS_PTY_SCIENCE:
strcpy(pbRDS_PTY+1,"Science\0");
break;
case RDS_PTY_VARIED:
strcpy(pbRDS_PTY+1,"Varied\0");
break;
case RDS_PTY_POPM:
strcpy(pbRDS_PTY+1,"Pop M\0");
break;
case RDS_PTY_ROCKM:
strcpy(pbRDS_PTY+1,"ROCK M\0");
break;
case RDS_PTY_EASYM:
strcpy(pbRDS_PTY+1,"Easy M\0");
break;
case RDS_PTY_LIGHTM:
strcpy(pbRDS_PTY+1,"Light M\0");
break;
case RDS_PTY_CLASSICS:
strcpy(pbRDS_PTY+1,"Classics\0");
break;
case RDS_PTY_OTHERM:
strcpy(pbRDS_PTY+1,"Other M\0");
break;
case RDS_PTY_Weather:
strcpy(pbRDS_PTY+1,"Weather\0");
break;
case RDS_PTY_FINANCE:
strcpy(pbRDS_PTY+1,"Finance\0");
break;
case RDS_PTY_CHIDREN:
strcpy(pbRDS_PTY+1,"Children\0");
break;
case RDS_PTY_SOCIAL:
strcpy(pbRDS_PTY+1,"Social\0");
break;
case RDS_PTY_RELIGION:
strcpy(pbRDS_PTY+1,"Religion\0");
break;
case RDS_PTY_PHONE:
strcpy(pbRDS_PTY+1,"Phone In\0");
break;
case RDS_PTY_TRAVEL:
strcpy(pbRDS_PTY+1,"Travel\0");
break;
case RDS_PTY_LEISURE:
strcpy(pbRDS_PTY+1,"Leisure\0");
break;
case RDS_PTY_JAZZ:
strcpy(pbRDS_PTY+1,"JAZZ\0");
break;
case RDS_PTY_COUNTRY:
strcpy(pbRDS_PTY+1,"Country\0");
break;
case RDS_PTY_NATION:
strcpy(pbRDS_PTY+1,"Nation M\0");
break;
case RDS_PTY_OLDIES:
strcpy(pbRDS_PTY+1,"Oldies\0");
break;
case RDS_PTY_FOLKM:
strcpy(pbRDS_PTY+1,"Folk M\0");
break;
case RDS_PTY_DOC:
strcpy(pbRDS_PTY+1,"Document\0");
break;
case RDS_PTY_TEST:
strcpy(pbRDS_PTY+1,"TEST\0");
break;
case RDS_PTY_ALARM:
strcpy(pbRDS_PTY+1,"Alarm\0");
break;
default:
printf("\n @@ No PTY");
return RADIODRV_ERR;
break;
}
//store the radio program type
strcpy(bRADIODRV_RDS_PTY,pbRDS_PTY);
//Get the string length
bIndex=1;
while(pbRDS_PTY[bIndex]!='\0')
bIndex++;
pbRDS_PTY[0]=bIndex-1;
//printf("\n @@PTY_L %hx",pbRDS_PTY[0]);
bRADIODRV_CountPTY=0x00;
if(bRDS_PTY==RDS_PTY_NONE)
{
return (!bRDS_PTY); //return 0xFF
}
else
{
return bRDS_PTY; //return the PTY
}
}
else
{
// printf("\n @@ PTY NS~~");
return RADIODRV_ERR;
}
}
return RADIODRV_ERR;
}
//*********************************************************************************************************
// @summary This function be used to access PS info. from the broadcasting
// @param pbRDS_PS User needs to access PS info. from the broadcasting
// @return Get the status of the PS info.
// @retval TRUE Get the PS code successfully
// @retval FALSE Get the PS code fail
// @description
// This function be used to access PS code from the broadcasting
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_RDS_PS(BYTE* pbRDS_PS)
{
BYTE bPSIndex=0;
// BYTE bIndex;
//step[1]: read program service name index which using for character index
bPSIndex=(wRADIODRVTunerReg[0x0d]&0x03)*2;
//step[2]: put the character to program service array
bRADIODRV_RDS_PS[bPSIndex+1]=(wRADIODRVTunerReg[0x0f]>>0x08);//high word
bRADIODRV_RDS_PS[bPSIndex+2]=(wRADIODRVTunerReg[0x0f]&0xFF);//low word
//Step[3]:To confirm the completed program service name.
//The total program service name has 8 characters to fill the PS array.So, needs to confirm tatal PS filled the array!!
if((bRADIODRV_RDS_PS[1]==(wRADIODRVTunerReg[0x0f]>>0x08))&&(bRADIODRV_RDS_PS[2]==(wRADIODRVTunerReg[0x0f]&0xFF)))
bRADIODRV_CountPS|=0x01;
if((bRADIODRV_RDS_PS[3]==(wRADIODRVTunerReg[0x0f]>>0x08))&&(bRADIODRV_RDS_PS[4]==(wRADIODRVTunerReg[0x0f]&0xFF)))
bRADIODRV_CountPS|=0x02;
if((bRADIODRV_RDS_PS[5]==(wRADIODRVTunerReg[0x0f]>>0x08))&&(bRADIODRV_RDS_PS[6]==(wRADIODRVTunerReg[0x0f]&0xFF)))
bRADIODRV_CountPS|=0x04;
if((bRADIODRV_RDS_PS[7]==(wRADIODRVTunerReg[0x0f]>>0x08))&&(bRADIODRV_RDS_PS[8]==(wRADIODRVTunerReg[0x0f]&0xFF)))
bRADIODRV_CountPS|=0x08;
//step[3]: check the the program service name. if the PS is different, program must copy new PS strings
//The bRADIODRV_CountPS=0x0F mean the Program service name is completed
if(((bRADIODRV_CountPS&0x0F)==0x0F)&&(strcmp(pbRDS_PS,bRADIODRV_RDS_PS)))
{
//the length of program service name
bRADIODRV_RDS_PS[0]=0x08;
strcpy(pbRDS_PS,bRADIODRV_RDS_PS);
bRADIODRV_CountPS=0x00;//reset the counter
return RADIODRV_NOERR; //Needs to return the character table. Support three Character table in the RDS spec
// for(bIndex=0;bIndex<9;bIndex++)
//printf("\n@@_1 %hx,%hx",bRADIODRV_RDS_PS[bIndex],bRADIODRV_RDS_PS[bIndex]);
}
return RADIODRV_ERR;
}
//*********************************************************************************************************
// @summary This function be used to access TP info. from the broadcasting
// @param None
// @return Get the status of the TP info.
// @retval TRUE Get the TP code successfully
// @retval FALSE Get the TP code fail
// @description
// This function be used to access TP code from the broadcasting
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_RDS_TP(void)
{
//Traffic programme identification code in all group
//read the TP bit
bRADIODRV_TP=(BYTE)(wRADIODRVTunerReg[0x0D]>>10);
if(bRADIODRV_TP)
{
//printf("\n @@TP");
return RADIODRV_NOERR;
}
else
{
//printf("\n @@NON_TP");
return RADIODRV_ERR;
}
}
//*********************************************************************************************************
// @summary This function be used to access TA info. from the broadcasting
// @param None
// @return Get the status of the TA info.
// @retval TRUE Get the TA code successfully
// @retval FALSE Get the TA code fail
// @description
// This function be used to access TA code from the broadcasting
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_RDS_TA(void)
{
//Traffic announcement code
bRADIODRV_TA=(BYTE)(wRADIODRVTunerReg[0x0D]>>4);
if(bRADIODRV_TA)
{
return RADIODRV_NOERR;
}
else
{
return RADIODRV_ERR;
}
}
//*********************************************************************************************************
// @summary This function be used to access DI info. from the broadcasting
// @param None
// @return Get the status of the DI info.
// @retval TRUE Get the DI code successfully
// @retval FALSE Get the DI code fail
// @description
// This function be used to access DI(decoder identification) code from the broadcasting.
// There are 4-bit used to indicate different operating modes to switch individual decoders on/off
// and to indicate if PTY codes in the transmission are dynamically switched
// @bug None
// @history
//*********************************************************************************************************
BYTE RADIODRV_RDS_DI(void)
{
BYTE bDIIndex;
BYTE bDItmp;
bDIIndex=(wRADIODRVTunerReg[0x0d]&0x03);//get the DI index
bDItmp=(BYTE)((wRADIODRVTunerReg[0x0D]>>2)&0x01); //get the DI value
bRADIODRV_DI|=(bDItmp<<(3-bDIIndex));
// pbRDS_DI[0]=(bRADIODRV_DI&0x0F);
// printf("\n @@ DI %hx, %hx, %x",bDIIndex,bRADIODRV_DI,(wRADIODRVTunerReg[0x0d]));
return (bRADIODRV_DI&0x0F);
}
//*********************************************************************************************************
// @summary This function be used to access RT info. from the broadcasting
// @param pbRDS_RT Desired display radio text
// @return Get the status of the RT info.
// @retval TRUE Get the RT info. successfully
// @retval FALSE Get the RT info. fail
// @description
// This function be used to access radio text from the broadcasting.
// @
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -