#include "Public.h"
int _fctcpy(char name);
/*********************************************
Function: main
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:40:45
*********************************************/
void main(void)
{
_fctcpy('F'); //Load in RAM FLASH section
if(UPDATE_FLAG==M_UPDATE_FLAG)
{
BasicPinInit();
UpdateFileDetect();
FlashUpdate();
MyMain();
}
else
{
MyMain();
}
}
/*********************************************
Function: Wait10us
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:40:55
*********************************************/
void IAPWait10us(unsigned char time)
{
unsigned char i;
for(;time>0;time--)
{
for(i=24;i>0;i--);
}
}
/*********************************************
Function: Wait1ms
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:40:54
*********************************************/
void IAPWait1ms(unsigned char time)
{
for(;time>0;time--)
{
IAPWait10us(100);
}
}
/*********************************************
Function: I2C2Start
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:01:06
*********************************************/
void IAPI2C2Start(void)
{
PD_SW2_I2CClk=1;
PD_SW2_I2CData=1;
Pin_SW2_I2CData=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
/*********************************************
Function: I2C2Stop
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:01:05
*********************************************/
void IAPI2C2Stop(void)
{
unsigned char i;
#if 1
PD_SW2_I2CClk=0;
Pin_SW2_I2CClk=1;
for(i=0;(i<200)&&(!PinIn_SW2_I2CClk);i++)IAPWait10us(10);
#endif
PD_SW2_I2CClk=1;
PD_SW2_I2CData=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CData=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
/*********************************************
Function: I2C2Out8Bit
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:01:03
*********************************************/
unsigned char IAPI2C2Out8Bit(unsigned char outbyte)
{
unsigned char i;
unsigned int j;
UCharField temp;
temp.byte=outbyte;
PD_SW2_I2CClk=1;
PD_SW2_I2CData=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
for(i=0x80;i>0;i>>=1)
{
Pin_SW2_I2CClk=0;
if(outbyte&i)
Pin_SW2_I2CData=1;
else
Pin_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
/*if(i==0x80)
{
PD_SW_I2CClk=0;
for(j=0;((j<1) && (!Pin_SW_I2CClk));j++);
PD_SW_I2CClk=1;
}*/
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
Pin_SW2_I2CClk=0;
PD_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
for(i=0;(i<20)&&(PinIn_SW2_I2CData);i++) IAPWait10us(5);
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
if(PinIn_SW2_I2CData)
i=1;
else
i=0;
Pin_SW2_I2CClk=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
return(i);
}
/*********************************************
Function: I2C2In8Bit
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:01:02
*********************************************/
unsigned char IAPI2C2In8Bit(void)
{
unsigned char i,inbyte=0;
#if 1
PD_SW2_I2CClk=0;
Pin_SW2_I2CClk=1;
for(i=0;(i<200)&&(!PinIn_SW2_I2CClk);i++)IAPWait10us(10);
#endif
PD_SW2_I2CClk=1;
PD_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
for(i=0x80;i>0;i>>=1)
{
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
if(PinIn_SW2_I2CData)
inbyte|=i;
Pin_SW2_I2CClk=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
return (inbyte);
}
/*********************************************
Function: I2C2Ack
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:01:00
*********************************************/
void IAPI2C2Ack(void)
{
PD_SW2_I2CClk=1;
PD_SW2_I2CData=1;
M_WAIT_IAP;
Pin_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=0;
PD_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
/*********************************************
Function: I2C2NAck
Description:
Write/Modify: Perry.Liang
Time: 2006-8-4- 10:00:56
*********************************************/
void IAPI2C2NAck(void)
{
PD_SW2_I2CClk=1;
PD_SW2_I2CData=1;
M_WAIT_IAP;
Pin_SW2_I2CData=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=1;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
Pin_SW2_I2CClk=0;
PD_SW2_I2CData=0;
M_WAIT_IAP;
M_WAIT_IAP; // for trial
M_WAIT_IAP; // for trial
}
void IAPI2C2_WAIT_SDA(void)
{
unsigned char i;
PD_SW2_I2CData=0;
for(i=0;(i<20)&&(!PinIn_SW2_I2CData);i++) IAPWait10us(5);
}
void IAPCDSendData(void)
{
unsigned char i,TempCS,retry,acknowledge;
// asm sim;
if(IAP.SendBuff[0]==0) return;
for (retry=0;retry<3;retry++){
if (retry!=0)
{
IAPWait1ms(10);
IAPWWatchDogRefresh();
IAPI2C2Stop();
}
IAPI2C2Start();
if (IAPI2C2Out8Bit(0xE0)) continue;
IAPI2C2_WAIT_SDA();
if (IAPI2C2Out8Bit(IAP.SendBuff[0])) continue;
IAPI2C2_WAIT_SDA();
TempCS=0x5A;
for(i=1;i<IAP.SendBuff[0];i++)
{
IAPWWatchDogRefresh();
if (IAPI2C2Out8Bit(IAP.SendBuff[i])) continue;
IAPI2C2_WAIT_SDA();
TempCS+=IAP.SendBuff[i];
}
IAP.SendBuff[i]=TempCS;
if (IAPI2C2Out8Bit(IAP.SendBuff[i])) continue;
IAPI2C2_WAIT_SDA();
IAPI2C2Stop();
break;
}
// asm rim;
for(i=1;i<IAP.SendBuff[0];i++)
{
IAP.SendBuff[i]=0;
}
IAP.SendBuff[0]=0;
}
void IAPCDReadData(void)
{
unsigned char i,TempCS;
Msg_receive = 1;
// asm sim;
IAPI2C2Start();
if (IAPI2C2Out8Bit(0xE1)==1){
//while(1);
}
IAP.ReadBuff[0]=IAPI2C2In8Bit();
if(IAP.ReadBuff[0]>59)
IAP.ReadBuff[0]=59;
IAPI2C2Ack();
TempCS=0x5A;
for(i=1;i<IAP.ReadBuff[0];i++)
{
IAPWWatchDogRefresh();
IAP.ReadBuff[i]=IAPI2C2In8Bit();
IAPI2C2Ack();
TempCS+=IAP.ReadBuff[i];
}
IAP.ReadBuff[i]=IAPI2C2In8Bit();
IAPI2C2NAck();
IAPI2C2Stop();
// asm rim;
if(TempCS!=IAP.ReadBuff[IAP.ReadBuff[0]])
{
for(i=0;i<IAP.ReadBuff[0];i++)
IAP.ReadBuff[i+1]=0;
IAP.ReadBuff[0]=0;
Msg_receive = 0;
}
}
void FlashUpdate()
{
unsigned char temp;
unsigned char i,nr,retry;
unsigned long int checksum;
unsigned int blocknr, IAPBlock;
if(!UPDATEFILE_Ready) return;
retry=0;
IAPUpdateStatus=Status_CmdStop;
while(!UPDATE_FINISH)
{
switch(IAPUpdateStatus)
{
case Status_CmdStop:
CDBasicCmdUpdate(IAP_CD_CMD_STOP);
IAPUpdateStatus = Status_MsgStop;
break;
case Status_MsgStop:
if(Msg_receive)
{
IAPWWatchDogRefresh();
Msg_receive = 0;
if((IAP.ReadBuff[1]==IAP_PLAYER_MSG_GROUP)
&&(IAP.ReadBuff[2]==IAP_MSG_PL
评论2