Syntax, Example, Crc16_ccitt( ) function – Echelon Neuron C User Manual

Page 97

Advertising
background image

Neuron C Reference Guide

77

1

2

15

16

+

+

+

x

x

x

This function is useful in conjunction with the support for the Touch I/O model,

but can also be used whenever a CRC is needed.

Syntax

#include <stdlib.h>
unsigned long crc16 (unsigned long

crc

, unsigned

new_data

);

Example

#include <stdlib.h>

unsigned data[SIZE];

void f(void)
{

unsigned i; // Or 'unsigned long' depending on SIZE

long

crc;

crc = 0;

for (i = 0; i < SIZE; ++i) {

// Combine partial CRC with next data value

crc = crc16(crc, data[i]);

}
}

crc16_ccitt( )

Function

The crc16_ccitt( ) function iteratively calculates a 16-bit Comité Consultatif
International Téléphonique et Télégraphique

1

(CCITT) cyclic redundancy check

(CRC) over an array of data bytes using the following polynomial:

1

5

12

16

+

+

+

x

x

x

Apart from using a different polynomial, this function differs from the crc16( )

function in that this function operates on a data array, which is generally faster.

This function is useful in conjunction with the support for the Touch I/O model,

but can also be used whenever a CRC is needed.

Syntax

#include <stdlib.h>
extern system far unsigned long crc16_ccitt (unsigned long

crc_in

,

const unsigned

*sp

, unsigned

len

);

crc-in

Specifies the input seed for the CRC calculation.

sp

Specifies a pointer to the buffer that contains the data to

be checked.

1

International Telegraph and Telephone Consultative Committee.

Advertising