public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Kallweit <simon.kallweit@intefo.ch>
To: ecos-patches@ecos.sourceware.org
Subject: crc16 accumulate patch
Date: Fri, 21 Aug 2009 13:00:00 -0000	[thread overview]
Message-ID: <4A8E9A8F.3040602@intefo.ch> (raw)

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

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.

Simon

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

diff --git a/packages/services/crc/current/ChangeLog b/packages/services/crc/current/ChangeLog
index 8a8342e..d3d07b4 100644
--- a/packages/services/crc/current/ChangeLog
+++ b/packages/services/crc/current/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-20  Simon Kallweit  <simon.kallweit@intefo.ch>
+
+    * include/crc.h:
+    * src/crc16.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;
 }
-

             reply	other threads:[~2009-08-21 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-21 13:00 Simon Kallweit [this message]
2009-08-25 20:53 ` John Dallaway
2009-08-26  6:34   ` Simon Kallweit
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=4A8E9A8F.3040602@intefo.ch \
    --to=simon.kallweit@intefo.ch \
    --cc=ecos-patches@ecos.sourceware.org \
    /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).