C-Code Generation Of Crc Example - JDS Uniphase SKB Series User Manual

Fiberoptic switch module
Hide thumbs Also See for SKB Series:
Table of Contents

Advertisement

C-Code Generation of CRC Example

/***************************************************************************\
*
*
*
*
*****************************************************************************
*
FILE NAME:
*
* DESCRIPTION: Win32 console app
*
*
NOTES:
*
*
HISTORY: Date
*
----
*
May 2001
\***************************************************************************/
#include <process.h>
#include <stdio.h>
#include <conio.h>
/****************************************************************************
*
FUNCTION
: calc_crc16
* DESCRIPTION
: Calculate CRC-16 value for RS-485 PACKET AND CRC EXAMPLE
*
application note link-layer packet example.
*
INPUTS
: unsigned char *ptr - pointer to link layer packet.
*
int count - number of bytes in packet
*
RETURNS
: int - CRC value. On WIN32 int is 32-bits - CRC appears in *
*
the low-order 16 bits.
*
SCOPE
: Global
****************************************************************************
*
NOTES
:
***************************************************************************/
int calc_crc16(unsigned char *ptr, int count)
{
int crc, i;
/* Initialize crc to 0 for XMODEM, -1 for CCITT. */
crc = 0;
/* cycle through all bytes and add to CRC */
while (--count >= 0)
{
/* XOR the running CRC value with next byte bit-shifted */
crc = crc ^ (int)*ptr++ << 8;
/* shift the CRC bits up or wrap with poly if 1 high bit set */
for (i = 0; i < 8; ++i)
{
if (crc & 0x8000)
(c) JDS Uniphase Corporation 2001
Nepean, Ontario, Canada
Name
Revision
----
--------
DP
Created for SKB testing.
Application Notes
85
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

Advertisement

Table of Contents
loading

Table of Contents