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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [packet_codec/] [1.0/] [vhd/] [pkt_counter.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Packet counter
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : pkt_counter.vhd
6
-- Author     : Jussi Nieminen
7
-- Company    : 
8
-- Created    : 2009-05-05
9
-- Last update: 2011-12-01
10
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: Counts pkt length, num of pkts and idle time
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2009 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2009-05-05  1.0      niemin95        Created
20
-------------------------------------------------------------------------------
21
 
22
-------------------------------------------------------------------------------
23
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
24
--
25
-- This source file may be used and distributed without
26
-- restriction provided that this copyright statement is not
27
-- removed from the file and that any derivative work contains
28
-- the original copyright notice and the associated disclaimer.
29
--
30
-- This source file is free software; you can redistribute it
31
-- and/or modify it under the terms of the GNU Lesser General
32
-- Public License as published by the Free Software Foundation;
33
-- either version 2.1 of the License, or (at your option) any
34
-- later version.
35
--
36
-- This source is distributed in the hope that it will be
37
-- useful, but WITHOUT ANY WARRANTY; without even the implied
38
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39
-- PURPOSE.  See the GNU Lesser General Public License for more
40
-- details.
41
--
42
-- You should have received a copy of the GNU Lesser General
43
-- Public License along with this source; if not, download it
44
-- from http://www.opencores.org/lgpl.shtml
45
-------------------------------------------------------------------------------
46
 
47
 
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.numeric_std.all;
51
 
52
 
53
entity pkt_counter is
54
 
55
  generic (
56
    tx_len_width_g : integer := 8
57
    );
58
 
59
  port (
60
    clk        : in std_logic;
61
    rst_n      : in std_logic;
62
 
63
    len_in     : in std_logic_vector( tx_len_width_g-1 downto 0 );
64
    new_tx_in  : in std_logic;
65
    new_pkt_in : in std_logic;
66
    idle_in    : in std_logic
67
    );
68
 
69
end pkt_counter;
70
 
71
 
72
architecture rtl of pkt_counter is
73
 
74
  -- count idle time
75
  signal idle_counter_r : integer;
76
  -- count active time to get procentual data
77
  signal active_counter_r : integer;
78
 
79
  -- min, max and avg pkt size
80
  signal min_tx_size_r : integer;
81
  signal max_tx_size_r : integer;
82
  -- needed for the avg
83
  signal sum_of_len_r : integer;
84
  signal current_tx_size_r : integer;
85
 
86
  -- num of packets
87
  signal pkt_count_r : integer;
88
  -- num of transfers
89
  signal tx_count_r : integer;
90
 
91
 
92
  -- needed for edge detection
93
  signal old_new_pkt_r : std_logic;
94
  signal old_new_tx_r : std_logic;
95
 
96
  -- len as integer
97
  signal len_int : integer;
98
 
99
-------------------------------------------------------------------------------
100
begin  -- rtl
101
-------------------------------------------------------------------------------
102
 
103
  -- convert len_in to integer
104
  len_int <= to_integer( unsigned( len_in ) );
105
 
106
 
107
  main: process (clk, rst_n)
108
    variable curr_tx_size_v : integer;
109
  begin  -- process main
110
    if rst_n = '0' then                 -- asynchronous reset (active low)
111
 
112
      idle_counter_r    <= 0;
113
      active_counter_r  <= 0;
114
      min_tx_size_r     <= 0;
115
      max_tx_size_r     <= 0;
116
      sum_of_len_r      <= 0;
117
      pkt_count_r       <= 0;
118
      tx_count_r        <= 0;
119
      current_tx_size_r <= 0;
120
      old_new_tx_r      <= '0';
121
      old_new_pkt_r     <= '0';
122
 
123
    elsif clk'event and clk = '1' then  -- rising clock edge
124
 
125
      old_new_pkt_r <= new_pkt_in;
126
      old_new_tx_r <= new_tx_in;
127
 
128
      curr_tx_size_v := current_tx_size_r;
129
 
130
      -- count the num of transfers from the rising edge
131
      if new_tx_in = '1' and old_new_tx_r = '0' then
132
        tx_count_r <= tx_count_r + 1;
133
 
134
        -- new tx, check the min size and reset the size counter
135
        -- min
136
        if min_tx_size_r = 0 or current_tx_size_r < min_tx_size_r then
137
          min_tx_size_r <= current_tx_size_r;
138
        end if;
139
 
140
        curr_tx_size_v := 0;
141
      end if;
142
 
143
 
144
      -- new_pkt_in comes from the write request, and it can be up several clk
145
      -- cycles, count rising edges
146
      if new_pkt_in = '1' and old_new_pkt_r = '0' then
147
        pkt_count_r <= pkt_count_r + 1;
148
 
149
        curr_tx_size_v := curr_tx_size_v + len_int;
150
 
151
        -- count pkt sizes here
152
        -- max
153
        if curr_tx_size_v > max_tx_size_r then
154
          max_tx_size_r <= curr_tx_size_v;
155
        end if;
156
 
157
        -- sum of lengths for counting of average length
158
        sum_of_len_r <= sum_of_len_r + len_int;
159
 
160
      end if;
161
 
162
      current_tx_size_r <= curr_tx_size_v;
163
 
164
      -- count the idle and active time
165
      if idle_in = '1' then
166
        idle_counter_r <= idle_counter_r + 1;
167
      else
168
        active_counter_r <= active_counter_r + 1;
169
      end if;
170
 
171
    end if;
172
  end process main;
173
 
174
end rtl;

powered by: WebSVN 2.1.0

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