NetBSD/usr.sbin/bta2dpd/sbc_crc-gen/sbc_crc.c

70 lines
2.2 KiB
C

/* $NetBSD: sbc_crc.c,v 1.3 2017/01/30 15:56:44 christos Exp $ */
/*-
* Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
* All rights reserved.
*
* This software is dedicated to the memory of -
* Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
*
* Barry was a man who loved his music.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
int
main(void)
{
unsigned int j, i, k, numbits, data;
printf("/* sbc_crc.h - Automatically generated by sbc_crc.c. */\n\n");
/* The CRC-8 polynomial this uses is 0x11D */
numbits = 8;
for (k = 0; k < 2; k++) {
printf("static const uint8_t sbc_crc%u[256] = {\n\t", numbits);
for (i = 0; i < 256; i++) {
data = i;
for (j = 0; j < numbits; j++) {
if (data & 0x80) {
data <<= 1;
data ^= 0x1d;
} else
data <<= 1;
}
if (i % 8 == 0 && i != 0)
printf("\n\t");
printf("0x%02x, ", data & 0xff);
}
printf("\n};\n\n");
numbits /= 2;
}
return 0;
}