voicecrc.c 1.27 KB
/*---------------------------------------------------------------------
 	Copyright (C) 1998 Nintendo.
 	
 	File		voicecrc.c
 	Coded    by	Koji Mitsunari.	May  8, 1998.
 	Modified by	
 	Comments	CRC calcurater for Voice Recognition System
   
 	$Id: voicecrc.c,v 1.2 2003/03/25 20:42:04 blythe Exp $
   ---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"

#define CRC5GEN		21	/* CRC5 generator = x^5 + x^4 + x^2 + 1 (-x^5) */
#define ADDR_LEN	11	/* address length in bits */
#define CRC8GEN		133	/* CRC8 generator = x^8 + x^7 + x^2 + 1 (-x^8) */
#define DATA_LEN	32	/* data length in bytes */

#ifndef BBPLAYER
u8 __osVoiceContDataCrc(u8 *data, u32 length)
/* calculate CRC8 for the data buffer of length DATA_LEN bytes */
/* 	using table-driven algorithm */
/* bufp: pointer to data buffer */
/* return: 8-bit crc value */
{
  u32	temp=0;
  u32	i, j;

  for( i = length ; i != 0 ; i-- ) {
    for( j = 0x80 ; j != 0 ; j >>= 1) {
      temp <<= 1;
      if ((u32)(*data) & j) {
	if (temp & 0x100) {
	  temp ^= 0x84;
	} else{
	  temp++;
	}
      } else {
	if (temp & 0x100) temp ^= 0x85;
      }
    }
    data++;
  }
  do {
    temp <<= 1;
    if (temp & 0x100) temp ^= 0x85;
  } while ( ++i < 8 ) ;

  return( (u8)temp );
}

#endif