Hauptseite | Klassenhierarchie | Alphabetische Liste | Auflistung der Klassen | Auflistung der Dateien | Klassen-Elemente

# crcmodel.h

    00001 /******************************************************************************/
    00002 /*                             Start of crcmodel.h                            */
    00003 /******************************************************************************/
    00004 /*                                                                            */
    00005 /* Author : Ross Williams (ross@guest.adelaide.edu.au.).                      */
    00006 /* Date   : 3 June 1993.                                                      */
    00007 /* Status : Public domain.                                                    */
    00008 /*                                                                            */
    00009 /* Description : This is the header (.h) file for the reference               */
    00010 /* implementation of the Rocksoft^tm Model CRC Algorithm. For more            */
    00011 /* information on the Rocksoft^tm Model CRC Algorithm, see the document       */
    00012 /* titled "A Painless Guide to CRC Error Detection Algorithms" by Ross        */
    00013 /* Williams (ross@guest.adelaide.edu.au.). This document is likely to be in   */
    00014 /* "ftp.adelaide.edu.au/pub/rocksoft".                                        */
    00015 /*                                                                            */
    00016 /* Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia.    */
    00017 /*                                                                            */
    00018 /******************************************************************************/
    00019 /*                                                                            */
    00020 /* How to Use This Package                                                    */
    00021 /* -----------------------                                                    */
    00022 /* Step 1: Declare a variable of type cm_t. Declare another variable          */
    00023 /*         (p_cm say) of type p_cm_t and initialize it to point to the first  */
    00024 /*         variable (e.g. p_cm_t p_cm = &cm_t).                               */
    00025 /*                                                                            */
    00026 /* Step 2: Assign values to the parameter fields of the structure.            */
    00027 /*         If you don't know what to assign, see the document cited earlier.  */
    00028 /*         For example:                                                       */
    00029 /*            p_cm->cm_width = 16;                                            */
    00030 /*            p_cm->cm_poly  = 0x8005L;                                       */
    00031 /*            p_cm->cm_init  = 0L;                                            */
    00032 /*            p_cm->cm_refin = TRUE;                                          */
    00033 /*            p_cm->cm_refot = TRUE;                                          */
    00034 /*            p_cm->cm_xorot = 0L;                                            */
    00035 /*         Note: Poly is specified without its top bit (18005 becomes 8005).  */
    00036 /*         Note: Width is one bit less than the raw poly width.               */
    00037 /*                                                                            */
    00038 /* Step 3: Initialize the instance with a call cm_ini(p_cm);                  */
    00039 /*                                                                            */
    00040 /* Step 4: Process zero or more message bytes by placing zero or more         */
    00041 /*         successive calls to cm_nxt. Example: cm_nxt(p_cm,ch);              */
    00042 /*                                                                            */
    00043 /* Step 5: Extract the CRC value at any time by calling crc = cm_crc(p_cm);   */
    00044 /*         If the CRC is a 16-bit value, it will be in the bottom 16 bits.    */
    00045 /*                                                                            */
    00046 /******************************************************************************/
    00047 /*                                                                            */
    00048 /* Design Notes                                                               */
    00049 /* ------------                                                               */
    00050 /* PORTABILITY: This package has been coded very conservatively so that       */
    00051 /* it will run on as many machines as possible. For example, all external     */
    00052 /* identifiers have been restricted to 6 characters and all internal ones to  */
    00053 /* 8 characters. The prefix cm (for Crc Model) is used as an attempt to avoid */
    00054 /* namespace collisions. This package is endian independent.                  */
    00055 /*                                                                            */
    00056 /* EFFICIENCY: This package (and its interface) is not designed for           */
    00057 /* speed. The purpose of this package is to act as a well-defined reference   */
    00058 /* model for the specification of CRC algorithms. If you want speed, cook up  */
    00059 /* a specific table-driven implementation as described in the document cited  */
    00060 /* above. This package is designed for validation only; if you have found or  */
    00061 /* implemented a CRC algorithm and wish to describe it as a set of parameters */
    00062 /* to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation  */
    00063 /* should behave identically to this package under those parameters.          */
    00064 /*                                                                            */
    00065 /******************************************************************************/
    00066
    00067 /* The following #ifndef encloses this entire */
    00068 /* header file, rendering it indempotent.     */
    00069 #ifndef CM_DONE
    00070 #define CM_DONE
    00071
    00072 /******************************************************************************/
    00073
    00074 /* The following definitions are extracted from my style header file which    */
    00075 /* would be cumbersome to distribute with this package. The DONE_STYLE is the */
    00076 /* idempotence symbol used in my style header file.                           */
    00077
    00078 #ifndef DONE_STYLE
    00079
    00080 typedef unsigned long   ulong;
    00081 /*typedef unsigned        bool; */
    00082 typedef unsigned char * p_ubyte_;
    00083
    00084 #ifndef TRUE
    00085 #define FALSE 0
    00086 #define TRUE  1
    00087 #endif
    00088
    00089 /* Change to the second definition if you don't have prototypes. */
    00090 #define P_(A) A
    00091 /* #define P_(A) () */
    00092
    00093 /* Uncomment this definition if you don't have void. */
    00094 /* typedef int void; */
    00095
    00096 #endif
    00097
    00098 /******************************************************************************/
    00099
    00100 /* CRC Model Abstract Type */
    00101 /* ----------------------- */
    00102 /* The following type stores the context of an executing instance of the  */
    00103 /* model algorithm. Most of the fields are model parameters which must be */
    00104 /* set before the first initializing call to cm_ini.                      */
    00105
    00109 typedef struct
    00110   {
    00111    int   cm_width;   /* Parameter: Width in bits [8,32].       */
    00112    ulong cm_poly;    /* Parameter: The algorithm's polynomial. */
    00113    ulong cm_init;    /* Parameter: Initial register value.     */
    00114    bool  cm_refin;   /* Parameter: Reflect input bytes?        */
    00115    bool  cm_refot;   /* Parameter: Reflect output CRC?         */
    00116    ulong cm_xorot;   /* Parameter: XOR this to output CRC.     */
    00117
    00118    ulong cm_reg;     /* Context: Context during execution.     */
    00119   } cm_t;
    00120 typedef cm_t *p_cm_t;
    00121
    00122 /******************************************************************************/
    00123
    00124 /* Functions That Implement The Model */
    00125 /* ---------------------------------- */
    00126 /* The following functions animate the cm_t abstraction. */
    00127
    00128 void cm_ini P_((p_cm_t p_cm));
    00129 /* Initializes the argument CRC model instance.          */
    00130 /* All parameter fields must be set before calling this. */
    00131
    00132 void cm_nxt P_((p_cm_t p_cm,int ch));
    00133 /* Processes a single message byte [0,255]. */
    00134
    00135 void cm_blk P_((p_cm_t p_cm,p_ubyte_ blk_adr,ulong blk_len));
    00136 /* Processes a block of message bytes. */
    00137
    00138 ulong cm_crc P_((p_cm_t p_cm));
    00139 /* Returns the CRC value for the message bytes processed so far. */
    00140
    00141 /******************************************************************************/
    00142
    00143 /* Functions For Table Calculation */
    00144 /* ------------------------------- */
    00145 /* The following function can be used to calculate a CRC lookup table.        */
    00146 /* It can also be used at run-time to create or check static tables.          */
    00147
    00148 ulong cm_tab P_((p_cm_t p_cm,int index));
    00149 /* Returns the i'th entry for the lookup table for the specified algorithm.   */
    00150 /* The function examines the fields cm_width, cm_poly, cm_refin, and the      */
    00151 /* argument table index in the range [0,255] and returns the table entry in   */
    00152 /* the bottom cm_width bytes of the return value.                             */
    00153
    00154 /******************************************************************************/
    00155
    00156 /* End of the header file idempotence #ifndef */
    00157 #endif
    00158
    00159 /******************************************************************************/
    00160 /*                             End of crcmodel.h                              */
    00161 /******************************************************************************/