📄 radiodrv.c
字号:
//**************************************************************************
// Copyright (c) 2007, Cheertek Inc . All rights reserved.
// J000, all right reserved.
// Product : Firmware
//
// Date : 2007.02.26
// Author : Cheertek (J000 Winnie)
// Purpose : Provide all Raiod tuner driver
// Sources : Radiodrv.h/ Radiodrv.c
//***************************************************************************
// Modification use :
//**************************************************************************
// Update
// Date : 2007.02.26
// Name : Cheertek (J000 Winnie)
// Description :
//
// Item Source
// ---------------------------------------- -------------------
//**************************************************************************
#include "winav.h"
#include "chips.h"
#include "hio.h"
#include "RADIODRV.h"
#ifdef SUPPORT_RADIO_TUNER
//*********************************************************************************************************
// @summary This is use delay time for radio function
// @param _bCount be used to delay time
// @return None
// @retval None
// @description
// This function be used to delay some time for radio driver function
// @bug None
// @history
//*********************************************************************************************************
void _Delay_RADIODRV(BYTE _bCount)
{
for(;_bCount > 0; _bCount--)
{
}
}
//*********************************************************************************************************
// @summary Control the IIC SCL as High
// @param None
// @return None
// @retval None
// @description
// This function be used to control SCL pin of IIC as High state
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_SCLHIGH(void)
{
HAL_WriteGPIO(GRP_RADIOSCK, PIN_RADIOSCK, 1);
_Delay_RADIODRV(40);
}
//*********************************************************************************************************
// @summary Control the IIC SCL as Low
// @param None
// @return None
// @retval None
// @description
// This function be used to control SCL pin of IIC as low state
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_SCLLOW(void)
{
HAL_WriteGPIO(GRP_RADIOSCK, PIN_RADIOSCK, 0);
_Delay_RADIODRV(100);
}
//*********************************************************************************************************
// @summary Control the IIC SDA as HIGH
// @param None
// @return None
// @retval None
// @description
// This function be used to control SCL pin of IIC as HIGH state
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_SDAHIGH(void)
{
HAL_WriteGPIO(GRP_RADIOSDA, PIN_RADIOSDA, 1);
_Delay_RADIODRV(40);
}
//*********************************************************************************************************
// @summary Control the IIC SDA as LOW
// @param None
// @return None
// @retval None
// @description
// This function be used to control SCL pin of IIC as LOW state
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_SDALOW(void)
{
HAL_WriteGPIO(GRP_RADIOSDA, PIN_RADIOSDA, 0);
_Delay_RADIODRV(40);
}
//*********************************************************************************************************
// @summary Send the start signal of IIC at SCL/SDA pin
// @param None
// @return None
// @retval None
// @description
// This function be used to send start signal at SCL/SDA pin
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_START(void)
{
_RADIODRV_IIC_SCLHIGH();
_RADIODRV_IIC_SDAHIGH();
_RADIODRV_IIC_SDALOW();
_RADIODRV_IIC_SCLLOW();
}
//*********************************************************************************************************
// @summary Send the stop signal of IIC at SCL/SDA pin
// @param None
// @return None
// @retval None
// @description
// This function be used to send stop signal at SCL/SDA pin
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_STOP(void)
{
_RADIODRV_IIC_SCLLOW();
_RADIODRV_IIC_SDALOW();
_RADIODRV_IIC_SCLHIGH();
_RADIODRV_IIC_SDAHIGH();
}
//*********************************************************************************************************
// @summary Get the ACK signal from other device via SCL/SDA
// @param None
// @return Make sure the ack signal
// @retval TRUE get the ack signal successfully
// @retval FALSE get the ack signal fail
// @description
// This function be used to get the ack signal from other device via SCL/SDA
// @bug None
// @history
//*********************************************************************************************************
BOOL _RADIODRV_IIC_GetACK(void)
{
BYTE _bRADIODRVData;
_Delay_RADIODRV(10);
HAL_ReadGPIO(GRP_RADIOSDA,PIN_RADIOSDA); //setting input mode
_Delay_RADIODRV(10);
_RADIODRV_IIC_SCLHIGH();
_bRADIODRVData = HAL_ReadGPIO(GRP_RADIOSDA, PIN_RADIOSDA); //ack as low
_RADIODRV_IIC_SCLLOW();
if(_bRADIODRVData==0) //ack
return RADIODRV_IIC_ACK;
return RADIODRV_IIC_NONACK;
}
//*********************************************************************************************************
// @summary To set the ACK signal to other device via SCL/SDA
// @param bACK Send ack signal. if bACK as TRUE, the low signal of sda pin. otherwise, the high signal of sda pin
// @return None
// @retval None
// @description
// This function be used to set the ack signal to other device via SCL/SDA
// @bug None
// @history
//*********************************************************************************************************
void _RADIODRV_IIC_SETACK(BOOL bACK)
{
if(bACK)
_RADIODRV_IIC_SDALOW();
else
_RADIODRV_IIC_SDAHIGH(); //set sda as non-ack before stop
_RADIODRV_IIC_SCLHIGH();
_RADIODRV_IIC_SCLLOW();
}
//*********************************************************************************************************
// @summary Write byte data to radio device via SCL/SDA pin
// @param bData Desired write byte
// @return Make sure the write byte status
// @retval TRUE Write byte successfully
// @retval FALSE Write byte fail
// @description
// This function be used to write registers of radio tuner to control radio device by IIC interface
// @bug None
// @history
//*********************************************************************************************************
BOOL _RADIODRV_WriteBYTE(BYTE bData)
{
BYTE bIndex;
for(bIndex = 0;bIndex < 8; bIndex++)
{
if( bData & 0x80)
_RADIODRV_IIC_SDAHIGH();
else
_RADIODRV_IIC_SDALOW();
_RADIODRV_IIC_SCLHIGH();
bData = bData<<1 ;
_RADIODRV_IIC_SCLLOW();
}
return _RADIODRV_IIC_GetACK();
}
//*********************************************************************************************************
// @summary Read byte data to radio device via SCL/SDA pin
// @param bData Desired read byte
// @return Make sure the read byte status
// @retval TRUE read byte successfully
// @retval FALSE read byte fail
// @description
// This function be used to read registers of radio tuner to control radio device by IIC interface
// @bug None
// @history
//*********************************************************************************************************
BYTE _RADIODRV_ReadBYTE(BYTE bACK)
{
BYTE bData;
BYTE bIndex;
bData=0x00;
for ( bIndex = 0; bIndex< 8; bIndex++)
{
bData =bData<< 1;
if ( HAL_ReadGPIO(GRP_RADIOSDA, PIN_RADIOSDA))
bData |= 0x01;
_RADIODRV_IIC_SCLHIGH();
_RADIODRV_IIC_SCLLOW();
}
_RADIODRV_IIC_SETACK(bACK) ;
return bData;
}
//*********************************************************************************************************
// @summary Write register of si4703 radio tuner which size of word to control si4703 radio tuner
// @param bLastReg desired writes last register address
// @param wRegArray desired writes register data
// @return Make sure that write registers status
// @retval TRUE write Si4703 radio tuner successfully
// @retval FALSE write Si4703 radio tuner fail
// @description
// This function be used to write registers of radio tuner which size of word to control si4703 radio tuner
// @bug None
// @history
//*********************************************************************************************************
BYTE _RADIODRV_WriteReg(BYTE bLastReg,WORD* wRegArray)
{
//RADIODRV tuner start write reg from 0x02
BYTE bRADIODRV_Reg=0x02;
_RADIODRV_IIC_START();
if(_RADIODRV_WriteBYTE(RADIODRV_ADDRESS)==FALSE)
{
goto ERROR_W;
}
//write the word which pairs of byte
do
{
_RADIODRV_WriteBYTE(wRegArray[bRADIODRV_Reg]>>8); //upper-byte
_RADIODRV_WriteBYTE(wRegArray[bRADIODRV_Reg]&0xff);//lower-byte
bRADIODRV_Reg = (bRADIODRV_Reg + 1) & 0x0f;
}while(bRADIODRV_Reg!=(bLastReg+1)&0x0f);
_RADIODRV_IIC_STOP(); //stop will reset internal counter of si4703
return RADIODRV_NOERR;
ERROR_W:
_RADIODRV_IIC_STOP();
printf("\n@ err_w");
return RADIODRV_ERR;
}
//*********************************************************************************************************
// @summary Read register of si4703 radio tuner which size of word to control si4703 radio tuner
// @param bLastReg desired read last register address
// @param wRegArray desired read register data
// @return Make sure that read registers status
// @retval TRUE read Si4703 radio tuner successfully
// @retval FALSE read Si4703 radio tuner fail
// @description
// This function be used to read registers of radio tuner which size of word to control si4703 radio tuner
// @bug None
// @history
//*********************************************************************************************************
BYTE _RADIODRV_ReadReg(BYTE bLastReg, WORD* wRegArray)
{
BYTE bRADIODRV_Temp;
WORD wRADIODRV_Temp;
//start read register from 0x0a
BYTE bRADIODRV_Reg=0x0A;
_RADIODRV_IIC_START();
if(_RADIODRV_WriteBYTE(RADIODRV_ADDRESS|0x01)==FALSE)
{
goto ERROR_R;
}
do
{
wRADIODRV_Temp=_RADIODRV_ReadBYTE(1);//high-byte
bRADIODRV_Temp=_RADIODRV_ReadBYTE(bLastReg-bRADIODRV_Reg);//lower-byte
wRegArray[bRADIODRV_Reg]=wRADIODRV_Temp*256+bRADIODRV_Temp; //get data of reg.
bRADIODRV_Reg = (bRADIODRV_Reg + 1)&0x0f;
}while(bRADIODRV_Reg!=((bLastReg+1)&0x0f));
_RADIODRV_IIC_STOP(); //stop will reset internal counter of si4703
return RADIODRV_NOERR;
ERROR_R:
_RADIODRV_IIC_STOP();
printf("\n @@ err_r");
return RADIODRV_ERR;
}
//*********************************************************************************************************
// @summary Reset the radio tuner
// @param None
// @return None
// @retval None
// @description
// This function be used to reset the radio tuner for si4703
// @bug None
// @history
//*********************************************************************************************************
void RADIODRV_Reset(void)
{
// printf("\n@@ Reset!!") ;
//first time needs to select 2-wire mode when reset pin rising edge
HAL_WriteGPIO(GRP_RADIOGPIO3, PIN_RADIOGPIO3, 1);
HAL_WriteGPIO(GRP_RADIOSDA, PIN_RADIOSDA, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -