Previous

Next

Bottom

Contents

Glossary

Index

 

Persistor CF1 User's Manual

Checksums and Cyclic Redundancy Checks

July 1998

Revision 1.01

 Persistor Instruments Inc.
© 1998 All rights reserved.

Quick Reference Table

CheckSum16

CRC16Block

CheckSum16Block

CRC32

CheckSum32

CRC32Block

CheckSum32Block

CRCInit

CRC16

 

About the CRC Functions

The CRC collection of BIOS functions implement error detection schemes with 16 and 32 bit checksum and cyclic redundancy checks. Both the checksum and CRC routines use an identical calling interface to let your application switch between the speed of simple checksums, or the slower but greatly improved error detection of CRCs. Because the 68338 has a 32 bit CPU, there is virtually no performance penalty associated with using the full 32 bit routines.

The 16 bit CRC routines use the same standard CCITT16 16 bit generating polynomial (x16 + x12 + x5 + 1) used by the XMODEM, YMODEM, and ZMODEM communications protocols. This 16 bit crc catches 99.998% of all errors and is appropriate for data blocks up to 4KB.

The 32 bit CRC routines use the same standard CCITT32 32 bit generating polynomial (x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1) used by ZMODEM and Ethernet ( IEEE 802) protocols. This 32 bit crc catches 99.999999977% of all errors and is appropriate for data blocks up to 64KB.

These routines are in the BIOS because both PicoDOS and the Persistor Boot Monitor make extensive use of CRCs to verify tables and applications in flash memory and to confirm the validity of the battery backed SRAM on waking from suspend mode. With the routines built into the BIOS, it's easy to make your own Persistor applications more robust with the additional guarantees of correctness provided with embedded CRCs.

CheckSum16 -- Update a running 16 bit checksum

This function computes and returns an updated unsigned short checksum derived from an unsigned byte value and an unsigned short running checksum. The running CRC is typically zero for the first call, and the latest returned value for subsequent calls. The algorithm uses simple addition primitives and has deterministic timing as shown below.

Use this routine to compute "on-the-fly" checksums for short data streams where speed and function pointer access are the paramount objectives. Otherwise, you are much better off maintaining your own checksum by adding new bytes into a totalizing unsigned short variable and allowing it to overflow. For much better error detection, use the CRC16() function. To compute checksums on fixed blocks of memory (like the flash), use the CheckSum 16Block() function.

Prototype:

ushort CheckSum16(uchar value, ushort runningSum);

Definition:

#include <cf1bios.h>

Inputs:

value is the next byte to checksum
runningSum is the running checksum from a previous call, usually initialized to zero for the first call

Returns:

the updated checksum, either the final value, or the next value to pass as the running sum

Timing:

5.0us 16MHz/0wts 7.5us 8MHz/-1wts

CheckSum16Block -- Compute a 16 bit checksum for a block of data

This function computes and returns an unsigned short checksum on a block of memory. Pass it a pointer to the start of the block, the number of bytes to compute, and a starting checksum value (typically zero). The algorithm uses simple addition primitives and has deterministic timing as shown below.

Use this routine to compute checksum s for small data blocks where speed and function pointer access are the paramount objectives. For much better error detection, use the CRC16Block() function. To compute checksums on data streams (like UART characters), use the CheckSum16 () or CheckSum32() functions.

Prototype:

ushort CheckSum16Block(const void *data, ulong len, ushort runningSum);

Definition:

#include <cf1bios.h>

Inputs:

data points to the start of the data block to CRC
len is the count in bytes to CRC
runningSum is the running checksum from a previous call, usually initialized to zero for the first call

Returns:

the computed checksum

Timing:

9us+1.9us/byte 16MHz/0wts 14us+2.9us/byte 8MHz/-1wts

CheckSum32 -- Update a running 32 bit checksum

This function computes and returns an updated unsigned long checksum derived from an unsigned byte value and an unsigned long running checksum. The running CRC is typically zero for the first call, and the latest returned value for subsequent calls. The algorithm uses simple addition primitives and has deterministic timing as shown below.

Use this routine to compute "on-the-fly" checksums for short data streams where speed and function pointer access are the paramount objectives. Otherwise, you are much better off maintaining your own checksum by adding new bytes into a totalizing unsigned long variable and allowing it to overflow. For much better error detection, use the CRC32() function. To compute checksums on fixed blocks of memory (like the flash), use the CheckSum 32Block() function.

Prototype:

ulong CheckSum32(uchar value, ulong runningSum);

Definition:

#include <cf1bios.h>

Inputs:

value is the next byte to checksum
runningSum is the running checksum from a previous call, usually initialized to zero for the first call

Returns:

the updated checksum, either the final value, or the next value to pass as the running sum

Timing:

5.5us 16MHz/0wts 8.2us 8MHz/-1wts

CheckSum32Block -- Compute a 32 bit checksum for a block of data

This function computes and returns an unsigned short checksum on a block of memory. Pass it a pointer to the start of the block, the number of bytes to compute, and a starting checksum value (typically zero). The algorithm uses simple addition primitives and has deterministic timing as shown below.

Use this routine to compute checksum s for small data blocks where speed and function pointer access are the paramount objectives. For much better error detection, use the CRC16Block() function. To compute checksums on data streams (like UART characters), use the CheckSum16 () or CheckSum32() functions.

