voicecrc.c
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*---------------------------------------------------------------------
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.1.1.1 2002/05/02 03:28:44 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 */
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 );
}