This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
crc16 accumulate patch
- From: Simon Kallweit <simon dot kallweit at intefo dot ch>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Fri, 21 Aug 2009 15:01:03 +0200
- Subject: crc16 accumulate patch
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
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;
}
-