Prototype:

ushort CheckSum16Block(const void *data, ulong len, ushort runningSum);

Definition:

#include <cf1bios.h>

Inputs:

data points to the start of the data block to CRC
len is the count in bytes to CRC
runningSum is the running checksum from a previous call, usually initialized to zero for the first call

Returns:

the computed checksum

Timing:

9us+1.9us/byte 16MHz/0wts 14us+2.9us/byte 8MHz/-1wts

 

CRC16 -- Update a running 16 bit CCITT CRC

This function computes and returns an updated unsigned short short cyclic redundancy check derived from an unsigned byte value and an unsigned short running CRC. The running CRC is typically zero for the first call, and the latest returned value for subsequent calls. The algorithm is table drive and has deterministic timing as shown below.

Use this routine to compute "on-the-fly" CRCs for data streams of 4kB or less. For faster operation, use the CheckSum16() function. For larger packets, or just better error checking, use the CRC32() function. To compute CRCs on fixed blocks of memory (like the flash), use the CRC16Block() function.

Prototype:

ushort CRC16(uchar value, ushort runningCRC);

Definition:

#include <cf1bios.h>

Inputs:

value is the next byte to CRC
runningCRC is the running CRC from a previous call, usually initialized to zero for the first call

Returns:

the updated CRC, either the final value, or the next value to pass as the running CRC

Timing:

9.2us 16MHz/0wts 14.2us 8MHz/-1wts

CRC16Block -- Compute a 16 bit CCITT CRC for a block of data

This function computes and returns an unsigned short cyclic redundancy check on a block of memory. Pass it a pointer to the start of the block, the number of bytes to compute, and a starting CRC value (typically zero). The algorithm is table drive and has deterministic timing as shown below.

Use this routine to compute CRCs for data blocks of 4kB or less. For faster operation, use the CheckSum16Block() function. For larger blocks, or just better error checking, use the CRC32Block() function. To compute CRCs on data streams (like UART characters), use the CRC16() function.

Prototype:

ushort CRC16Block(const void *data, ulong len, ushort runningCRC);

Definition:

#include <cf1bios.h>

Inputs:

data points to the start of the data block to CRC
len is the count in bytes to CRC
runningCRC is the running CRC from a previous call, usually initialized to zero for the first call

Returns:

the computed CRC

Timing:

10us+5.8us/byte 16MHz/0wts 15us+9.4us/byte 8MHz/-1wts

CRC32 -- Update a running 32 bit CCITT CRC

This function computes and returns an updated unsigned short long cyclic redundancy check derived from an unsigned byte value and an unsigned short running CRC. The running CRC is typically zero for the first call, and the latest returned value for subsequent calls. The algorithm is table drive and has deterministic timing as shown below.

Use this routine to compute "on-the-fly" CRCs for data streams of 64kB or less. For faster operation, use the CheckSum32() function. For packets smaller than 4KB, use the CRC32() function. To compute CRCs on fixed blocks of memory (like the flash), use the CRC32Block() function.

Prototype:

ulong CRC32(uchar value, ulong runningCRC);

Definition:

#include <cf1bios.h>

Inputs:

value is the next byte to CRC
runningCRC is the running CRC from a previous call, usually initialized to zero for the first call

Returns:

the updated CRC, either the final value, or the next value to pass as the running CRC

Timing:

9.4us 16MHz/0wts 14.4us 8MHz/-1wts

CRC32Block -- Compute a 32 bit CCITT CRC for a block of data

This function computes and returns an unsigned long cyclic redundancy check on a block of memory. Pass it a pointer to the start of the block, the number of bytes to compute, and a starting CRC value (typically zero). The algorithm is table drive and has deterministic timing as shown below.

Use this routine to compute CRCs for data blocks of 64kB or less. For faster operation, use the CheckSum32Block() function. For blocks smaller than 4KB, use the CRC16Block() function. To compute CRCs on data streams (like UART characters), use the CRC32() function.

Prototype:

ulong CRC32Block(const void *data, ulong len, ulong runningCRC);

Definition:

#include <cf1bios.h>

Inputs:

data points to the start of the data block to CRC
len is the count in bytes to CRC
runningCRC is the running CRC from a previous call, usually initialized to zero for the first call

Returns:

the computed CRC

Timing:

10us+5.8us/byte 16MHz/0wts 15us+9.4us/byte 8MHz/-1wts

CRCInit -- Initialize the CRC tables

The 16 and 32 bit CRC routines work from table lookup algorithms rather than performing full computations for each request. These tables are setup by this routine, which is automatically called as part of the drivers initialization performed during the BIOS initialization. You will never need to explicitly call this function, and its description is included here so that when you see this function listed in the function table, you won't wonder if this is something you need to do. Calling this function more than once has no effect.

Prototype:

void CRCInit(void);

Definition:

#include <cf1bios.h>

Notes:

called automatically at BIOS startup

Timing:

unspecified

 

Previous

Next

Top

Contents

Glossary

Index

Tel: 508-759-6434

Fax: 508-759-6436

Copyright (C) 1998 Persistor Instruments Inc. - All Rights Reserved