11.3Schristos/* $NetBSD: sbc_crc.c,v 1.3 2017/01/30 15:56:44 christos Exp $ */
21.1Snat
31.1Snat/*-
41.1Snat * Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
51.1Snat * All rights reserved.
61.1Snat *
71.1Snat *		This software is dedicated to the memory of -
81.1Snat *	   Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
91.1Snat *
101.1Snat *		Barry was a man who loved his music.
111.1Snat *
121.1Snat * Redistribution and use in source and binary forms, with or without
131.1Snat * modification, are permitted provided that the following conditions
141.1Snat * are met:
151.1Snat * 1. Redistributions of source code must retain the above copyright
161.1Snat *    notice, this list of conditions and the following disclaimer.
171.1Snat * 2. Redistributions in binary form must reproduce the above copyright
181.1Snat *    notice, this list of conditions and the following disclaimer in the
191.1Snat *    documentation and/or other materials provided with the distribution.
201.1Snat *
211.1Snat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
221.1Snat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
231.1Snat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
241.1Snat * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
251.1Snat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
261.1Snat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
271.1Snat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
281.1Snat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
291.1Snat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
301.1Snat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
311.1Snat * POSSIBILITY OF SUCH DAMAGE.
321.1Snat */
331.1Snat
341.1Snat#include <stdio.h>
351.1Snat
361.1Snatint
371.3Schristosmain(void)
381.1Snat{
391.3Schristos	unsigned int j, i, k, numbits, data;
401.1Snat
411.1Snat	printf("/* sbc_crc.h - Automatically generated by sbc_crc.c. */\n\n");
421.1Snat
431.1Snat	/* The CRC-8 polynomial this uses is 0x11D */
441.1Snat
451.1Snat	numbits = 8;
461.1Snat	for (k = 0; k < 2; k++) {
471.3Schristos		printf("static const uint8_t sbc_crc%u[256] = {\n\t", numbits);
481.1Snat		for (i = 0; i < 256; i++) {
491.1Snat			data = i;
501.1Snat
511.1Snat			for (j = 0; j < numbits; j++) {
521.3Schristos				if (data & 0x80) {
531.3Schristos					data <<= 1;
541.3Schristos					data ^= 0x1d;
551.1Snat				} else
561.3Schristos					data <<= 1;
571.1Snat			}
581.1Snat
591.1Snat			if (i % 8 == 0 && i != 0)
601.3Schristos				printf("\n\t");
611.1Snat
621.3Schristos			printf("0x%02x, ", data & 0xff);
631.1Snat		}
641.1Snat		printf("\n};\n\n");
651.1Snat
661.3Schristos		numbits /= 2;
671.1Snat	}
681.1Snat	return 0;
691.1Snat}
70