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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [sc_packet.cpp] - Blame information for rev 31

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

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "sc_packet.cpp"                                   ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
#include <stdio.h>
39
#include <iostream>
40
#include <sys/times.h>
41
#include <sys/stat.h>
42
 
43
#include "systemc.h"
44
 
45
#include "crc.h"
46
#include "sc_packet.h"
47
 
48
ostream& operator<<(ostream& os, const packet_t& p) {
49
    os << "\n=====================\n"
50
       << dec
51
       << "   length   : " << p.length  << "\n"
52
       << hex
53
       << "   src_addr : 0x" << p.src_addr  << "\n"
54
       << "   dest_addr: 0x" << p.dest_addr << "\n"
55
       << "   crc      : 0x" << p.crc << "\n"
56
       << "   crc_rx   : 0x" << p.crc_rx << "\n"
57
       << "   err_flags: 0x" << p.err_flags << "\n"
58
       << "   payload  : " << "\n";
59
 
60
    for (int i = 0; i < p.length; i++) {
61
        os << p.payload[i] << " ";
62
    }
63
 
64
    cout << "\n--\n";
65
 
66
    for (int i = 0; i < p.length; i++) {
67
        os << p.data[i] << " ";
68
    }
69
 
70
    os << dec << "\n" << endl;
71
 
72
    return os;
73
}
74
 
75
void pack(packet_t* p) {
76
    if (p->dest_addr != 0) {
77
        for (int i = 0; i < 6; i++) {
78
            p->payload[i] = p->dest_addr >> ((5-i)*8);
79
        }
80
    }
81
    for (int i = 0; i < p->length; i++) {
82
        p->data[i] = p->payload[i];
83
    }
84
}
85
 
86
 
87
void unpack(packet_t* p) {
88
    for (int i = 0; i < p->length; i++) {
89
        p->payload[i] = p->data[i];
90
    }
91
}
92
 
93
void add_crc(packet_t* p) {
94
    for (int i = p->length; i < p->length + 4; i++) {
95
        p->data[i] = p->crc >> (8 * (i - p->length));
96
    }
97
    p->length += 4;
98
}
99
 
100
void strip_crc(packet_t* p) {
101
    if (p->length >= 4) {
102
        p->crc_rx = 0;
103
        for (int i = p->length - 4; i < p->length; i++) {
104
          p->crc_rx |= p->data[i] << (8 * (i - p->length - 4));
105
        }
106
        p->length -= 4;
107
    }
108
}
109
 
110
void calc_crc(packet_t* p) {
111
 
112
    u_int32_t crc;
113
 
114
    p->crc = chksum_crc32(p->data, p->length);
115
}
116
 
117
void pad(packet_t* p, int len) {
118
    if (p->length < len) {
119
        for (int i = p->length; i < len; i++) {
120
            p->payload[i] = 0;
121
        }
122
        p->length = len;
123
    };
124
}
125
 
126
bool compare(packet_t* pkta, packet_t* pktb) {
127
 
128
    bool good = true;
129
 
130
    if (pkta->length != pktb->length) {
131
 
132
        good = false;
133
 
134
    }
135
    else {
136
 
137
        if (pkta->crc != pktb->crc) {
138
            good = false;
139
        }
140
 
141
        for (int i = 0; i < pkta->length; i++) {
142
            if (pkta->payload[i] != pktb->payload[i]) {
143
                good = false;
144
            }
145
        }
146
 
147
    }
148
 
149
    return good;
150
}
151
 

powered by: WebSVN 2.1.0

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