OpenCores
URL https://opencores.org/ocsvn/xge_mac/xge_mac/trunk

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [crc.cpp] - Blame information for rev 23

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
/*
2
 * efone - Distributed internet phone system.
3
 *
4
 * (c) 1999,2000 Krzysztof Dabrowski
5
 * (c) 1999,2000 ElysiuM deeZine
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version
10
 * 2 of the License, or (at your option) any later version.
11
 *
12
 */
13
 
14
/* based on implementation by Finn Yannick Jacobs */
15
 
16
#include <stdio.h>
17
#include <stdlib.h>
18
 
19
#include <systemc.h>
20
 
21
/* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
22
 *              so make sure, you call it before using the other
23
 *              functions!
24
 */
25
u_int32_t crc_tab[256];
26
 
27
/* chksum_crc() -- to a given block, this one calculates the
28
 *                              crc32-checksum until the length is
29
 *                              reached. the crc32-checksum will be
30
 *                              the result.
31
 */
32
u_int32_t chksum_crc32 (sc_uint<8> *block, unsigned int length)
33
{
34
    register unsigned long crc;
35
    unsigned long i;
36
 
37
    crc = 0xFFFFFFFF;
38
    for (i = 0; i < length; i++)
39
        {
40
            crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
41
        }
42
    return (crc ^ 0xFFFFFFFF);
43
}
44
 
45
/* chksum_crc32gentab() --      to a global crc_tab[256], this one will
46
 *                              calculate the crcTable for crc32-checksums.
47
 *                              it is generated to the polynom [..]
48
 */
49
 
50
void chksum_crc32gentab ()
51
{
52
    unsigned long crc, poly;
53
    int i, j;
54
 
55
    poly = 0xEDB88320L;
56
    for (i = 0; i < 256; i++)
57
        {
58
            crc = i;
59
            for (j = 8; j > 0; j--)
60
                {
61
                    if (crc & 1)
62
                        {
63
                            crc = (crc >> 1) ^ poly;
64
                        }
65
                    else
66
                        {
67
                            crc >>= 1;
68
                        }
69
                }
70
            crc_tab[i] = crc;
71
        }
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.