Mercurial > flash_v2
changeset 395:9f81d6e38c3d
Fixed 32-bit reliance.
| author | asl |
|---|---|
| date | Tue, 29 Oct 2002 08:18:17 +0000 |
| parents | 7ca632b46393 |
| children | 256f9ccc0c3c |
| files | packages/services/crc/current/ChangeLog packages/services/crc/current/doc/crc.sgml packages/services/crc/current/include/crc.h packages/services/crc/current/src/crc16.c packages/services/crc/current/src/crc32.c packages/services/crc/current/src/posix_crc.c packages/services/crc/current/tests/crc_test.c |
| diffstat | 7 files changed, 39 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/services/crc/current/ChangeLog +++ b/packages/services/crc/current/ChangeLog @@ -1,3 +1,7 @@ +2002-10-28 Andrew Lunn <andrew.lunn@ascom.ch> + + * */*: Fixed 32-bit reliance. + 2002-10-18 Jonathan Larmour <jifl@eCosCentric.com> * include/crc.h: Add extern definitions.
--- a/packages/services/crc/current/doc/crc.sgml +++ b/packages/services/crc/current/doc/crc.sgml @@ -24,7 +24,7 @@ This function implements a 32 bit CRC wh 1008.2 Standard. This is the same as the Linux cksum program. </para> <programlisting> -unsigned long cyg_posix_crc32(unsigned char * s, int len); +cyg_uint32 cyg_posix_crc32(unsigned char * s, int len); </programlisting> <para> The CRC calculation is run over the data pointed to by @@ -40,8 +40,8 @@ polynomial X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0. </para> <programlisting> -unsigned long cyg_crc32(unsigned char * s, int len); -unsigned long cyg_crc32_accumulate(unsigned long crc, unsigned char * s, int len); +cyg_uint32 cyg_crc32(unsigned char * s, int len); +cyg_uint32 cyg_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len); </programlisting> <para> The CRC calculation is run over the data pointed to by @@ -61,8 +61,8 @@ result from the previous CRC calculation These functions implement the 32 bit CRC used by the Ethernet FCS word. </para> <programlisting> -unsigned long cyg_ether_crc32(unsigned char * s, int len); -unsigned long cyg_ether_crc32_accumulate(unsigned long crc, unsigned char * s, int len); +cyg_uint32 cyg_ether_crc32(unsigned char * s, int len); +cyg_uint32 cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len); </programlisting> <para> The CRC calculation is run over the data pointed to by @@ -83,7 +83,7 @@ This function implements a 16 bit CRC. I x^16+x^12+x^5+1. </para> <programlisting> -unsigned short cyg_crc16(unsigned char * s, int len); +cyg_uint16 cyg_crc16(unsigned char * s, int len); </programlisting> <para> The CRC calculation is run over the data pointed to by
--- a/packages/services/crc/current/include/crc.h +++ b/packages/services/crc/current/include/crc.h @@ -55,6 +55,8 @@ #ifndef _SERVICES_CRC_CRC_H_ #define _SERVICES_CRC_CRC_H_ +#include <cyg/infra/cyg_type.h> + #ifndef __externC # ifdef __cplusplus # define __externC extern "C" @@ -65,34 +67,34 @@ // Compute a CRC, using the POSIX 1003 definition -__externC unsigned long +__externC cyg_uint32 cyg_posix_crc32(unsigned char *s, int len); // Gary S. Brown's 32 bit CRC -__externC unsigned long +__externC cyg_uint32 cyg_crc32(unsigned char *s, int len); // Gary S. Brown's 32 bit CRC, but accumulate the result from a // previous CRC calculation -__externC unsigned long -cyg_crc32_accumulate(unsigned long crc, unsigned char *s, int len); +__externC cyg_uint32 +cyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len); // Ethernet FCS Algorithm -__externC unsigned long +__externC cyg_uint32 cyg_ether_crc32(unsigned char *s, int len); // Ethernet FCS algorithm, but accumulate the result from a previous // CRC calculation. -__externC unsigned long -cyg_ether_crc32_accumulate(unsigned long crc, unsigned char *s, int len); +__externC cyg_uint32 +cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len); // 16 bit CRC with polynomial x^16+x^12+x^5+1 -__externC unsigned short +__externC cyg_uint16 cyg_crc16(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 @@ -56,7 +56,7 @@ #include <cyg/crc/crc.h> // Table of CRC constants - implements x^16+x^12+x^5+1 -static const unsigned short crc16_tab[] = { +static const cyg_uint16 crc16_tab[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, @@ -91,11 +91,11 @@ static const unsigned short crc16_tab[] 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, }; -unsigned short +cyg_uint16 cyg_crc16(unsigned char *buf, int len) { int i; - unsigned short cksum; + cyg_uint16 cksum; cksum = 0; for (i = 0; i < len; i++) {
--- a/packages/services/crc/current/src/crc32.c +++ b/packages/services/crc/current/src/crc32.c @@ -65,7 +65,7 @@ /* */ /* ====================================================================== */ -static const unsigned long crc32_tab[] = { +static const cyg_uint32 crc32_tab[] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, @@ -122,8 +122,8 @@ static const unsigned long crc32_tab[] = /* This is the standard Gary S. Brown's 32 bit CRC algorithm, but accumulate the CRC into the result of a previous CRC. */ -unsigned long -cyg_crc32_accumulate(unsigned long crc32val, unsigned char *s, int len) +cyg_uint32 +cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) { int i; @@ -134,7 +134,7 @@ cyg_crc32_accumulate(unsigned long crc32 } /* This is the standard Gary S. Brown's 32 bit CRC algorithm */ -unsigned long +cyg_uint32 cyg_crc32(unsigned char *s, int len) { return (cyg_crc32_accumulate(0,s,len)); @@ -143,8 +143,8 @@ cyg_crc32(unsigned char *s, int len) /* Return a 32-bit CRC of the contents of the buffer accumulating the result from a previous CRC calculation. This uses the Ethernet FCS algorithm.*/ -unsigned long -cyg_ether_crc32_accumulate(unsigned long crc32val, unsigned char *s, int len) +cyg_uint32 +cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) { int i; @@ -159,7 +159,7 @@ cyg_ether_crc32_accumulate(unsigned long /* Return a 32-bit CRC of the contents of the buffer, using the Ethernet FCS algorithm. */ -unsigned long +cyg_uint32 cyg_ether_crc32(unsigned char *s, int len) { return cyg_ether_crc32_accumulate(0,s,len);
--- a/packages/services/crc/current/src/posix_crc.c +++ b/packages/services/crc/current/src/posix_crc.c @@ -61,7 +61,7 @@ // opposite order. This computation matches the output of the // Linux 'cksum' program. -static const unsigned long posix_crc32_tab[] = { +static const cyg_uint32 posix_crc32_tab[] = { 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, @@ -96,11 +96,11 @@ static const unsigned long posix_crc32_t 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4 }; -unsigned long +cyg_uint32 cyg_posix_crc32(unsigned char *s, int len) { int i; - unsigned long crc32val; + cyg_uint32 crc32val; unsigned long length; crc32val = 0;
--- a/packages/services/crc/current/tests/crc_test.c +++ b/packages/services/crc/current/tests/crc_test.c @@ -79,13 +79,13 @@ cyg_start( void ) CYG_TEST_INFO("Calculating CRCs"); - if (1500790746l != cyg_posix_crc32(license_txt,sizeof(license_txt)-1)) { + if (1500790746UL != cyg_posix_crc32(license_txt,sizeof(license_txt)-1)) { CYG_TEST_FAIL("Wrong POSIX CRC32 calculation"); } else { CYG_TEST_PASS("POSIX CRC32 calculation"); } - if (1667500021 != cyg_ether_crc32(license_txt,sizeof(license_txt)-1)) { + if (1667500021UL != cyg_ether_crc32(license_txt,sizeof(license_txt)-1)) { CYG_TEST_FAIL("Wrong Ethernet crc32 calculation"); } else { CYG_TEST_PASS("Ethernet crc32 calculation"); @@ -97,14 +97,14 @@ cyg_start( void ) crc1= cyg_ether_crc32_accumulate(0, license_txt,sizeof(license_txt)-1); crc2 = cyg_ether_crc32_accumulate(crc1, license_txt,sizeof(license_txt)-1); - if ((1667500021 != crc1) || (3478736840u != crc2)) { + if ((1667500021UL != crc1) || (3478736840UL != crc2)) { CYG_TEST_FAIL("Wrong Etheret crc32 accumulate"); } else { CYG_TEST_PASS("Ethernet crc32_accumulate"); } } - if (1247800780 != cyg_crc32(license_txt,sizeof(license_txt)-1)) { + if (1247800780UL != cyg_crc32(license_txt,sizeof(license_txt)-1)) { CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 calculation"); } else { CYG_TEST_PASS("Gary S. Browns' crc32 calculation"); @@ -113,13 +113,13 @@ cyg_start( void ) crc1 = cyg_crc32_accumulate(0,license_txt,sizeof(license_txt)-1); crc2 = cyg_crc32_accumulate(crc1,license_txt,sizeof(license_txt)-1); - if ((1247800780 != crc1) || (926002294 != crc2)) { + if ((1247800780UL != crc1) || (926002294UL != crc2)) { CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 accumulate calculation"); } else { CYG_TEST_PASS("Gary S. Browns' crc32 accumulate calculation"); } - if (32256 != cyg_crc16(license_txt,sizeof(license_txt)-1)) { + if (32256UL != cyg_crc16(license_txt,sizeof(license_txt)-1)) { CYG_TEST_FAIL_FINISH("Wrong 16bit CRC calculation"); } else { CYG_TEST_PASS_FINISH("16bit CRC calculation");
