📄 ddc2bi.c
字号:
}
else
{
DDC2Bi_InitRx ();
}
break;
//
case DDC2B_SRCADDRESS:
// get the length
rxLength = rxByte & ~DDC2Bi_CONTROL_STATUS_FLAG;
// put the received byte in DDCBuffer
DDCBuffer[rxIndex++] = rxByte;
rxChkSum ^= rxByte;
// set the receive body state
rxStatus++;// = DDC2B_COMMAND;
//if it is a NULL message
if (rxLength == 0 || rxLength >= MaxBufLen)
{
rxStatus=DDC2B_COMPLETED;
Set_RxBusyFlag();
}
break;
// get the command
case DDC2B_COMMAND:
// save the commandbyte
rxStatus++;// = DDC2B_RECBODY;
// get the message body
case DDC2B_RECBODY:
DDCBuffer[rxIndex++] = rxByte;
rxChkSum ^= rxByte;
rxLength--;
// the last byte in the message body
if (rxLength == 0)
{
rxStatus++;// = DDC2B_WAITFORCK;
}
break;
// ...here we are waiting for checksum...
case DDC2B_WAITFORCK:
// if checksum match
if (rxChkSum == rxByte)
{
if(intype==0)
RxInputPort = 0;
else
RxInputPort = 1;
rxStatus = DDC2B_COMPLETED;
Set_RxBusyFlag();
}
// elsechecksum error
else
{
// if checksum error re-initialize the receive buffer
DDC2Bi_InitRx ();
}
break;
default:
// clear the rxState and the current buffer for a new message
if (!RxBusyFlag)
DDC2Bi_InitRx ();
break;
}
intFlag &= (~RCBI); //clear interrupt flag
break;
}
}
}
void EXT1Interrupt(void) interrupt 2
{
EX1=0;
}
#endif // Albert
#endif
/*
#else
void DDC2Bi_InitRx (void)
{
// clear the rxState
rxStatus = DDC2B_CLEAR;
// the current buffer for a new message
rxIndex = 0;
}
void DDC2Bi_Init (void)
{
// initialize various flags and data items
DDC2Bi_InitRx ();
txStatus = DDC2B_CLEAR; // initialize transmit status
// enable the DDC2Bi(SlaveB) port
SLVBADDR = 0xB7; //Bit7: enable slaveB IIC(0x6e) 0x80|(0x6e<<1)
PADMOD2 = 0x80; //Set P3.4 P3.5 as Hsda/Hclk
// set the EX1 priority to HIGH
PX1 = 1;
// enable IRQ1 interrupt level
EX1 = 1;
// initialize the transmit communication, so that either a valid
// or a NULL message is sent on a request from host
txBufferPtr = &nullMsg1[0];
txLength = sizeof (nullMsg1);
RCBTXBBUF = *txBufferPtr++;
}
void DDC2Bi_GetTxBuffer (void)
{ BYTE i; // loop variable
for ( i=MAX_TXWAIT_DELAY; i>0; i--)
if (txStatus == DDC2B_MSGON)
{
Delay1ms(1);
}
txStatus = DDC2B_CLEAR;
}
BYTE DDC2Bi_ComputeChecksum(BYTE count)
{
BYTE checksum = INITTxCK;
BYTE i = 0;
for ( ; count>0; count--)
checksum ^= DDCBuffer[i++];
return checksum;
}
void DDC2Bi_MessageReady (void)
{
//DDCBuffer[0] |= DDC2Bi_CONTROL_STATUS_FLAG;
// compute the check sum and assign to tx buffer
DDCBuffer[(DDCBuffer[0] & ~DDC2Bi_CONTROL_STATUS_FLAG) + 1] =
DDC2Bi_ComputeChecksum ((DDCBuffer[0] & ~DDC2Bi_CONTROL_STATUS_FLAG) + 1);
//DDCBuffer[9] = DDC2Bi_ComputeChecksum(9);
// wait until old packet sent out
//DDCBuffer[10] = 0x6e;
DDC2Bi_GetTxBuffer ();
//DDCBuffer[9] = 0x50;
//
EA = 0;
txBufferPtr = &DDCBuffer[0];
txLength = (DDCBuffer[0] & (~DDC2Bi_CONTROL_STATUS_FLAG)) + 2;
// re enable interrupts
EA = 1;
}
void DDC2Bi_ParseCommand (void)
{
BYTE length;//, command;
length = DDCBuffer[LENGTH] & 0x7F;
if(rxIndex <= 0) return;
if(length <= 0)
{
EA = 0;
txBufferPtr = &nullMsg1[1];
txLength = sizeof (nullMsg1);
// re enable interrupts
EA = 1;
RCBTXBBUF = DDC2B_DEST_ADDRESS;
return;
}
//----------------------
#if 0
if(mStar_ReadOSDByte(IOSDC1)&0x01)
{ //Draw_RootMenu();
MenuPageIndex=RootMenu;
MenuItemIndex=0;
ExecuteKeyEvent(MIA_RedrawMenu);
}
#endif
//Osd_Hide();
#if 1
length = AlignControl();
#endif
if(length <= 0)
{
DDCBuffer[0] = 0x80;
}
else if(length == 0xFE || length == 0xFD)
{
DDCBuffer[0] = 0x80;
//return;
}
DDC2Bi_MessageReady();
RCBTXBBUF = DDC2B_DEST_ADDRESS;
}
void DDC2Bi_CommandHandler (void)
{
BYTE index;
if (rxStatus == DDC2B_COMPLETED)
{
INTEN=0x00;
index=0;
#if 0//def Debug DDC
Osd_SetTextColor(1, rxIndex);
Osd_DrawHex(0, 0, CmIndex++);
for (index=0; index<rxIndex; index++)
Osd_DrawHex(3, index+0, DDCBuffer[index]);
#endif
DDC2Bi_ParseCommand ();
Clr_RxBusyFlag();
DDC2Bi_InitRx ();
INTEN=0xC6; //0xc0;
}
}
void EXT1Interrupt(void) interrupt 2
{ BYTE intFlag, rxByte;
EX1=0;
intFlag=INTFLG;
if ( intFlag)
{
switch (intFlag & (WslvA1 | WslvA2))
{
case WslvA1:
RewriteDDC_A1=1;
INTFLG &= (~WslvA1); //clear interrupt flag
break;
case WslvA2:
RewriteDDC_A2=1;
INTFLG &= (~WslvA2); //clear interrupt flag
break;
}
switch (intFlag & (TXBI | RCBI ))
{
case TXBI:
txStatus = DDC2B_MSGON;
// no characters left
if (!(txLength))
{
// clear the transmit status
txStatus = DDC2B_CLEAR;
RCBTXBBUF = 0;
EX1=1;
return ;
}
// send out the current byte
RCBTXBBUF = *txBufferPtr++;
txLength--;
INTFLG &= (~TXBI); //clear interrupt flag
break;
case RCBI:
// read the received byte
rxByte = RCBTXBBUF;
// depending of the message status
switch (rxStatus)
{
// in case there is nothing received yet
case DDC2B_CLEAR:
if (rxByte == DDC2B_SRC_ADDRESS)
{
rxStatus++;// = DDC2B_SRCADDRESS;
rxChkSum = INITRxCK;
}
else
{
DDC2Bi_InitRx ();
}
break;
case DDC2B_SRCADDRESS:
// Power_TurnOffGreenLed(); // turn off green led // jeff add it 11 24
// Power_TurnOnAmberLed();
// get the length
rxLength = rxByte & ~DDC2Bi_CONTROL_STATUS_FLAG;
// put the received byte in DDCBuffer
DDCBuffer[rxIndex++] = rxByte;
rxChkSum ^= rxByte;
// set the receive body state
rxStatus++;// = DDC2B_COMMAND;
//if it is a NULL message
if (rxLength == 0 || rxLength >= MaxBufLen)
{
// wait for CK
//rxStatus++;// = DDC2B_RECBODY;
//rxStatus++;// = DDC2B_WAITFORCK;
rxStatus=DDC2B_COMPLETED;
Set_RxBusyFlag();
}
break;
// get the command
case DDC2B_COMMAND:
// save the commandbyte
rxStatus++;// = DDC2B_RECBODY;
// get the message body
case DDC2B_RECBODY:
DDCBuffer[rxIndex++] = rxByte;
rxChkSum ^= rxByte;
rxLength--;
// the last byte in the message body
if (rxLength == 0)
{
#if 1
rxStatus++;// = DDC2B_WAITFORCK;
#else
rxStatus=DDC2B_COMPLETED;
Set_RxBusyFlag();
#endif
}
break;
// ...here we are waiting for checksum...
#if 1
case DDC2B_WAITFORCK:
// if checksum match
if (rxChkSum == rxByte)
{
rxStatus = DDC2B_COMPLETED;
Set_RxBusyFlag();
}
// elsechecksum error
else
{
// if checksum error re-initialize the receive buffer
DDC2Bi_InitRx ();
}
break;
#endif
// error condition
default:
// clear the rxState and the current buffer for a new message
if (!RxBusyFlag)
DDC2Bi_InitRx ();
break;
}
INTFLG &= (~RCBI); //clear interrupt flag
break;
}
}
EX1=1;
// EA=1;
}
#endif
BYTE AlignControl(void)
{
return 0;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -