sbc_crc.c revision 1.1
11.1Snat/* $NetBSD: sbc_crc.c,v 1.1 2017/01/28 16:55:54 nat 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 <sys/types.h> 351.1Snat#include <stdio.h> 361.1Snat 371.1Snatint 381.1Snatmain() 391.1Snat{ 401.1Snat int j, i, k, numbits; 411.1Snat uint8_t data; 421.1Snat 431.1Snat printf("/* sbc_crc.h - Automatically generated by sbc_crc.c. */\n\n"); 441.1Snat 451.1Snat /* The CRC-8 polynomial this uses is 0x11D */ 461.1Snat 471.1Snat numbits = 8; 481.1Snat for (k = 0; k < 2; k++) { 491.1Snat printf("static const uint8_t sbc_crc%d[256] = {\n ",numbits); 501.1Snat for (i = 0; i < 256; i++) { 511.1Snat data = i; 521.1Snat 531.1Snat for (j = 0; j < numbits; j++) { 541.1Snat if (data & 0x80){ 551.1Snat data = data << 1; 561.1Snat data = (data ^ 0x1d); 571.1Snat } else 581.1Snat data = data << 1; 591.1Snat } 601.1Snat 611.1Snat if (i % 8 == 0 && i != 0) 621.1Snat printf("\n "); 631.1Snat 641.1Snat printf("0x%02x, ",data); 651.1Snat } 661.1Snat printf("\n};\n\n"); 671.1Snat 681.1Snat numbits = 4; 691.1Snat } 701.1Snat return 0; 711.1Snat} 72