DMU380SA Series
User’s Manual
________________________________________________________________________
Doc# 7430-0026 Rev.01
Page 85
result->crc
= packetCRC;
for(counter=0; counter < result->length; +)
{
result->data[counter] = peekByte(queue_ptr, 5+counter);
}
Pop(queue_ptr, dat7);
return 1;
}
/*******************************************************************************
* FUNCTION: calcCRC calculates a 2-byte CRC on serial data using
* CRC-CCITT 16-bit standard maintained by the ITU
*
(International Telecommunications Union).
* ARGUMENTS: queue_ptr is pointer to queue holding area to be CRCed
*
startIndex is offset into buffer where to begin CRC
calculation
*
num is offset into buffer where to stop CRC calculation
* RETURNS:
2-byte CRC
*******************************************************************************/
unsigned short calcCRC(QUEUE_TYPE *queue_ptr, unsigned int startIndex, unsigned
int num) {
unsigned int i=0, j=0;
unsigned short crc=0x1D0F; //non-augmented inital value equivalent to
augmented initial value 0xFFFF
for (i=0; i<num; i+=1) {
crc ^= peekByte(queue_ptr, stai) << 8;
for(j=0;j<8;j+=1) {
if(crc & 0x8000) crc = (crc << 1) ^ 0x1021;
else crc = crc << 1;
}
}
return crc;
}
/*******************************************************************************
* FUNCTION: Initialize - initialize the queue
* ARGUMENTS: queue_ptr is pointer to the queue
*******************************************************************************/
void Initialize(QUEUE_TYPE *queue_ptr)
{
queue_ptr->count = 0;
queue_ptr->front = 0;