Annotation of multiplexer/crc16.c, revision 1.1
1.1 ! oskar 1: /*
! 2: * cyclic redundancy check 16 bit
! 3: * Copyright (C) 1999 Christian Wolff, 2004 Oskar Schirmer
! 4: * for Convergence Integrated Media GmbH (http://www.convergence.de)
! 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 19: */
! 20:
! 21: #include <sys/types.h>
! 22: #include "crc16.h"
! 23:
! 24: u_int16_t crc_16_table[256];
! 25:
! 26: // generate the tables of CRC-16 remainders for all possible bytes
! 27: void gen_crc16_table() {
! 28: register int i,j;
! 29: register u_int16_t crc16;
! 30: for (i=0; i<256; i++) {
! 31: crc16=(u_int16_t)i << 8;
! 32: for (j=0; j<8; j++) {
! 33: crc16 = (crc16 << 1) ^ ((crc16 & (1<<15)) ? POLYNOMIAL_16_MSBF : 0);
! 34: }
! 35: crc_16_table[i]=crc16;
! 36: }
! 37: }
! 38:
! 39: // update the CRC on the data block one byte at a time
! 40: u_int16_t update_crc_16_block(u_int16_t crc, char *data_block_ptr, int data_block_size)
! 41: {
! 42: register int i;
! 43: for (i=data_block_size; i>0; i--)
! 44: crc=update_crc_16(crc, *data_block_ptr++);
! 45: return crc;
! 46: }
! 47:
! 48: void crc16_calc (char *data,
! 49: int size,
! 50: char *crc)
! 51: {
! 52: u_int16_t c;
! 53: c = CRC_INIT_16;
! 54: while (--size >= 0) {
! 55: c = update_crc_16 (c,*data++);
! 56: }
! 57: crc[1] = c; c >>= 8;
! 58: crc[0] = c;
! 59: }
! 60:
LinuxTV legacy CVS <linuxtv.org/cvs>