1 |
10 |
khatib |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Tx buffer
|
3 |
|
|
-- Project : HDLC controller
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : TxBuff.vhd
|
6 |
|
|
-- Author : Jamil Khatib (khatib@ieee.org)
|
7 |
|
|
-- Organization: OpenIPCore Project
|
8 |
|
|
-- Created :2001/03/08
|
9 |
|
|
-- Last update: 2001/03/18
|
10 |
|
|
-- Platform :
|
11 |
|
|
-- Simulators : Modelsim 5.3XE/Windows98,NC-SIM/Linux
|
12 |
|
|
-- Synthesizers:
|
13 |
|
|
-- Target :
|
14 |
|
|
-- Dependency : ieee.std_logic_1164
|
15 |
|
|
-- memLib.mem_pkg
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-- Description: HDLC controller
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
-- Copyright (c) 2000 Jamil Khatib
|
20 |
|
|
--
|
21 |
|
|
-- This VHDL design file is an open design; you can redistribute it and/or
|
22 |
|
|
-- modify it and/or implement it after contacting the author
|
23 |
|
|
-- You can check the draft license at
|
24 |
|
|
-- http://www.opencores.org/OIPC/license.shtml
|
25 |
|
|
|
26 |
|
|
-------------------------------------------------------------------------------
|
27 |
|
|
-- Revisions :
|
28 |
|
|
-- Revision Number : 1
|
29 |
|
|
-- Version : 0.1
|
30 |
|
|
-- Date : 8 March 2001
|
31 |
|
|
-- Modifier : Jamil Khatib (khatib@ieee.org)
|
32 |
|
|
-- Desccription : Created
|
33 |
|
|
-- ToOptimize :
|
34 |
|
|
-- Bugs :
|
35 |
|
|
-------------------------------------------------------------------------------
|
36 |
|
|
-- $Log: not supported by cvs2svn $
|
37 |
|
|
-- Revision 1.1 2001/03/21 20:19:43 jamil
|
38 |
|
|
-- Initial Release
|
39 |
|
|
--
|
40 |
|
|
-------------------------------------------------------------------------------
|
41 |
|
|
|
42 |
|
|
library ieee;
|
43 |
|
|
use ieee.std_logic_1164.all;
|
44 |
|
|
use ieee.std_logic_unsigned.all;
|
45 |
|
|
|
46 |
|
|
library memLib;
|
47 |
|
|
use memLib.mem_pkg.all;
|
48 |
|
|
|
49 |
|
|
entity TxBuff_ent is
|
50 |
|
|
generic (
|
51 |
|
|
ADD_WIDTH : integer := 7); -- Internal address width
|
52 |
|
|
|
53 |
|
|
port (
|
54 |
|
|
TxClk : in std_logic; -- Tx Clock
|
55 |
|
|
rst_n : in std_logic; -- System reset
|
56 |
|
|
RdBuff : in std_logic; -- Read byte
|
57 |
|
|
Wr : in std_logic; -- Write Byte
|
58 |
|
|
TxDataAvail : out std_logic; -- Data Available to be read
|
59 |
|
|
TxEnable : in std_logic; -- TxEnable (Write Frame completed)
|
60 |
|
|
TxDone : out std_logic; -- Transmission Done (Read Frame completed)
|
61 |
|
|
TxDataOutBuff : out std_logic_vector(7 downto 0); -- Output Data
|
62 |
|
|
TxDataInBuff : in std_logic_vector(7 downto 0); -- Input Data
|
63 |
|
|
Full : out std_logic); -- Full Buffer (no more write is allowed)
|
64 |
|
|
|
65 |
|
|
end TxBuff_ent;
|
66 |
|
|
-------------------------------------------------------------------------------
|
67 |
|
|
|
68 |
|
|
architecture TxBuff_beh of TxBuff_ent is
|
69 |
|
|
|
70 |
|
|
signal WR_i : std_logic; -- Internal Read/Write signal
|
71 |
|
|
signal Address : std_logic_vector(ADD_WIDTH-1 downto 0);
|
72 |
|
|
-- Internal Address bus
|
73 |
|
|
type states_typ is (IDLE_typ, WRITE_typ, READ_typ); -- states types
|
74 |
|
|
|
75 |
|
|
signal p_state : states_typ; -- Present state
|
76 |
|
|
signal n_state : states_typ; -- Next State
|
77 |
|
|
|
78 |
|
|
signal FrameSize : std_logic_vector(ADD_WIDTH-1 downto 0); -- Frame Size
|
79 |
|
|
signal load_FrSize : std_logic; -- Load Frame Size
|
80 |
|
|
signal en_Count : std_logic; -- Enable Counter
|
81 |
|
|
|
82 |
|
|
signal Data_In_i : std_logic_vector(7 downto 0);
|
83 |
|
|
-- Internal Data in
|
84 |
|
|
signal Data_Out_i : std_logic_vector(7 downto 0);
|
85 |
|
|
-- Internal Data out
|
86 |
|
|
constant MAX_ADDRESS : std_logic_vector(ADD_WIDTH-1 downto 0) := (others => '1');
|
87 |
|
|
-- MAX Address
|
88 |
|
|
|
89 |
|
|
signal Count : std_logic_vector(ADD_WIDTH-1 downto 0); -- Counter
|
90 |
|
|
signal rst_count : std_logic; -- Reset Counter
|
91 |
|
|
|
92 |
|
|
signal cs_i : std_logic := '1'; -- Internal chip select
|
93 |
|
|
begin -- TxBuff_beh
|
94 |
|
|
|
95 |
|
|
Spmem_core : Spmem_ent
|
96 |
|
|
generic map (
|
97 |
|
|
USE_RESET => false,
|
98 |
|
|
USE_CS => false,
|
99 |
|
|
DEFAULT_OUT => '0',
|
100 |
|
|
OPTION => 0,
|
101 |
|
|
ADD_WIDTH => ADD_WIDTH,
|
102 |
|
|
WIDTH => 8)
|
103 |
|
|
port map (
|
104 |
|
|
cs => cs_i,
|
105 |
|
|
clk => TxClk,
|
106 |
|
|
reset => rst_n,
|
107 |
|
|
add => Address,
|
108 |
|
|
Data_In => Data_In_i,
|
109 |
|
|
Data_Out => Data_Out_i,
|
110 |
|
|
WR => WR_i);
|
111 |
|
|
-------------------------------------------------------------------------------
|
112 |
|
|
|
113 |
|
|
Data_In_i <= TxDataInBuff;
|
114 |
|
|
TxDataOutBuff <= Data_Out_i;
|
115 |
|
|
|
116 |
|
|
-------------------------------------------------------------------------------
|
117 |
|
|
Full <= '1' when Address = MAX_ADDRESS else '0';
|
118 |
|
|
Address <= Count;
|
119 |
|
|
|
120 |
|
|
-------------------------------------------------------------------------------
|
121 |
|
|
-- purpose: Byte counter
|
122 |
|
|
-- type : sequential
|
123 |
|
|
-- inputs : TxClk, rst_n
|
124 |
|
|
-- outputs:
|
125 |
|
|
counter_proc : process (TxClk, rst_n)
|
126 |
|
|
-- variable count : std_logic_vector(ADD_WIDTH-1 downto 0); -- Counter
|
127 |
|
|
begin -- process counter_proc
|
128 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
129 |
|
|
|
130 |
|
|
count <= (others => '0');
|
131 |
|
|
|
132 |
|
|
elsif TxClk'event and TxClk = '1' then -- rising clock edge
|
133 |
|
|
if rst_count = '1' then
|
134 |
|
|
count <= (others => '0');
|
135 |
|
|
elsif en_Count = '1' then
|
136 |
|
|
count <= count +1;
|
137 |
|
|
end if;
|
138 |
|
|
|
139 |
|
|
end if;
|
140 |
|
|
end process counter_proc;
|
141 |
|
|
-------------------------------------------------------------------------------
|
142 |
|
|
-- purpose: Frame Size register
|
143 |
|
|
-- type : sequential
|
144 |
|
|
-- inputs : TxClk, rst_n
|
145 |
|
|
-- outputs:
|
146 |
|
|
FrameSize_reg : process (TxClk, rst_n)
|
147 |
|
|
begin -- process FrameSize_reg
|
148 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
149 |
|
|
FrameSize <= (others => '0');
|
150 |
|
|
|
151 |
|
|
elsif TxClk'event and TxClk = '1' then -- rising clock edge
|
152 |
|
|
if load_FrSize = '1' then
|
153 |
|
|
FrameSize <= address;
|
154 |
|
|
end if;
|
155 |
|
|
end if;
|
156 |
|
|
end process FrameSize_reg;
|
157 |
|
|
|
158 |
|
|
-------------------------------------------------------------------------------
|
159 |
|
|
|
160 |
|
|
-- purpose: fsm process
|
161 |
|
|
-- type : sequential
|
162 |
|
|
-- inputs : TxClk, rst_n
|
163 |
|
|
-- outputs:
|
164 |
|
|
fsm_proc : process (TxClk, rst_n)
|
165 |
|
|
begin -- process fsm_proc
|
166 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
167 |
|
|
|
168 |
|
|
p_state <= IDLE_typ;
|
169 |
|
|
|
170 |
|
|
elsif TxClk'event and TxClk = '1' then -- rising clock edge
|
171 |
|
|
p_state <= n_state;
|
172 |
|
|
end if;
|
173 |
|
|
end process fsm_proc;
|
174 |
|
|
-------------------------------------------------------------------------------
|
175 |
|
|
-- purpose: Read write machine
|
176 |
|
|
-- type : combinational
|
177 |
|
|
-- inputs : strobe
|
178 |
|
|
-- outputs:
|
179 |
|
|
read_write_proc : process (TxEnable, Wr, Address, p_state, RdBuff, FrameSize)
|
180 |
|
|
|
181 |
|
|
begin -- process read_write_proc
|
182 |
|
|
|
183 |
|
|
case p_state is
|
184 |
|
|
|
185 |
|
|
when IDLE_typ =>
|
186 |
|
|
|
187 |
|
|
TxDone <= '1';
|
188 |
|
|
TxDataAvail <= '0';
|
189 |
|
|
load_FrSize <= '0';
|
190 |
|
|
|
191 |
|
|
wr_i <= not wr;
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
if wr = '1' then
|
195 |
|
|
n_state <= WRITE_typ;
|
196 |
|
|
en_Count <= '1';
|
197 |
|
|
rst_count <= '0';
|
198 |
|
|
else
|
199 |
|
|
n_state <= IDLE_typ;
|
200 |
|
|
en_Count <= '0';
|
201 |
|
|
rst_count <= '1';
|
202 |
|
|
end if;
|
203 |
|
|
|
204 |
|
|
when WRITE_typ =>
|
205 |
|
|
TxDone <= '0';
|
206 |
|
|
TxDataAvail <= '0';
|
207 |
|
|
|
208 |
|
|
wr_i <= not wr;
|
209 |
|
|
en_Count <= wr;
|
210 |
|
|
|
211 |
|
|
if (TxEnable = '1') or (address = MAX_ADDRESS) then
|
212 |
|
|
|
213 |
|
|
n_state <= READ_typ;
|
214 |
|
|
load_FrSize <= '1';
|
215 |
|
|
rst_count <= '1';
|
216 |
|
|
else
|
217 |
|
|
n_state <= WRITE_typ;
|
218 |
|
|
load_FrSize <= '0';
|
219 |
|
|
rst_count <= '0';
|
220 |
|
|
end if;
|
221 |
|
|
|
222 |
|
|
when READ_typ =>
|
223 |
|
|
|
224 |
|
|
wr_i <= '1';
|
225 |
|
|
en_Count <= RdBuff;
|
226 |
|
|
load_FrSize <= '0';
|
227 |
|
|
TxDataAvail <= '1';
|
228 |
|
|
|
229 |
|
|
if address = FrameSize then
|
230 |
|
|
TxDone <= '1';
|
231 |
|
|
n_state <= IDLE_typ;
|
232 |
|
|
rst_count <= '1';
|
233 |
|
|
else
|
234 |
|
|
TxDone <= '0';
|
235 |
|
|
n_state <= READ_typ;
|
236 |
|
|
rst_count <= '0';
|
237 |
|
|
end if;
|
238 |
|
|
|
239 |
|
|
when others =>
|
240 |
|
|
wr_i <= '1';
|
241 |
|
|
en_Count <= '0';
|
242 |
|
|
load_FrSize <= '0';
|
243 |
|
|
TxDataAvail <= '0';
|
244 |
|
|
TxDone <= '0';
|
245 |
|
|
rst_count <= '1';
|
246 |
|
|
end case;
|
247 |
|
|
|
248 |
|
|
end process read_write_proc;
|
249 |
|
|
end TxBuff_beh;
|