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.interface/] [switch_packet_codec/] [1.0/] [vhd/] [switch_packet_codec.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Switch to packet codec
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : switch_packet_codec.vhd
6
-- Author     : Lasse Lehtonen
7
-- Company    : 
8
-- Last update: 2012-03-16
9
-- Platform   : 
10
-------------------------------------------------------------------------------
11
-- Description: Detects an edge in switch input and generates a constant
12
--              message to the network.
13
-------------------------------------------------------------------------------
14
-- Revisions  :
15
-- Date        Version  Author  Description
16
 
17
-------------------------------------------------------------------------------
18
 
19
-------------------------------------------------------------------------------
20
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
21
--
22
-- This source file may be used and distributed without
23
-- restriction provided that this copyright statement is not
24
-- removed from the file and that any derivative work contains
25
-- the original copyright notice and the associated disclaimer.
26
--
27
-- This source file is free software; you can redistribute it
28
-- and/or modify it under the terms of the GNU Lesser General
29
-- Public License as published by the Free Software Foundation;
30
-- either version 2.1 of the License, or (at your option) any
31
-- later version.
32
--
33
-- This source is distributed in the hope that it will be
34
-- useful, but WITHOUT ANY WARRANTY; without even the implied
35
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
36
-- PURPOSE.  See the GNU Lesser General Public License for more
37
-- details.
38
--
39
-- You should have received a copy of the GNU Lesser General
40
-- Public License along with this source; if not, download it
41
-- from http://www.opencores.org/lgpl.shtml
42
-------------------------------------------------------------------------------
43
 
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47
use ieee.numeric_std.all;
48
 
49
entity switch_packet_codec is
50
 
51
  generic (
52
    data_width_g   : integer := 32;
53
    tx_len_width_g : integer := 16;
54
    my_id_g        : integer);          -- Target network address
55
                                        -- And yes, very poor name for that
56
 
57
  port (
58
 
59
 
60
    clk   : in std_logic;
61
    rst_n : in std_logic;
62
 
63
 
64
    tx_av_out    : out std_logic;
65
    tx_data_out  : out std_logic_vector (data_width_g -1 downto 0);
66
    tx_comm_out  : out std_logic_vector (5 -1 downto 0);
67
    tx_we_out    : out std_logic;
68
    tx_txlen_out : out std_logic_vector (tx_len_width_g -1 downto 0);
69
    tx_full_in   : in  std_logic;
70
 
71
    rx_av_in    : in  std_logic;
72
    rx_data_in  : in  std_logic_vector (data_width_g -1 downto 0);
73
    rx_re_out   : out std_logic;
74
    rx_empty_in : in  std_logic;
75
 
76
 
77
    switch_in : in std_logic
78
    );
79
 
80
end switch_packet_codec;
81
 
82
 
83
 
84
architecture rtl of switch_packet_codec is
85
 
86
  signal tx_av_out_r    : std_logic;
87
  signal tx_data_out_r  : std_logic_vector(data_width_g-1 downto 0);
88
  signal tx_we_out_r    : std_logic;
89
  signal tx_txlen_out_r : std_logic_vector(tx_len_width_g-1 downto 0);
90
 
91
  signal switch_in_r  : std_logic;
92
  signal switch_in2_r : std_logic;
93
  signal switch_in3_r : std_logic;
94
 
95
  type   state_type is (idle, addr, data);
96
  signal state_r : state_type;
97
 
98
begin  -- rtl
99
 
100
  tx_av_out    <= tx_av_out_r;
101
  tx_data_out  <= tx_data_out_r;
102
  tx_we_out    <= tx_we_out_r;
103
  tx_txlen_out <= tx_txlen_out_r;
104
  rx_re_out    <= '0';
105
 
106
 
107
  tx_comm_out <= "00010" when tx_we_out_r = '1' else (others => '0');  -- ES 2012-03-16
108
 
109
  main_p : process (clk, rst_n)
110
  begin  -- process main_p
111
    if rst_n = '0' then                 -- asynchronous reset (active low)
112
 
113
      tx_av_out_r    <= '0';
114
      tx_data_out_r  <= (others => '0');
115
      tx_we_out_r    <= '0';
116
      tx_txlen_out_r <= (others => '0');
117
      switch_in_r    <= '0';
118
      state_r        <= idle;
119
 
120
    elsif clk'event and clk = '1' then  -- rising clock edge
121
 
122
      switch_in3_r <= switch_in;
123
      switch_in2_r <= switch_in3_r;
124
      switch_in_r  <= switch_in2_r;
125
 
126
      case state_r is
127
        -----------------------------------------------------------------------
128
        -- IDLE
129
        -----------------------------------------------------------------------
130
        when idle =>
131
          tx_av_out_r    <= '0';
132
          tx_data_out_r  <= (others => '0');
133
          tx_we_out_r    <= '0';
134
          tx_txlen_out_r <= (others => '0');
135
 
136
          if switch_in2_r /= switch_in_r then
137
            state_r <= addr;
138
          end if;
139
 
140
          ---------------------------------------------------------------------
141
          -- ADDR
142
          ---------------------------------------------------------------------
143
        when addr =>
144
          tx_av_out_r   <= '1';
145
          tx_data_out_r <=
146
            std_logic_vector(to_unsigned(my_id_g, data_width_g));
147
          tx_txlen_out_r <= std_logic_vector(to_unsigned(1, tx_len_width_g));
148
          tx_we_out_r    <= '1';
149
          if tx_full_in /= '1' then
150
            state_r <= data;
151
          end if;
152
 
153
 
154
          ---------------------------------------------------------------------
155
          -- DATA
156
          ---------------------------------------------------------------------
157
        when data =>
158
          tx_av_out_r    <= '0';
159
          tx_data_out_r  <= std_logic_vector(to_unsigned(42, data_width_g));
160
          tx_txlen_out_r <= std_logic_vector(to_unsigned(1, tx_len_width_g));
161
          tx_we_out_r    <= '1';
162
          if tx_full_in /= '1' then
163
            state_r <= idle;
164
          end if;
165
 
166
 
167
        when others =>
168
          state_r <= idle;
169
 
170
      end case;
171
 
172
 
173
    end if;
174
  end process main_p;
175
 
176
end rtl;

powered by: WebSVN 2.1.0

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