summaryrefslogtreecommitdiff
path: root/board/ti/logic/prod-id/crc-15.c
blob: 344fdaad9ea5682d050998082f89e4d207933b8c (plain)
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
#include "crc-15.h"

/*
 * Calculate a CRC-15 of a data buffer passed in
 */

void crc_15_step(unsigned short *crc, unsigned char byte)
{
	int i;
	unsigned short crcnext;

	for (i=0; i<7; ++i) {
		crcnext = (byte & 1) ^ (*crc>>14);
		*crc = (*crc << 1) & 0x7fff;
		if (crcnext)
			*crc ^= 0x4599;
		byte >>= 1;
	}
}

unsigned short crc_15(void *buf, int len)
{
	unsigned char *p = buf;
	unsigned short xsum = 0;
	int i;

	for (i=0; i<len; ++i) {
		crc_15_step(&xsum, p[i]);
	}
	return xsum;
}