public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Kallweit <simon.kallweit@intefo.ch>
To: John Dallaway <john@dallaway.org.uk>
Cc: ecos-patches@ecos.sourceware.org
Subject: Re: crc16 accumulate patch
Date: Wed, 26 Aug 2009 06:34:00 -0000	[thread overview]
Message-ID: <4A94D77C.4040405@intefo.ch> (raw)
In-Reply-To: <4A944F33.3060100@dallaway.org.uk>

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

John Dallaway wrote:
> Hi Simon
> 
> Simon Kallweit wrote:
> 
>> I have already sent in this patch some months ago, but it has not been
>> accepted. So I try again. This patch will add a new method
>> crc16_accumulate() and brings the API for crc16 in line with the others
>> which already support accumulation. There is no change to the existing API.
> 
> Can you extend the CRC test to exercise cyg_crc16_accumulate() in a
> similar way to cyg_crc32_accumulate() please?

Done, also updated the ChangeLog.

Simon

[-- Attachment #2: crc16_accumulate.patch --]
[-- Type: text/x-patch, Size: 3188 bytes --]

diff --git a/packages/services/crc/current/ChangeLog b/packages/services/crc/current/ChangeLog
index 8a8342e..6dc0ba7 100644
--- a/packages/services/crc/current/ChangeLog
+++ b/packages/services/crc/current/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-26  Simon Kallweit  <simon.kallweit@intefo.ch>
+
+	* include/crc.h:
+	* src/crc16.c:
+	* tests/crc_test.c:
+	Added cyg_crc16_accumulate() to continue on previous crc calculation.
+
 2005-08-03  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* tests/crc_test.c: casts to make it gcc 4.0.1 frendly.
diff --git a/packages/services/crc/current/include/crc.h b/packages/services/crc/current/include/crc.h
index 6f20b49..d58d4d1 100644
--- a/packages/services/crc/current/include/crc.h
+++ b/packages/services/crc/current/include/crc.h
@@ -96,6 +96,9 @@ cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
 __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_
 
 
diff --git a/packages/services/crc/current/src/crc16.c b/packages/services/crc/current/src/crc16.c
index 7d6fa38..60f810f 100644
--- a/packages/services/crc/current/src/crc16.c
+++ b/packages/services/crc/current/src/crc16.c
@@ -92,13 +92,16 @@ static const cyg_uint16 crc16_tab[] = {
 cyg_uint16
 cyg_crc16(unsigned char *buf, int len)
 {
+    return cyg_crc16_accumulate(0, buf, len);
+}
+
+cyg_uint16
+cyg_crc16_accumulate(cyg_uint16 crc16val, 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);
+        crc16val = crc16_tab[((crc16val>>8) ^ *buf++) & 0xFF] ^ (crc16val << 8);
     }
-    return cksum;
+    return crc16val;
 }
-
diff --git a/packages/services/crc/current/tests/crc_test.c b/packages/services/crc/current/tests/crc_test.c
index a37fef7..c15fa97 100644
--- a/packages/services/crc/current/tests/crc_test.c
+++ b/packages/services/crc/current/tests/crc_test.c
@@ -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_FINISH("16bit CRC calculation");
+    CYG_TEST_PASS("16bit CRC calculation");
+  }
+  
+  if (0 != cyg_crc16_accumulate(0,0,0)) {
+    CYG_TEST_FAIL("16bit CRC accumulate setup");
+  } else {
+    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");
+    }
   }
 }

  reply	other threads:[~2009-08-26  6:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-21 13:00 Simon Kallweit
2009-08-25 20:53 ` John Dallaway
2009-08-26  6:34   ` Simon Kallweit [this message]
2009-08-26  6:56     ` John Dallaway

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A94D77C.4040405@intefo.ch \
    --to=simon.kallweit@intefo.ch \
    --cc=ecos-patches@ecos.sourceware.org \
    --cc=john@dallaway.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).