view stashaway/mkcrc32tab.c @ 137:5fe5559003b7

RV bring-up: RVT "system time" heartbeat messages now get printed every 20 s! The problem was a slight Nucleus API incompatibility between what the RVF code from TCS211 expected and what our FreeNucleus implements: in the TCS211 version of Nucleus it was OK to pass 0 for the initial_time parameter to NU_Create_Timer(), but our version flags such usage as an error. RVF used 0 as the dummy initial_time value when initializing the legacy RV timers with NU_DISABLE_TIMER. Implemented fix: using a dummy value of 1 instead.
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 11 Nov 2013 09:56:23 +0000
parents 8fbd52a639a5
children
line wrap: on
line source

/*
 * This program generates the CRC-32 table for the LSB-first direction.
 * Derived from the MSB-first version written years earlier by the
 * same author (Michael Spacefalcon) for SDSL/ATM AAL5.
 */

#include <sys/types.h>
#include <stdio.h>

u_long table[256];

main(argc, argv)
	char **argv;
{
	build_table();
	emit_table();
	exit(0);
}

u_long
crc_byte(crc, inb)
	u_long crc;
	int inb;
{
	register int bit;

	crc ^= inb & 0xFF;
	for (bit = 0; bit < 8; bit++) {
		if (crc & 1)
			crc = (crc >> 1) ^ 0xEDB88320;
		else
			crc >>= 1;
	}
	return(crc);
}

build_table()
{
	int i;

	for (i = 0; i < 256; i++)
		table[i] = crc_byte(0, i);
}

emit_table()
{
	int i, j, idx;

	printf("unsigned long crc32_table[256] = {\n");
	for (i = 0, idx = 0; i < 64; i++) {
		putchar('\t');
		for (j = 0; j < 4; j++, idx++)
			printf("0x%08X,%c", table[idx], j==3 ? '\n' : ' ');
	}
	printf("};\n");
}