1 |
2 |
khatib |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : ISDN tdm controller
|
3 |
|
|
-- Project : TDM controller
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : ISDN_cont.vhd
|
6 |
|
|
-- Author : Jamil Khatib <khatib@ieee.org>
|
7 |
|
|
-- Organization: OpenCores.org
|
8 |
|
|
-- Created : 2001/04/30
|
9 |
|
|
-- Last update:2001/05/04
|
10 |
|
|
-- Platform :
|
11 |
|
|
-- Simulators : NC-sim/linux, Modelsim XE/windows98
|
12 |
|
|
-- Synthesizers: Leonardo
|
13 |
|
|
-- Target :
|
14 |
|
|
-- Dependency : ieee.std_logic_1164
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
|
|
-- Description: ISDN tdm controller that extracts 2B+D channels from 3 time
|
17 |
|
|
-- slots of the incoming streem
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
-- Copyright (c) 2001 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 |
|
|
-- Revisions :
|
27 |
|
|
-- Revision Number : 1
|
28 |
|
|
-- Version : 0.1
|
29 |
|
|
-- Date : 2001/04/30
|
30 |
|
|
-- Modifier : Jamil Khatib <khatib@ieee.org>
|
31 |
|
|
-- Desccription : Created
|
32 |
|
|
-- ToOptimize :
|
33 |
|
|
-- Known Bugs : The serial interface is not compatible with the ST-Bus
|
34 |
|
|
-------------------------------------------------------------------------------
|
35 |
|
|
-- $Log: not supported by cvs2svn $
|
36 |
|
|
-- Revision 1.1 2001/05/06 17:55:23 jamil
|
37 |
|
|
-- Initial Release
|
38 |
|
|
--
|
39 |
|
|
-------------------------------------------------------------------------------
|
40 |
|
|
library ieee;
|
41 |
|
|
use ieee.std_logic_1164.all;
|
42 |
|
|
use ieee.std_logic_unsigned.all;
|
43 |
|
|
|
44 |
|
|
entity isdn_cont_ent is
|
45 |
|
|
|
46 |
|
|
port (
|
47 |
|
|
rst_n : in std_logic; -- System asynchronous reset
|
48 |
|
|
C2 : in std_logic; -- ST-Bus clock
|
49 |
|
|
DSTi : in std_logic; -- ST-Bus input Data
|
50 |
|
|
DSTo : out std_logic; -- ST-Bus output Data
|
51 |
|
|
F0_n : in std_logic; -- St-Bus Framing pulse
|
52 |
|
|
F0od_n : out std_logic; -- ST-Bus Delayed Framing pulse
|
53 |
|
|
HDLCen1 : out std_logic; -- HDLC controller 1 enable
|
54 |
|
|
HDLCen2 : out std_logic; -- HDLC controller 2 enable
|
55 |
|
|
HDLCen3 : out std_logic; -- HDLC controller 3 enable
|
56 |
|
|
HDLCTxen1 : out std_logic; -- HDLC controller 1 enable Tx
|
57 |
|
|
HDLCTxen2 : out std_logic; -- HDLC controller 2 enable Tx
|
58 |
|
|
HDLCTxen3 : out std_logic; -- HDLC controller 3 enable Tx
|
59 |
|
|
Dout : out std_logic; -- Serial Data output
|
60 |
|
|
Din1 : in std_logic; -- Serial Data input1
|
61 |
|
|
Din2 : in std_logic; -- Serial Data input2
|
62 |
|
|
Din3 : in std_logic); -- Serial Data input3
|
63 |
|
|
|
64 |
|
|
end isdn_cont_ent;
|
65 |
|
|
|
66 |
|
|
-------------------------------------------------------------------------------
|
67 |
|
|
|
68 |
|
|
architecture isdn_cont_rtl of isdn_cont_ent is
|
69 |
|
|
type STATES_TYPE is (IDLE_st, PASSB1_st, PASSB2_st, PASSD_st); -- FSM states
|
70 |
|
|
|
71 |
|
|
signal p_state : STATES_TYPE; -- Present state
|
72 |
|
|
signal n_state : STATES_TYPE; -- Next State
|
73 |
|
|
signal counter_Rx_i : std_logic_vector( 2 downto 0); -- Internal counter
|
74 |
|
|
signal counter_Rx_reg : std_logic_vector( 2 downto 0); -- Internal counter
|
75 |
|
|
|
76 |
|
|
signal p_state_Tx : STATES_TYPE; -- Present state
|
77 |
|
|
signal n_state_Tx : STATES_TYPE; -- Next State
|
78 |
|
|
|
79 |
|
|
signal counter_Tx_i : std_logic_vector( 2 downto 0); -- Internal counter
|
80 |
|
|
signal counter_Tx_reg : std_logic_vector( 2 downto 0); -- Internal counter
|
81 |
|
|
|
82 |
|
|
signal DSTi_reg : std_logic; -- DSTi register
|
83 |
|
|
signal F0_n_reg : std_logic; -- F0_n register
|
84 |
|
|
|
85 |
|
|
signal F0od_n_i : std_logic; -- Delayed F0output internal
|
86 |
|
|
signal outputData_reg : std_logic_vector(17 downto 0);
|
87 |
|
|
-- Output Data register
|
88 |
|
|
signal outputData : std_logic_vector(17 downto 0);
|
89 |
|
|
-- Output Data
|
90 |
|
|
|
91 |
|
|
begin -- isdn_cont_rtl
|
92 |
|
|
|
93 |
|
|
Dout <= DSTi_reg;
|
94 |
|
|
|
95 |
|
|
-- purpose: Rising edge F0_n sampling
|
96 |
|
|
-- type : sequential
|
97 |
|
|
-- inputs : C2, rst_n
|
98 |
|
|
-- outputs:
|
99 |
|
|
rising_edge_regs : process (C2, rst_n)
|
100 |
|
|
begin -- process rising_edge
|
101 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
102 |
|
|
F0_n_reg <= '1';
|
103 |
|
|
-- F0od_n <= '1';
|
104 |
|
|
outputData_reg <= (others => '1');
|
105 |
|
|
p_state_tx <= IDLE_st;
|
106 |
|
|
counter_Tx_reg <= "000";
|
107 |
|
|
elsif C2'event and C2 = '1' then -- rising clock edge
|
108 |
|
|
F0_n_reg <= F0_n;
|
109 |
|
|
-- F0od_n <= F0od_n_i;
|
110 |
|
|
outputData_reg <= outputData;
|
111 |
|
|
p_state_tx <= n_state_tx;
|
112 |
|
|
counter_Tx_reg <= counter_Tx_i;
|
113 |
|
|
end if;
|
114 |
|
|
end process rising_edge_regs;
|
115 |
|
|
-------------------------------------------------------------------------------
|
116 |
|
|
|
117 |
|
|
-------------------------------------------------------------------------------
|
118 |
|
|
-- purpose: FSM Combinational logic
|
119 |
|
|
-- type : combinational
|
120 |
|
|
-- inputs : F0_n, p_state_tx, counter_tx_reg, outputData_reg, Din1, Din2, Din3
|
121 |
|
|
-- outputs:
|
122 |
|
|
comb_tx : process (F0_n, p_state_tx, counter_tx_reg, outputData_reg, Din1, Din2, Din3)
|
123 |
|
|
|
124 |
|
|
begin -- PROCESS comb
|
125 |
|
|
|
126 |
|
|
case p_state_tx is
|
127 |
|
|
|
128 |
|
|
when IDLE_st =>
|
129 |
|
|
HDLCTxen1 <= '0';
|
130 |
|
|
HDLCTxen2 <= '0';
|
131 |
|
|
HDLCTxen3 <= '0';
|
132 |
|
|
|
133 |
|
|
counter_Tx_i <= "000";
|
134 |
|
|
|
135 |
|
|
DSTo <= 'Z';
|
136 |
|
|
outputData <= outputData_reg;
|
137 |
|
|
|
138 |
|
|
if (F0_n = '0') then
|
139 |
|
|
n_state_tx <= PASSB1_st;
|
140 |
|
|
else
|
141 |
|
|
n_state_tx <= IDLE_st;
|
142 |
|
|
end if;
|
143 |
|
|
|
144 |
|
|
when PASSB1_st =>
|
145 |
|
|
|
146 |
|
|
HDLCTxen1 <= '1';
|
147 |
|
|
HDLCTxen2 <= '0';
|
148 |
|
|
HDLCTxen3 <= '0';
|
149 |
|
|
|
150 |
|
|
counter_Tx_i <= counter_Tx_reg + 1;
|
151 |
|
|
|
152 |
|
|
if (counter_tx_reg = "110" ) then
|
153 |
|
|
n_state_tx <= PASSB2_st;
|
154 |
|
|
else
|
155 |
|
|
n_state_tx <= PASSB1_st;
|
156 |
|
|
end if;
|
157 |
|
|
DSTo <= outputData_reg(0);
|
158 |
|
|
outputData <= Din1 & outputData_reg(17 downto 1);
|
159 |
|
|
|
160 |
|
|
when PASSB2_st =>
|
161 |
|
|
counter_Tx_i <= counter_Tx_reg +1;
|
162 |
|
|
|
163 |
|
|
HDLCTxen1 <= '0';
|
164 |
|
|
HDLCTxen2 <= '1';
|
165 |
|
|
HDLCTxen3 <= '0';
|
166 |
|
|
|
167 |
|
|
if (counter_tx_reg = "110" ) then
|
168 |
|
|
n_state_tx <= PASSD_st;
|
169 |
|
|
else
|
170 |
|
|
n_state_tx <= PASSB2_st;
|
171 |
|
|
end if;
|
172 |
|
|
DSTo <= outputData_reg(0);
|
173 |
|
|
outputData <= Din2 & outputData_reg(17 downto 1);
|
174 |
|
|
|
175 |
|
|
when PASSD_st =>
|
176 |
|
|
counter_Tx_i <= counter_Tx_reg + 1;
|
177 |
|
|
|
178 |
|
|
HDLCTxen1 <= '0';
|
179 |
|
|
HDLCTxen2 <= '0';
|
180 |
|
|
HDLCTxen3 <= '1';
|
181 |
|
|
|
182 |
|
|
if (counter_tx_reg = "001" ) then
|
183 |
|
|
n_state_tx <= IDLE_st;
|
184 |
|
|
else
|
185 |
|
|
n_state_tx <= PASSD_st;
|
186 |
|
|
end if;
|
187 |
|
|
DSTo <= outputData_reg(0);
|
188 |
|
|
outputData <= Din3 & outputData_reg(17 downto 1);
|
189 |
|
|
|
190 |
|
|
end case;
|
191 |
|
|
|
192 |
|
|
end process comb_tx;
|
193 |
|
|
-------------------------------------------------------------------------------
|
194 |
|
|
-------------------------------------------------------------------------------
|
195 |
|
|
-------------------------------------------------------------------------------
|
196 |
|
|
-------------------------------------------------------------------------------
|
197 |
|
|
-- purpose: FSM registers
|
198 |
|
|
-- type : sequential
|
199 |
|
|
-- inputs : C2, rst_n
|
200 |
|
|
-- outputs:
|
201 |
|
|
fsm : process (C2, rst_n)
|
202 |
|
|
begin -- PROCESS fsm
|
203 |
|
|
|
204 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
205 |
|
|
p_state <= IDLE_st;
|
206 |
|
|
DSTi_reg <= '0';
|
207 |
|
|
F0od_n <= '1';
|
208 |
|
|
counter_Rx_reg <= "000";
|
209 |
|
|
elsif C2'event and C2 = '0' then -- falling clock edge
|
210 |
|
|
p_state <= n_state;
|
211 |
|
|
DSTi_reg <= DSTi;
|
212 |
|
|
F0od_n <= F0od_n_i;
|
213 |
|
|
counter_Rx_reg <= counter_Rx_i;
|
214 |
|
|
end if;
|
215 |
|
|
|
216 |
|
|
end process fsm;
|
217 |
|
|
|
218 |
|
|
-------------------------------------------------------------------------------
|
219 |
|
|
-- purpose: FSM Combinational logic
|
220 |
|
|
-- type : combinational
|
221 |
|
|
-- inputs : F0_n,Din,p_state
|
222 |
|
|
-- outputs:
|
223 |
|
|
comb : process (F0_n_reg, p_state, counter_Rx_reg, outputData_reg, Din1, Din2, Din3)
|
224 |
|
|
|
225 |
|
|
begin -- PROCESS comb
|
226 |
|
|
|
227 |
|
|
case p_state is
|
228 |
|
|
|
229 |
|
|
when IDLE_st =>
|
230 |
|
|
HDLCen1 <= '0';
|
231 |
|
|
HDLCen2 <= '0';
|
232 |
|
|
HDLCen3 <= '0';
|
233 |
|
|
|
234 |
|
|
counter_Rx_i <= "000";
|
235 |
|
|
|
236 |
|
|
F0od_n_i <= '1';
|
237 |
|
|
|
238 |
|
|
if (F0_n_reg = '0') then
|
239 |
|
|
n_state <= PASSB1_st;
|
240 |
|
|
else
|
241 |
|
|
n_state <= IDLE_st;
|
242 |
|
|
end if;
|
243 |
|
|
|
244 |
|
|
when PASSB1_st =>
|
245 |
|
|
|
246 |
|
|
HDLCen1 <= '1';
|
247 |
|
|
HDLCen2 <= '0';
|
248 |
|
|
HDLCen3 <= '0';
|
249 |
|
|
|
250 |
|
|
counter_Rx_i <= counter_Rx_reg + 1;
|
251 |
|
|
|
252 |
|
|
F0od_n_i <= '1';
|
253 |
|
|
|
254 |
|
|
if (counter_Rx_reg = "111" ) then
|
255 |
|
|
n_state <= PASSB2_st;
|
256 |
|
|
else
|
257 |
|
|
n_state <= PASSB1_st;
|
258 |
|
|
end if;
|
259 |
|
|
|
260 |
|
|
when PASSB2_st =>
|
261 |
|
|
HDLCen1 <= '0';
|
262 |
|
|
HDLCen2 <= '1';
|
263 |
|
|
HDLCen3 <= '0';
|
264 |
|
|
counter_Rx_i <= counter_Rx_reg + 1;
|
265 |
|
|
F0od_n_i <= '1';
|
266 |
|
|
|
267 |
|
|
if (counter_Rx_reg = "111" ) then
|
268 |
|
|
n_state <= PASSD_st;
|
269 |
|
|
else
|
270 |
|
|
n_state <= PASSB2_st;
|
271 |
|
|
end if;
|
272 |
|
|
|
273 |
|
|
when PASSD_st =>
|
274 |
|
|
HDLCen1 <= '0';
|
275 |
|
|
HDLCen2 <= '0';
|
276 |
|
|
HDLCen3 <= '1';
|
277 |
|
|
counter_Rx_i <= counter_Rx_reg + 1;
|
278 |
|
|
|
279 |
|
|
if (counter_Rx_reg = "001" ) then
|
280 |
|
|
n_state <= IDLE_st;
|
281 |
|
|
F0od_n_i <= '0';
|
282 |
|
|
else
|
283 |
|
|
n_state <= PASSD_st;
|
284 |
|
|
F0od_n_i <= '1';
|
285 |
|
|
end if;
|
286 |
|
|
|
287 |
|
|
end case;
|
288 |
|
|
end process comb;
|
289 |
|
|
|
290 |
|
|
-------------------------------------------------------------------------------
|
291 |
|
|
end isdn_cont_rtl;
|