Moog Crossbow GNAV540 User Manual
Page 117

GNAV540 User Manual
7430‐0808‐01 Rev. B
Page 117
* 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 crc ^= peekByte(queue_ptr, startIndex+i) << 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; queue_ptr->rear = -1; } /******************************************************************************* * FUNCTION: AddQueue - add item in front of queue * ARGUMENTS: item holds item to be added to queue * queue_ptr is pointer to the queue * RETURNS: returns 0 if queue is full. 1 if successful *******************************************************************************/ int AddQueue(char item, QUEUE_TYPE *queue_ptr) { int retval = 0; if(queue_ptr->count >= MAXQUEUE) { retval = 0; /* queue is full */ } else { queue_ptr->count++; queue_ptr->rear = (queue_ptr->rear + 1) % MAXQUEUE; queue_ptr->entry(queue_ptr->rear) = item; retval = 1; } return retval; }