📄 ddcci.c
字号:
void _ddcMessage( char *msg )
{
if( NULL != dbCallback )
(*dbCallback)( msg );
}
/****************************************************************************/
/* Receiver state machine. */
/* */
/* State machine is in RSM_IDLE state between messages. When 'start' indi- */
/* cation is received, the machine progresses through its states until a */
/* valid message is found or a protocol error occurs. */
/****************************************************************************/
BOOL _ddcReadCallback( uint08* byte, BOOL start )
{
/************************************************/
/* Start state machine on "start" indication. */
/************************************************/
if( start )
{
rsmState = RSM_START;
_ddcMessage( "r-Start" );
}
_ddcMessage( (char*)rbyte[*byte] );
switch( rsmState )
{
/************************************************/
/* If state machine is IDLE, wait for "start" */
/* indication. */
/************************************************/
case RSM_IDLE: /* receiver waiting for "start" */
break;
/************************************************/
/* If state machine is START, initialize for. */
/* message reception. */
/************************************************/
case RSM_START: /* receiver state machine started */
rsmAddr = (uint08*)&ciRxMsg; /* message buffer pointer */
rsmCount = 2; /* next-state byte count */
rsmState = RSM_LENGTH; /* state machine state */
*rsmAddr++ = CI_ADDRESS; /* insert destination address */
*rsmAddr++ = *byte; /* copy source address */
rsmCkSum = CI_ADDRESS ^ *byte; /* initialize checksum */
break;
/************************************************/
/* If state machine is LENGTH, read the message */
/* byte count. */
/************************************************/
case RSM_LENGTH: /* receiver obtaining message length */
*rsmAddr++ = *byte; /* copy message length */
rsmCkSum ^= *byte; /* update checksum */
rsmCount = 0x7f & *byte; /* next-state byte count */
rsmState = RSM_TEXT; /* state machine state */
if(( 0 == rsmCount ) || ( rsmCount > 33 ))
{
_ddcMessage( "Invalid message length" );
rsmState = RSM_IDLE; /* invalid count, restart */
}
break;
/************************************************/
/* If state machine is TEXT, read the function */
/* code and message text. */
/************************************************/
case RSM_TEXT: /*receiver obtaining message text */
*rsmAddr++ = *byte; /* copy message byte */
rsmCkSum ^= *byte; /* update checksum */
if( 0 == --rsmCount ) /* if all text received */
rsmState = RSM_CKSUM;
break;
/************************************************/
/* If state machine is CKSUM, indicate message */
/* complete if checksum is valid. */
/************************************************/
case RSM_CKSUM: /* receiver obtaining checksum */
*rsmAddr = *byte; /* copy checksum byte */
rsmState = RSM_IDLE; /* restart */
if( 0 == ( rsmCkSum ^ *byte )) /* validate checksum */
{
ciResponse = FALSE; /* prior response invalid */
RTA_EventSet( ciEvent );
_ddcMessage( "r-Comp" );
}
break;
}
return TRUE; /* not buffer-full */
}
/****************************************************************************/
/* Transmitter state machine. */
/* */
/* State machine is in TSM_IDLE state between messages. When a 'start' in- */
/* dication is received, the machine determines if it has a valid message */
/* to send. If so, it transmission of the messge is initiated. If not, a */
/* no-op message is sent. */
/* */
/* Any write callbacks received when the state machine is not sending a */
/* message causes a \0 byte to be sent. */
/****************************************************************************/
void _ddcWriteCallback( uint08* byte, BOOL start )
{
/************************************************/
/* Start state machine on "start" indication. */
/************************************************/
if( start )
{
tsmState = TSM_START;
_ddcMessage( "t-Start" );
}
switch( tsmState )
{
/************************************************/
/* If state machine is IDLE, send \0 to avoid */
/* I2C protocol error. */
/************************************************/
case TSM_IDLE: /* transmitter waiting for "start" */
*byte = 0;
break;
/************************************************/
/* If state machine is START, initialize for. */
/* message transmission. */
/************************************************/
case TSM_START: /* transmitter state machine started */
if( ciResponse ) /* if CI response is available */
{
_ddcMessage( "t-Resp" );
tsmAddr = (uint08 *)&ciTxMsg + 1;
tsmCount = (0x7f & ciTxMsg.length ) + 2;
tsmState = TSM_TEXT;
}
else
{
_ddcMessage( "t-Null" );
tsmAddr = ciNullMsg + 1;
tsmCount = (0x7f & ciNullMsg[2] ) + 2;
tsmState = TSM_TEXT;
}
*byte = *tsmAddr++;
break;
/************************************************/
/* If state machine is TEXT, send next byte. */
/************************************************/
case TSM_TEXT: /* transmitter sending bytes */
*byte = *tsmAddr++; /* next byte */
if( 0 == --tsmCount ) /* if last byte sent */
{
ciResponse = FALSE; /* response taken */
_ddcMessage( "t-End" );
tsmState = TSM_IDLE;
}
break;
}
_ddcMessage( (char*)tbyte[*byte] );
}
/****************************************************************************/
/* End of ITCM code. */
/****************************************************************************/
#pragma arm section code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -