public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* crc16 accumulate patch
@ 2009-08-21 13:00 Simon Kallweit
  2009-08-25 20:53 ` John Dallaway
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Kallweit @ 2009-08-21 13:00 UTC (permalink / raw)
  To: ecos-patches

[-- 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;
 }
-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: crc16 accumulate patch
  2009-08-21 13:00 crc16 accumulate patch Simon Kallweit
@ 2009-08-25 20:53 ` John Dallaway
  2009-08-26  6:34   ` Simon Kallweit
  0 siblings, 1 reply; 4+ messages in thread
From: John Dallaway @ 2009-08-25 20:53 UTC (permalink / raw)
  To: Simon Kallweit; +Cc: ecos-patches

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?

Otherwise, this is fine for check-in.

Thank you

John Dallaway

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: crc16 accumulate patch
  2009-08-25 20:53 ` John Dallaway
@ 2009-08-26  6:34   ` Simon Kallweit
  2009-08-26  6:56     ` John Dallaway
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Kallweit @ 2009-08-26  6:34 UTC (permalink / raw)
  To: John Dallaway; +Cc: ecos-patches

[-- 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");
+    }
   }
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: crc16 accumulate patch
  2009-08-26  6:34   ` Simon Kallweit
@ 2009-08-26  6:56     ` John Dallaway
  0 siblings, 0 replies; 4+ messages in thread
From: John Dallaway @ 2009-08-26  6:56 UTC (permalink / raw)
  To: Simon Kallweit; +Cc: ecos-patches

Hi Simon

Simon Kallweit wrote:

> 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.

Checked-in.

Thank you for the contribution!

John Dallaway

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-08-26  6:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-21 13:00 crc16 accumulate patch Simon Kallweit
2009-08-25 20:53 ` John Dallaway
2009-08-26  6:34   ` Simon Kallweit
2009-08-26  6:56     ` John Dallaway

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).