csi_crc.h File Reference

CRC calculation for Common Serial Interface (CSI) protocol. More...

#include "csi_const.h"
#include "csi_plfabstr.h"
+ Include dependency graph for csi_crc.h:
+ This graph shows which files directly or indirectly include this file:

Functions

CSI_API uint16_t CsiCrcCalc (const uint16_t *pDataArray, uint16_t NumberOfWords)
 Calculate CRC-field for CSI protocol. More...
 
CSI_API uint16_t CsiCrcCalcIncremental (const uint16_t *pWordArray, uint16_t NumberOfWords, uint16_t CRC)
 Calculate CRC-field for CSI protocol. More...
 

Detailed Description

CRC calculation for Common Serial Interface (CSI) protocol.

Author
Uwe Kindler (UK)
Date
2009/08/27

Function Documentation

CSI_API uint16_t CsiCrcCalc ( const uint16_t *  pDataArray,
uint16_t  NumberOfWords 
)

Calculate CRC-field for CSI protocol.

Parameters
[in]pDataArrayPoints to array of data words to calculate checksum
[in]NumberOfWordsThe number of words in pDataArray
Returns
CRC checksum for CRC field
57 {
58  return CsiCrcCalcIncremental(pWordArray, NumberOfWords, 0);
59 }
uint16_t CsiCrcCalcIncremental(const uint16_t *pWordArray, uint16_t NumberOfWords, uint16_t CRC)
Calculate CRC-field for CSI protocol.
Definition: csi_crc.c:18

+ Here is the call graph for this function:

CSI_API uint16_t CsiCrcCalcIncremental ( const uint16_t *  pWordArray,
uint16_t  NumberOfWords,
uint16_t  CRC 
)

Calculate CRC-field for CSI protocol.

Parameters
[in]pWordArrayPoints to array of data words to calculate checksum
[in]NumberOfWordsThe number of words in pDataArray
[in]CRCThe current CRC sum
Returns
CRC checksum for CRC field

Referenced by CsiBusWriteLargeData(), and CsiCrcCalc().

20 {
21  uint16_t shifter;
22  uint16_t DataWord;
23  uint16_t carry;
24 
25  //
26  // Calculate pDataArray Word by Word
27  //
28  while(NumberOfWords--)
29  {
30  shifter = 0x8000;
31  DataWord = *pWordArray++;
32  do
33  {
34  carry = CRC & 0x8000;
35  CRC <<= 1;
36  if(DataWord & shifter)
37  {
38  CRC++;
39  }
40 
41  if(carry)
42  {
43  CRC ^= 0x1021;
44  }
45  shifter >>= 1;
46  }
47  while(shifter);
48  } // while(wNumberOfWords--)
49  return CRC;
50 }