OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [tags/] [v0.0/] [sw/] [dev/] [test_bfm/] [ether/] [crc_ip.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kuzmi4
//////////////////////////////////////////////////////////////////////////////////
2
#include <stdlib.h>
3
#include <stdio.h>
4
 
5
//////////////////////////////////////////////////////////////////////////////////
6
 
7
unsigned short crc_ip(void * ptr, unsigned count)
8
{
9
    unsigned short checksum;
10
    unsigned short * addr = (unsigned short *)ptr;
11
 
12
    /********** code from rfc1071 **********/
13
    {
14
        /* Compute Internet Checksum for "count" bytes
15
        *         beginning at location "addr".
16
        */
17
 
18
        long sum = 0;
19
        count += count;  /* make passed word count into byte count */
20
 
21
        while( count > 1 )
22
        {
23
            /*  This is the inner loop */
24
            sum += *addr++;
25
            count -= 2;
26
        }
27
 
28
        /*  Add left-over byte, if any */
29
        if( count > 0 )
30
            sum += * (unsigned char *) addr;
31
 
32
        /*  Fold 32-bit sum to 16 bits */
33
        while (sum>>16)
34
            sum = (sum & 0xffff) + (sum >> 16);
35
 
36
        // curr CRC realisation expects to do the final 1s complement of the checksum in the raw-code
37
        checksum = (unsigned short)sum;
38
        // or?
39
        //checksum = ~sum;
40
   }
41
    /******** end of RFC 1071 code **********/
42
 
43
    return checksum;
44
}
45
 
46
//////////////////////////////////////////////////////////////////////////////////

powered by: WebSVN 2.1.0

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