?? tuner_drv.c
字號:
/*
********************************************************************************
* Description: FM Module - Driver for EDA5800
* Author: Eric Xie
********************************************************************************
*/
#include <Creg.h>
#include "Macro.h"
#include "Memap.h"
#include "MsgDef.h"
#include "Resource.h"
#include "Global.h"
#ifdef FM_MODULE
#define IN_TUNER_DRV
#include "FmMacro.h"
#include "FmStruct.h"
#include "FmGlobal.h"
#include "Tuner_drv.h"
__attribute__((section(".fm_data, \"aw\"")))
unsigned int cwFMDefault[]={ //init data table
0x0000,
0x0000,
0x9881,//0x02 //d881-->9881 for first init don't need voice output,0xb881 no stereo
0x0000, //97100KHZ
0x0400, //no interruput
0x10f8, //0x05 //rssi=16
0x0000,
0x00cd,
0x0096,
0x0020,
0x4163, //0x0a
0x0806,
0x5800,
0x5800,
0x5800,
0x5800,
0x4c08,//0x4808,//0x10
0x20a2,
0x0000,
0x000f,
0x06de,
0xecc0, //0x15
0x0200,
0x5383,
0x95a4,
0xe848,
0x0700,//0x1a
0x00ff,
0x889b,
0x0d84,
0x4f04,
0x8832,
0x7f71,//0x20
0x0660,
0x4010,
0x6002,
0x1808,
0x6458,
0x787f, //0x26
0x0100,
0xc040,
0xc020,
0x0024,//0x2a
0x0400,
0x0020, //0x0160 softemute
};
//Used for dummy IIC
#define FM_RAD5800_ADD 0x10
#define FM_READ_COM ((FM_RAD5800_ADD<<1)|0x01)
#define FM_WRITE_COM ((FM_RAD5800_ADD<<1)&(~0x01))
#define SDA_BIT 1
#define SCL_BTI 2
#define SDA (1<<1)
#define SCL (1<<2)
#define SDA_IN write_mem(GPIO_PCON1,((read_mem(GPIO_PCON1)&0xffc3)|0x0010))
#define SDA_OUT write_mem(GPIO_PCON1,((read_mem(GPIO_PCON1)&0xffc3)|0x0014))
#define SCL_HIGH write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)|SCL));
#define SCL_LOW write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SCL)));
#define SDA_HIGH write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)|SDA))
#define SDA_LOW write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA)))
/*
********************************************************************************
* Function name : DelayXus()
* Author: Eric Xie
* Description: Dummy IIC - Delay Xus.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
void DelayXus(unsigned int X)
{
unsigned int i;
for(i = X; i >= 1; i--)
{
delay_nops(CurrCpuFreq);
}
}
/*
********************************************************************************
* Function name : I2C_Start()
* Author: Eric Xie
* Description: Dummy IIC - Start.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
void I2C_Start(void)
{
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)|SCL|SDA));
SDA_OUT;
DelayXus(10);
SDA_LOW;
DelayXus(20);
SCL_LOW;
DelayXus(10);
}
/*
********************************************************************************
* Function name : I2C_Stop()
* Author: Eric Xie
* Description: Dummy IIC - Stop.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
void I2C_Stop(void)
{
SDA_LOW;
SDA_OUT;
DelayXus(10);
SCL_HIGH;
DelayXus(20);
SDA_HIGH;
}
/*
********************************************************************************
* Function name : I2C_SendAck()
* Author: Eric Xie
* Description: Dummy IIC - Send ACK.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
void I2C_SendAck(unsigned int ack)
{
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA))|(ack<<SDA_BIT));
SDA_OUT;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
SCL_LOW;
DelayXus(10);
}
/*
********************************************************************************
* Function name : I2C_ReadByte()
* Author: Eric Xie
* Description: Dummy IIC - Read byte.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_ReadByte(void)
{
int i;
unsigned int byte = 0;
SDA_IN;
DelayXus(10);
for(i=7;i>=0;i--)
{
SCL_HIGH;
DelayXus(10);
byte <<= 1;
byte |= ((read_mem(GPIO_PDAT1)&SDA)>>SDA_BIT);
DelayXus(10);
SCL_LOW;
DelayXus(10);
}
return byte;
}
/*
********************************************************************************
* Function name : I2C_SendByte()
* Author: Eric Xie
* Description: Dummy IIC - Send byte.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_SendByte(unsigned int byte)
{
int i;
unsigned int ack = 0;
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA))|((byte&0x0080)>>(7-SDA_BIT)));
SDA_OUT;
byte <<= 1;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
SCL_LOW;
DelayXus(10);
for(i=5;i>=0;i--)
{
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA))|((byte&0x0080)>>(7-SDA_BIT)));
byte <<= 1;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
SCL_LOW;
DelayXus(10);
}
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA))|((byte&0x0080)>>(7-SDA_BIT)));
DelayXus(10);
SCL_HIGH;
DelayXus(10);
SCL_LOW;
SDA_IN;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
ack = (read_mem(GPIO_PDAT1)&SDA);
SCL_LOW;
return ack;
}
/*
********************************************************************************
* Function name : I2C_ReadWord()
* Author: Eric Xie
* Description: Dummy IIC - Read word.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_ReadWord(void)
{
int i,j;
unsigned int word = 0;
for(j=0;j<2;j++)
{
SDA_IN;
DelayXus(10);
for(i=7;i>=0;i--)
{
SCL_HIGH;
DelayXus(10);
word <<= 1;
word |= ((read_mem(GPIO_PDAT1)&SDA)>>SDA_BIT);
SCL_LOW;
DelayXus(10);
}
if(j==0)
{
I2C_SendAck(0);
}
}
return word;
}
/*
********************************************************************************
* Function name : I2C_SendWord()
* Author: Eric Xie
* Description: Dummy IIC - Send word.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_SendWord(unsigned int word)
{
int i,j;
unsigned int ack = 0;
for(j=0;j<2;j++)
{
for(i=7;i>=0;i--)
{
write_mem(GPIO_PDAT1,(read_mem(GPIO_PDAT1)&(~SDA))|((word&0x8000)>>(15-SDA_BIT)));
SDA_OUT;
word <<= 1;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
SCL_LOW;
DelayXus(10);
}
SDA_IN;
DelayXus(10);
SCL_HIGH;
DelayXus(10);
ack = (read_mem(GPIO_PDAT1)&SDA);
if(ack)
{
break;
}
SCL_LOW;
DelayXus(10);
}
return ack;
}
/*
********************************************************************************
* Function name : I2C_ReadFMxReg()
* Author: Eric Xie
* Description: Dummy IIC - Read data.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_ReadFMxReg(unsigned int *data,unsigned int size)
{
unsigned int i,state = 0;
unsigned int ImaskTemp;
read_creg(%imask,ImaskTemp); //Disable Interrupt
bitclear_creg(%imask,15);
I2C_Start();
if(I2C_SendByte(FM_READ_COM))
{
state = 1;
goto I2C_STOP;
}
for(i=0;i<size-1;i++)
{
data[i] = I2C_ReadByte();
I2C_SendAck(0);
}
data[i] = I2C_ReadByte();
I2C_SendAck(1);
I2C_STOP:
I2C_Stop();
write_creg(%imask,ImaskTemp); //Enable Interrupt
return state;
}
/*
********************************************************************************
* Function name : I2C_WriteFMxReg()
* Author: Eric Xie
* Description: Dummy IIC - Write data.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
unsigned int I2C_WriteFMxReg(unsigned int *data,unsigned int size)
{
unsigned int i,state = 0;
unsigned int ImaskTemp;
read_creg(%imask,ImaskTemp); //Disable Interrupt
bitclear_creg(%imask,15);
I2C_Start();
if(I2C_SendByte(FM_WRITE_COM))
{
state = 1;
goto I2C_STOP;
}
for(i=0;i<size;i++)
{
if(I2C_SendByte(data[i]))
{
state = 1;
break;
}
}
I2C_STOP:
I2C_Stop();
write_creg(%imask,ImaskTemp); //Enable Interrupt
return state;
}
/*
********************************************************************************
* Function name : FmWaitSTC()
* Author: Eric Xie
* Description: EDA5800 read STC.
********************************************************************************
*/
__attribute__((section(".fm_text,\"ax\"")))
char FmWaitSTC(void)
{
char readData8[2];
if(I2C_ReadFMxReg(readData8,2)==1)
{
return(1);
}
if((readData8[0]&0x40))
{
return(0);
}
else
{
return(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -