Mercurial > ecos
changeset 2912:3fa8710867ea
* 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().
| author | jld |
|---|---|
| date | Wed, 26 Aug 2009 06:54:11 +0000 |
| parents | 7a3b9a2f019b |
| children | c7609c2784f3 |
| files | packages/services/crc/current/ChangeLog packages/services/crc/current/include/crc.h packages/services/crc/current/src/crc16.c packages/services/crc/current/tests/crc_test.c |
| diffstat | 4 files changed, 43 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/services/crc/current/ChangeLog +++ b/packages/services/crc/current/ChangeLog @@ -1,3 +1,9 @@ +2009-08-26 Simon Kallweit <simon.kallweit@intefo.ch> + + * 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 <andrew.lunn@ascom.ch> * tests/crc_test.c: casts to make it gcc 4.0.1 frendly. @@ -42,7 +48,7 @@ 2002-08-07 Andrew Lunn <andrew.lunn@as // ####GPLCOPYRIGHTBEGIN#### // ------------------------------------------- // 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. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by
--- a/packages/services/crc/current/include/crc.h +++ b/packages/services/crc/current/include/crc.h @@ -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 @@ -96,6 +96,9 @@ cyg_ether_crc32_accumulate(cyg_uint32 cr __externC cyg_uint16 cyg_crc16(unsigned char *s, int len); +__externC cyg_uint16 +cyg_crc16_accumulate(cyg_uint16 crc, unsigned char *s, int len); + #endif // _SERVICES_CRC_CRC_H_
--- a/packages/services/crc/current/src/crc16.c +++ b/packages/services/crc/current/src/crc16.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 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 @@ -92,13 +92,16 @@ static const cyg_uint16 crc16_tab[] = { cyg_uint16 cyg_crc16(unsigned char *buf, int len) { - int i; - cyg_uint16 cksum; - - cksum = 0; - for (i = 0; i < len; i++) { - cksum = crc16_tab[((cksum>>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; +}
--- 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"); + } } }
