This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

CRC16 accumulate function


This patch adds a cyg_crc16_accumulate function which allows to continue on previous crc calculations. Besides my need for this it also makes the group of crc function more consistent.

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]