# HG changeset patch # User jld # Date 1251269651 0 # Node ID 3fa8710867ea0c1e93bc7fb491fddb20489d758d # Parent 7a3b9a2f019b1de8d503f873ccfde678b3537595 * include/crc.h, src/crc16.c: Add cyg_crc16_accumulate() to continue a previous crc calculation. * tests/crc_test.c: Extend to test cyg_crc16_accumulate(). diff --git a/packages/services/crc/current/ChangeLog b/packages/services/crc/current/ChangeLog --- a/packages/services/crc/current/ChangeLog +++ b/packages/services/crc/current/ChangeLog @@ -1,3 +1,9 @@ +2009-08-26 Simon Kallweit + + * include/crc.h, src/crc16.c: Add cyg_crc16_accumulate() to continue + a previous crc calculation. + * tests/crc_test.c: Extend to test cyg_crc16_accumulate(). + 2005-08-03 Andrew Lunn * tests/crc_test.c: casts to make it gcc 4.0.1 frendly. @@ -42,7 +48,7 @@ 2002-08-07 Andrew Lunn >8) ^ *buf++) & 0xFF] ^ (cksum << 8); - } - return cksum; + return cyg_crc16_accumulate(0, buf, len); } +cyg_uint16 +cyg_crc16_accumulate(cyg_uint16 crc16val, unsigned char *buf, int len) +{ + int i; + + for (i = 0; i < len; i++) { + crc16val = crc16_tab[((crc16val>>8) ^ *buf++) & 0xFF] ^ (crc16val << 8); + } + return crc16val; +} diff --git a/packages/services/crc/current/tests/crc_test.c b/packages/services/crc/current/tests/crc_test.c --- a/packages/services/crc/current/tests/crc_test.c +++ b/packages/services/crc/current/tests/crc_test.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 2002 Free Software Foundation, Inc. +// Copyright (C) 2002, 2009 Free Software Foundation, Inc. // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -125,10 +125,25 @@ cyg_start( void ) CYG_TEST_PASS("Gary S. Browns' crc32 accumulate calculation"); } - if (32256UL != cyg_crc16((unsigned char *)license_txt, - sizeof(license_txt)-1)) { - CYG_TEST_FAIL_FINISH("Wrong 16bit CRC calculation"); + if (32256 != cyg_crc16((unsigned char *)license_txt, + sizeof(license_txt)-1)) { + CYG_TEST_FAIL("Wrong 16bit CRC calculation"); + } else { + CYG_TEST_PASS("16bit CRC calculation"); + } + + if (0 != cyg_crc16_accumulate(0,0,0)) { + CYG_TEST_FAIL("16bit CRC accumulate setup"); } else { - CYG_TEST_PASS_FINISH("16bit CRC calculation"); + crc1= cyg_crc16_accumulate(0, (unsigned char *)license_txt, + sizeof(license_txt)-1); + crc2 = cyg_crc16_accumulate(crc1, (unsigned char *)license_txt, + sizeof(license_txt)-1); + + if ((32256 != crc1) || (48052 != crc2)) { + CYG_TEST_FAIL_FINISH("Wrong 16bit CRC accumulate"); + } else { + CYG_TEST_PASS_FINISH("16bit CRC accumulate"); + } } }