[Tinyos-2-commits] CVS: tinyos-2.x/tos/system crc.h,1.4,1.5

akoepke andreaskoepke at users.sourceforge.net
Mon May 7 08:44:01 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/tos/system
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv7759

Modified Files:
	crc.h 
Log Message:
faster crc implementation

Index: crc.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/system/crc.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** crc.h	12 Dec 2006 18:23:47 -0000	1.4
--- crc.h	7 May 2007 15:43:59 -0000	1.5
***************
*** 49,53 ****
--- 49,56 ----
   * @return New CRC value
   *
+  * To understand how the CRC works and how it relates to the polynomial, read through this
+  * loop based implementation.
   */
+ /*
  uint16_t crcByte(uint16_t crc, uint8_t b)
  {
***************
*** 65,68 ****
--- 68,89 ----
    return crc;
  }
+ */
+ /**
+  * The following implementation computes the same polynomial.  It should be
+  * (much) faster on any processor architecture, as it does not involve
+  * loops. Unfortunately, I can not yet give a reference to a derivation.
+  * 
+  * @author Andreas Koepke <koepke at tkn.tu-berlin.de> (porting to tinyos)
+  * @author Paul Curtis (pointed out this implementation on the MSP430 yahoo mailing list)
+  */
+ 
+ uint16_t crcByte(uint16_t crc, uint8_t b) {
+   crc = (uint8_t)(crc >> 8) | (crc << 8);
+   crc ^= b;
+   crc ^= (uint8_t)(crc & 0xff) >> 4;
+   crc ^= crc << 12;
+   crc ^= (crc & 0xff) << 5;
+   return crc;
+ }
  #endif
  



More information about the Tinyos-2-commits mailing list