/*********************************  crc8.h  *********************************
 * $Source: /home/cvs/ESP/gen2/software/msp430/include/crc8.h,v $
 *  Copyright (C) 2003 MBARI
 *
 *  MBARI Proprietary Information. All rights reserved.
 * $Id: crc8.h,v 1.6 2004/07/02 23:59:55 brent Exp $
 *
 * 8-bit CRC for I2C messages
 * 
 *****************************************************************************/

#ifndef CRC8_H
#define CRC8_H

#include "types.h"

#define CRC8seed (0xe5)

extern const byte CRC8nibbleTable[32], CRC8byteTable[256];

#define CRC8init(crc) (crc = CRC8seed)

//crc is the CRC8 accumulator
//data must be 0..0xff
#define CRC8next(crc, data) ((crc) = CRC8byteTable[(crc) ^ (data)])

//an alternate version that uses just CRC8nibbleTable
#define CRC8nibbleNext(crc, data) { \
  unsigned b = data ^ crc; \
  crc = CRC8nibbleTable[b&0xf] ^ (CRC8nibbleTable+16)[b>>4]; \
}


#endif
