/*
** FILE
** dsa.c
**
** DESCRIPTION
** control DSA interface.
**
*/
///////////////////////////////////////////////////
#include "global.h"
#include "timer.h"
#include "I2C.h"
#ifdef SUPPORT_AUDIO
#include "teavol.h"
#endif
#include "LCD.h"
#ifdef SUPPORT_IR
#include "ir.h"
#endif
#include "key.h"
#include "keyproc.h"
#ifdef SUPPORT_TV
#include "tv.h"
#include "typedef.h"
#include "at1819_osd.h"
#endif
#if defined(MODE_V3)
extern BYTE data gbDispTimer1;
extern BYTE data CloseWaiting;
extern BIT bOpenwaiting;
extern BYTE data gbCDResetTimer;
//=========================
#endif
#define DSA_T250MS TIMER_250ms
#define SetDSA_DAT(x) DSA_DAT = x
#define SetDSA_ACK(x) DSA_ACK = x
#define SetDSA_STB(x) DSA_STB = x
#define GetDSA_DAT() (DSA_DAT)
#define GetDSA_ACK() (DSA_ACK)
#define GetDSA_STB() (DSA_STB)
#define SetDAT_READ() DSA_DAT = 1
#define SetACK_READ() DSA_ACK = 1
#define SetSTB_READ() DSA_STB = 1
BYTE data gbDSATimer = 0;
BIT bCDPlayState = 0;
//BIT FLAG=0;
//=====modify===============
// 4 - 29 - v1
// cd-mp3 display bug
//========================
BIT bClear=0,bOpenClose ;
BYTE gbDiscState;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
#define DSA_CMD_BUF_SIZE 10
BYTE MuteEn=0;
BIT bMuteFreeze=0;
BIT bMuteOff=0;
//=========================
//=====modify==============
// 6 - 21 - v1
// dsp reset
//=========================
BIT bOldState=0;
BIT bCheckUp=0;
//=========================
//=====modify==============
// 6 - 23 - v1
// dsp reset
//=========================
BIT bCDReset;
BIT bCDResetAct;
#ifdef SUPPORT_DSA_RESET
extern BYTE gbDsaReset;
BIT bDsafirst;
#endif
//==========================
BYTE gbNeedOpen=0;
BIT dsa_send_flag = 0;
BIT dsa_receive_flag = 0;
static BYTE data dsa_mode = 0;
static UINT16 data dsa_in_data;
static UINT16 data dsa_out_data = 0;
static BYTE idata dsa_send_data_head, dsa_send_data_tail;
static UINT16 idata dsa_send_data[DSA_CMD_BUF_SIZE];
#define DSA_IDLE 0
#define DSA_R_SYNC 1
#define DSA_R_SYNC_WAIT 2
#define DSA_R_READ 3
#define DSA_R_WAIT 4
#define DSA_R_ACK 5
#define DSA_R_END 6
#define DSA_R_END_ALL 7
#define DSA_T_SYNC 8
#define DSA_T_SYNC_WAIT 9
#define DSA_T_SEND 10
#define DSA_T_WAIT 11
#define DSA_T_ACK 12
#define DSA_T_END 13
#define DSA_T_END_ALL 14
Uint16 tmp=0;
void write_data_to_dsabuf(Uint16 vaule)
{
#ifdef SIMULATE_232
RS232_WriteStr("s=");
RS232_WriteHex81((BYTE)(vaule>>8));
RS232_WriteHex81((BYTE)(vaule&0x00ff));
#endif
dsa_send_data[dsa_send_data_tail] = vaule;
dsa_send_data_tail++;
if(dsa_send_data_tail >= DSA_CMD_BUF_SIZE)
dsa_send_data_tail = 0;
}
static void Dsa_Rcom(void)
{
if((dsa_send_flag == 0) && (dsa_send_data_head != dsa_send_data_tail)){
dsa_out_data = dsa_send_data[dsa_send_data_head];
dsa_send_flag = 1;
dsa_send_data_head++;
if(dsa_send_data_head >= DSA_CMD_BUF_SIZE)
dsa_send_data_head = 0;
}
}
static void Dsa_Process(void)
{
static BYTE nCounter;
switch(dsa_mode){
case DSA_IDLE: // reset dsa to idle mode; detect send or receive
gbDSATimer = DSA_T250MS;
if(!GetDSA_DAT()){
dsa_mode = DSA_R_SYNC;
SetDSA_ACK(0);
nCounter = 0;
}else if(dsa_send_flag){
/* if((dsa_out_data&0xff00)==0xd200){
// LCD_Debug_Key(dsa_out_data);
// LCD_Debug_Key(dsa_send_data_tail);
//gbDispTimer1=TIMER_1s;
//while(gbDispTimer1);
tmp=dsa_out_data;
}*/
SetDSA_DAT(0);
dsa_mode = DSA_T_SYNC;
nCounter = 0;
}
else Dsa_Rcom();
break;
case DSA_T_SYNC:
if(!GetDSA_ACK()){
SetDSA_DAT(1);
dsa_mode = DSA_T_SYNC_WAIT;
}
break;
case DSA_T_SYNC_WAIT:
if(GetDSA_ACK()){
dsa_mode = DSA_T_SEND;
}
break;
case DSA_T_SEND:
if(dsa_out_data & (1 << (15 - nCounter))) SetDSA_DAT(1);
else SetDSA_DAT(0);
SetDSA_STB(0);
dsa_mode = DSA_T_WAIT;
break;
case DSA_T_WAIT:
if(!GetDSA_ACK())
{
SetDSA_STB(1);
dsa_mode = DSA_T_ACK;
}
break;
case DSA_T_ACK:
if(GetDSA_ACK())
{
if(nCounter == 15)
{
SetSTB_READ();
SetDAT_READ();
SetDSA_ACK(0);
dsa_mode = DSA_T_END;
} else {
nCounter++;
dsa_mode = DSA_T_SEND;
}
}
break;
case DSA_T_END:
if(!GetDSA_STB())
{
BIT bRCVResponse = GetDSA_DAT();
SetDSA_ACK(1);
dsa_mode = DSA_T_END_ALL;
if(bRCVResponse)
{
dsa_send_flag = 0;
}
}
break;
case DSA_T_END_ALL:
if(GetDSA_STB())
{
SetDAT_READ();
SetACK_READ();
SetSTB_READ();
dsa_mode = DSA_IDLE;
}
break;
case DSA_R_SYNC:
if(GetDSA_DAT())
{
SetSTB_READ();
SetDSA_ACK(1);
dsa_in_data = 0;
dsa_mode = DSA_R_READ;
}
break;
case DSA_R_READ:
if(!GetDSA_STB())
{
dsa_in_data |= GetDSA_DAT();
SetDSA_ACK(0);
dsa_mode = DSA_R_WAIT;
}
break;
case DSA_R_WAIT:
if(GetDSA_STB()){
SetDSA_ACK(1);
dsa_mode=DSA_R_ACK;
}
break;
case DSA_R_ACK:
if(nCounter == 15)
{
SetACK_READ();
SetDSA_DAT(1);
dsa_mode = DSA_R_END;
} else {
nCounter++;
dsa_in_data <<= 1;
dsa_mode = DSA_R_READ;
}
break;
case DSA_R_END:
if(!GetDSA_ACK())
{
SetDSA_DAT(1);
SetDSA_STB(0);
dsa_mode = DSA_R_END_ALL;
}
break;
case DSA_R_END_ALL:
if(GetDSA_ACK())
{
SetDAT_READ();
SetACK_READ();
SetSTB_READ();
dsa_mode = DSA_IDLE;
dsa_receive_flag = 1;
}
break;
default:
gbDSATimer = 0;
dsa_mode = DSA_IDLE;
break;
}
if(!gbDSATimer)
{
SetDAT_READ();
SetACK_READ();
SetSTB_READ();
dsa_mode = DSA_IDLE;
dsa_send_flag = 0;
dsa_receive_flag=0;
}
}
static void VCD_key_server()
{
Uint8 curkey;
curkey = SYS_get_key();
if(gbOsdTimer&0x80){
gbOsdTimer=0;
if(gbSysState.Sub==TV_NORMAL_STATE)OsdClear();
}
#ifdef SIMULATE_232
if(curkey&0x3f) send_asc(" key=", curkey);
#endif
#ifdef SUPPORT_MUTE_RELEASE
if(bMuteFreeze){
if(((curkey & 0x3f)!=KEY_SOURCE)&&((curkey & 0x3f)!=KEY_MUTE)\
&&((curkey & 0x3f)!=KEY_VOL_UP)&&((curkey &0x3f)!=KEY_VOL_DOWN)\