Annotation of margi2/crc.c, revision 1.1.1.1

1.1       cvs         1: /* 
                      2:     crc.c
                      3: 
                      4:     Copyright (C) Christian Wolff for convergence integrated media.
                      5: 
                      6:     This program is free software; you can redistribute it and/or modify
                      7:     it under the terms of the GNU General Public License as published by
                      8:     the Free Software Foundation; either version 2 of the License, or
                      9:     (at your option) any later version.
                     10: 
                     11:     This program is distributed in the hope that it will be useful,
                     12:     but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13:     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14:     GNU General Public License for more details.
                     15: 
                     16:     You should have received a copy of the GNU General Public License
                     17:     along with this program; if not, write to the Free Software
                     18:     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     19: */
                     20: 
                     21: /*---------------------------------------------------------
                     22: 
                     23: Cyclic Redundancy Check 16 and 32 Bit
                     24: 
                     25: Christian Wolff, 19990122
                     26: 
                     27: ---------------------------------------------------------*/
                     28: 
                     29: #define __NO_VERSION__
                     30: 
                     31: #include "crc.h"
                     32: 
                     33: unsigned short crc_16_table[256];
                     34: unsigned long crc_32_table[256];
                     35: 
                     36: // generate the tables of CRC-16 and CRC-32 remainders for all possible bytes
                     37: void gen_crc_table()
                     38: {
                     39:        register int i, j;
                     40:        register unsigned short crc16;
                     41:        register unsigned long crc32;
                     42:        for (i = 0; i < 256; i++) {
                     43:                crc16 = (unsigned short) i << 8;
                     44:                crc32 = (unsigned long) i << 24;
                     45:                for (j = 0; j < 8; j++) {
                     46:                        if (crc16 & 0x8000)
                     47:                                crc16 = (crc16 << 1) ^ POLYNOMIAL_16;
                     48:                        else
                     49:                                crc16 = (crc16 << 1);
                     50:                        if (crc32 & 0x80000000L)
                     51:                                crc32 = (crc32 << 1) ^ POLYNOMIAL_32;
                     52:                        else
                     53:                                crc32 = (crc32 << 1);
                     54:                }
                     55:                crc_16_table[i] = crc16;
                     56:                crc_32_table[i] = crc32;
                     57:        }
                     58: }
                     59: 
                     60: // update the CRC on the data block one byte at a time
                     61: unsigned short update_crc_16_block(unsigned short crc,
                     62:                                   char *data_block_ptr,
                     63:                                   int data_block_size)
                     64: {
                     65:        register int i;
                     66:        for (i = 0; i < data_block_size; i++)
                     67:                crc = update_crc_16(crc, *data_block_ptr++);
                     68:        return crc;
                     69: }
                     70: 
                     71: unsigned long update_crc_32_block(unsigned long crc, char *data_block_ptr,
                     72:                                  int data_block_size)
                     73: {
                     74:        register int i;
                     75:        for (i = 0; i < data_block_size; i++)
                     76:                crc = update_crc_32(crc, *data_block_ptr++);
                     77:        return crc;
                     78: }

LinuxTV legacy CVS <linuxtv.org/cvs>