2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * Author : Ross Williams (ross@guest.adelaide.edu.au.). 2N/A * Date : 3 June 1993. 2N/A * Status : Public domain. 2N/A * Description : This is the header (.h) file for the reference 2N/A * implementation of the Rocksoft^tm Model CRC Algorithm. For more 2N/A * information on the Rocksoft^tm Model CRC Algorithm, see the document 2N/A * titled "A Painless Guide to CRC Error Detection Algorithms" by Ross 2N/A * Williams (ross@guest.adelaide.edu.au.). This document is likely to be in 2N/A * Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. 2N/A * How to Use This Package 2N/A * ----------------------- 2N/A * Step 1: Declare a variable of type cm_t. Declare another variable 2N/A * (p_cm say) of type p_cm_t and initialize it to point to the first 2N/A * variable (e.g. p_cm_t p_cm = &cm_t). 2N/A * Step 2: Assign values to the parameter fields of the structure. 2N/A * If you don't know what to assign, see the document cited earlier. 2N/A * p_cm->cm_width = 16; 2N/A * p_cm->cm_poly = 0x8005L; 2N/A * p_cm->cm_init = 0L; 2N/A * p_cm->cm_refin = TRUE; 2N/A * p_cm->cm_refot = TRUE; 2N/A * p_cm->cm_xorot = 0L; 2N/A * Note: Poly is specified without its top bit (18005 becomes 8005). 2N/A * Note: Width is one bit less than the raw poly width. 2N/A * Step 3: Initialize the instance with a call cm_ini(p_cm); 2N/A * Step 4: Process zero or more message bytes by placing zero or more 2N/A * successive calls to cm_nxt. Example: cm_nxt(p_cm,ch); 2N/A * Step 5: Extract the CRC value at any time by calling crc = cm_crc(p_cm); 2N/A * If the CRC is a 16-bit value, it will be in the bottom 16 bits. 2N/A * PORTABILITY: This package has been coded very conservatively so that 2N/A * it will run on as many machines as possible. For example, all external 2N/A * identifiers have been restricted to 6 characters and all internal ones to 2N/A * 8 characters. The prefix cm (for Crc Model) is used as an attempt to avoid 2N/A * namespace collisions. This package is endian independent. 2N/A * EFFICIENCY: This package (and its interface) is not designed for 2N/A * speed. The purpose of this package is to act as a well-defined reference 2N/A * model for the specification of CRC algorithms. If you want speed, cook up 2N/A * a specific table-driven implementation as described in the document cited 2N/A * above. This package is designed for validation only; if you have found or 2N/A * implemented a CRC algorithm and wish to describe it as a set of parameters 2N/A * to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation 2N/A * should behave identically to this package under those parameters. 2N/A/* The following definitions are extracted from my style header file which */ 2N/A/* would be cumbersome to distribute with this package. The DONE_STYLE is the */ 2N/A/* idempotence symbol used in my style header file. */ 2N/Atypedef unsigned bool;
2N/A/* Change to the second definition if you don't have prototypes. */ 2N/A/* #define P_(A) () */ 2N/A/* Uncomment this definition if you don't have void. */ 2N/A/* typedef int void; */ 2N/A/* CRC Model Abstract Type */ 2N/A/* ----------------------- */ 2N/A/* The following type stores the context of an executing instance of the */ 2N/A/* model algorithm. Most of the fields are model parameters which must be */ 2N/A/* set before the first initializing call to cm_ini. */ 2N/A/* Functions That Implement The Model */ 2N/A/* ---------------------------------- */ 2N/A/* The following functions animate the cm_t abstraction. */ 2N/A/* Initializes the argument CRC model instance. */ 2N/A/* All parameter fields must be set before calling this. */ 2N/A/* Processes a single message byte [0,255]. */ 2N/A/* Processes a block of message bytes. */ 2N/A/* Returns the CRC value for the message bytes processed so far. */ 2N/A/* Functions For Table Calculation */ 2N/A/* ------------------------------- */ 2N/A/* The following function can be used to calculate a CRC lookup table. */ 2N/A/* It can also be used at run-time to create or check static tables. */ 2N/A/* Returns the i'th entry for the lookup table for the specified algorithm. */ 2N/A/* The function examines the fields cm_width, cm_poly, cm_refin, and the */ 2N/A/* argument table index in the range [0,255] and returns the table entry in */ 2N/A/* the bottom cm_width bytes of the return value. */ 2N/A#
endif /* _CRCMODEL_H */