1 |
192 |
jshamlet |
-- Copyright (c)2020 Jeremy Seth Henry
|
2 |
|
|
-- All rights reserved.
|
3 |
|
|
--
|
4 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
5 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
6 |
|
|
-- * Redistributions of source code must retain the above copyright
|
7 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
8 |
|
|
-- * Redistributions in binary form must reproduce the above copyright
|
9 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
10 |
|
|
-- documentation and/or other materials provided with the distribution,
|
11 |
|
|
-- where applicable (as part of a user interface, debugging port, etc.)
|
12 |
|
|
--
|
13 |
|
|
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
|
14 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
|
17 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 |
|
|
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 |
|
|
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 |
|
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 |
|
|
--
|
24 |
|
|
-- VHDL Units : o8_sdlc_if
|
25 |
|
|
-- Description: Provides a full memory-mapped SDLC stack with automatic CRC16
|
26 |
|
|
-- Checksum insertion and integrity checking.
|
27 |
|
|
--
|
28 |
|
|
-- Transmit Memory Map
|
29 |
|
|
-- "0_0000_0000" (0x000) TX Buffer START
|
30 |
|
|
-- "0_1111_1101" (0x0FD) TX Buffer END
|
31 |
|
|
-- "0_1111_1110" (0x0FE) Clock Status*
|
32 |
|
|
-- "0_1111_1111" (0x0FF) TX Length / Status**
|
33 |
|
|
--
|
34 |
|
|
-- Receive Memory Map
|
35 |
|
|
-- "1_0000_0000" (0x100) RX Buffer START
|
36 |
196 |
jshamlet |
-- "1_1111_1101" (0x1FD) RX Buffer END
|
37 |
|
|
-- "1_1111_1110" (0x0FE) Reserved
|
38 |
|
|
-- "1_1111_1111" (0x1FF) RX Length / Status***
|
39 |
192 |
jshamlet |
--
|
40 |
196 |
jshamlet |
-- * Address 0xFE reports the SDLC bit clock status and updates on changes.
|
41 |
|
|
-- 1) If BClk_Okay = '0' (Bitclock is NOT present), the field will report
|
42 |
|
|
-- 0x00. Otherwise, it will report 0xFF if the bitclock is present.
|
43 |
|
|
-- 2) Writing any value to the register will cause the controller to
|
44 |
|
|
-- silently reset the clock status without causing an interrupt.
|
45 |
|
|
--
|
46 |
|
|
-- ** This location serves as the control/status register for transmit
|
47 |
|
|
-- 1) Writing a value between 1 and 253 will trigger the transmit engine,
|
48 |
|
|
-- using the write value as the packet length.
|
49 |
|
|
-- 2) Values 0x00, 0xFE, or 0xFF are invalid, and will be ignored.
|
50 |
|
|
-- 3) This value will change from the user written value to 0xFF once the
|
51 |
|
|
-- packet is transmitted to indicate the transmission is complete.
|
52 |
|
|
--
|
53 |
|
|
-- *** This location serves as the status register for the receive
|
54 |
|
|
-- 1) This value is only updated on reception of a full frame, indicated
|
55 |
|
|
-- by a start followed by a stop flag. Incomplete frames are ignored.
|
56 |
|
|
-- 2) If the packet CRC matches the transmitted CRC, the packet is
|
57 |
|
|
-- considered valid, and the received length (less CRC) is written.
|
58 |
|
|
-- 3) If the packet CRC doesn't match, a value of ERR_CHECKSUM is written.
|
59 |
|
|
-- 4) If too many bytes are received (buffer overflow), a value of
|
60 |
|
|
-- ERR_LENGTH is written.
|
61 |
192 |
jshamlet |
|
62 |
|
|
library ieee;
|
63 |
|
|
use ieee.std_logic_1164.all;
|
64 |
|
|
use ieee.std_logic_unsigned.all;
|
65 |
|
|
use ieee.std_logic_arith.all;
|
66 |
|
|
|
67 |
|
|
library work;
|
68 |
|
|
use work.open8_pkg.all;
|
69 |
|
|
|
70 |
|
|
library work;
|
71 |
|
|
use work.sdlc_serial_pkg.all;
|
72 |
|
|
|
73 |
|
|
entity o8_sdlc_if is
|
74 |
|
|
generic(
|
75 |
|
|
Poly_Init : std_logic_vector(15 downto 0) := x"0000";
|
76 |
|
|
Set_As_Master : boolean := true;
|
77 |
|
|
Clock_Offset : integer := 6;
|
78 |
|
|
BitClock_Freq : real := 500000.0;
|
79 |
|
|
Sys_Freq : real := 100000000.0;
|
80 |
|
|
Reset_Level : std_logic := '1';
|
81 |
|
|
Address : ADDRESS_TYPE
|
82 |
|
|
);
|
83 |
|
|
port(
|
84 |
|
|
Clock : in std_logic;
|
85 |
|
|
Reset : in std_logic;
|
86 |
|
|
--
|
87 |
|
|
Bus_Address : in ADDRESS_TYPE;
|
88 |
|
|
Wr_Enable : in std_logic;
|
89 |
|
|
Wr_Data : in DATA_TYPE;
|
90 |
|
|
Rd_Enable : in std_logic;
|
91 |
|
|
Rd_Data : out DATA_TYPE;
|
92 |
|
|
Interrupt : out std_logic;
|
93 |
|
|
-- Serial IO
|
94 |
|
|
SDLC_In : in std_logic;
|
95 |
|
|
SDLC_SClk : in std_logic;
|
96 |
|
|
SDLC_MClk : out std_logic;
|
97 |
|
|
SDLC_Out : out std_logic
|
98 |
|
|
);
|
99 |
|
|
end entity;
|
100 |
|
|
|
101 |
|
|
architecture behave of o8_sdlc_if is
|
102 |
|
|
|
103 |
|
|
-- Connect the CPU to the dual-port memory
|
104 |
|
|
constant Base_Addr : std_logic_vector(15 downto 9)
|
105 |
|
|
:= Address(15 downto 9);
|
106 |
|
|
|
107 |
|
|
alias RAM_Upper_Addr is Bus_Address(15 downto 9);
|
108 |
|
|
alias RAM_Lower_Addr is Bus_Address(8 downto 0);
|
109 |
|
|
|
110 |
|
|
signal RAM_Addr_Match : std_logic := '0';
|
111 |
|
|
signal RAM_Wr_En : std_logic := '0';
|
112 |
|
|
signal RAM_Rd_En : std_logic := '0';
|
113 |
|
|
signal Rd_Data_i : DATA_TYPE := OPEN8_NULLBUS;
|
114 |
|
|
|
115 |
196 |
jshamlet |
constant Reg_Sub_Addr : std_logic_vector(8 downto 1) := x"7F";
|
116 |
192 |
jshamlet |
|
117 |
196 |
jshamlet |
alias Reg_Upper_Addr is Bus_Address(8 downto 1);
|
118 |
|
|
alias Reg_Lower_Addr is Bus_Address(0);
|
119 |
|
|
|
120 |
|
|
signal Reg_Addr : std_logic_vector(8 downto 1) := (others => '0');
|
121 |
|
|
signal Reg_Sel : std_logic := '0';
|
122 |
192 |
jshamlet |
signal Reg_Wr_En : std_logic := '0';
|
123 |
196 |
jshamlet |
signal Reg_Clk_Sel : std_logic := '0';
|
124 |
|
|
signal Reg_TxS_Sel : std_logic := '0';
|
125 |
|
|
|
126 |
192 |
jshamlet |
-- Connect the serial engine to the dual-port memory
|
127 |
|
|
signal DP_Addr : std_logic_vector(8 downto 0) := (others => '0');
|
128 |
|
|
signal DP_Wr_Data : DATA_IN_TYPE := x"00";
|
129 |
|
|
signal DP_Wr_En : std_logic := '0';
|
130 |
|
|
signal DP_Rd_Data : DATA_IN_TYPE := x"00";
|
131 |
|
|
|
132 |
|
|
signal BClk_RE : std_logic := '0';
|
133 |
|
|
signal BClk_FE : std_logic := '0';
|
134 |
|
|
|
135 |
|
|
signal TX_Wr_En : std_logic := '0';
|
136 |
|
|
signal TX_Wr_Flag : std_logic := '0';
|
137 |
|
|
signal TX_Wr_Data : DATA_IN_TYPE := x"00";
|
138 |
|
|
signal TX_Req_Next : std_logic := '0';
|
139 |
|
|
|
140 |
|
|
signal TX_CRC_Clr : std_logic := '0';
|
141 |
|
|
signal TX_CRC_En : std_logic := '0';
|
142 |
|
|
signal TX_CRC_Data : CRC_OUT_TYPE := x"0000";
|
143 |
|
|
alias TX_CRC_Data_LB is TX_CRC_Data(7 downto 0);
|
144 |
|
|
alias TX_CRC_Data_UB is TX_CRC_Data(15 downto 8);
|
145 |
|
|
signal TX_CRC_Valid : std_logic := '0';
|
146 |
|
|
|
147 |
|
|
signal RX_Valid : std_logic := '0';
|
148 |
|
|
signal RX_Flag : std_logic := '0';
|
149 |
|
|
signal RX_Data : DATA_IN_TYPE := x"00";
|
150 |
|
|
signal RX_Idle : std_logic := '0';
|
151 |
|
|
|
152 |
|
|
signal RX_CRC_Clr : std_logic := '0';
|
153 |
|
|
signal RX_CRC_En : std_logic := '0';
|
154 |
|
|
signal RX_CRC_Data : CRC_OUT_TYPE := x"0000";
|
155 |
|
|
signal RX_CRC_Valid : std_logic := '0';
|
156 |
|
|
|
157 |
|
|
signal BClk_Okay : std_logic := '0';
|
158 |
|
|
|
159 |
|
|
begin
|
160 |
|
|
|
161 |
|
|
-- This decode needs to happen immediately, to give the RAM a chance to
|
162 |
|
|
-- do the lookup before we have to set Rd_Data
|
163 |
|
|
RAM_Addr_Match <= '1' when Base_Addr = RAM_Upper_Addr else '0';
|
164 |
|
|
RAM_Wr_En <= RAM_Addr_Match and Wr_Enable;
|
165 |
|
|
|
166 |
|
|
CPU_RAM_proc: process( Reset, Clock )
|
167 |
|
|
begin
|
168 |
|
|
if( Reset = Reset_Level )then
|
169 |
|
|
Reg_Addr <= (others => '0');
|
170 |
|
|
Reg_Wr_En <= '0';
|
171 |
196 |
jshamlet |
Reg_Clk_Sel <= '0';
|
172 |
|
|
Reg_TxS_Sel <= '0';
|
173 |
192 |
jshamlet |
RAM_Rd_En <= '0';
|
174 |
|
|
Rd_Data <= OPEN8_NULLBUS;
|
175 |
|
|
elsif( rising_edge(Clock) )then
|
176 |
196 |
jshamlet |
Reg_Addr <= Reg_Upper_Addr;
|
177 |
|
|
Reg_Sel <= Reg_Lower_Addr;
|
178 |
192 |
jshamlet |
Reg_Wr_En <= RAM_Addr_Match and Wr_Enable;
|
179 |
|
|
|
180 |
196 |
jshamlet |
Reg_Clk_Sel <= '0';
|
181 |
|
|
Reg_TxS_Sel <= '0';
|
182 |
192 |
jshamlet |
if( Reg_Addr = Reg_Sub_Addr )then
|
183 |
196 |
jshamlet |
Reg_Clk_Sel <= Reg_Wr_En and not Reg_Sel;
|
184 |
|
|
Reg_TxS_Sel <= Reg_Wr_En and Reg_Sel;
|
185 |
192 |
jshamlet |
end if;
|
186 |
|
|
|
187 |
|
|
RAM_Rd_En <= RAM_Addr_Match and Rd_Enable;
|
188 |
|
|
Rd_Data <= OPEN8_NULLBUS;
|
189 |
|
|
if( RAM_Rd_En = '1' )then
|
190 |
|
|
Rd_Data <= Rd_Data_i;
|
191 |
|
|
end if;
|
192 |
|
|
end if;
|
193 |
|
|
end process;
|
194 |
|
|
|
195 |
|
|
U_RAM : entity work.ram_dp512b_core
|
196 |
|
|
port map(
|
197 |
|
|
clock => Clock,
|
198 |
|
|
address_a => RAM_Lower_Addr,
|
199 |
|
|
address_b => DP_Addr,
|
200 |
|
|
data_a => Wr_Data,
|
201 |
|
|
data_b => DP_Wr_Data,
|
202 |
|
|
wren_a => RAM_Wr_En,
|
203 |
|
|
wren_b => DP_Wr_En,
|
204 |
|
|
q_a => Rd_Data_i,
|
205 |
|
|
q_b => DP_Rd_Data
|
206 |
|
|
);
|
207 |
|
|
|
208 |
|
|
U_BCLK : entity work.sdlc_serial_clk
|
209 |
|
|
generic map(
|
210 |
|
|
Set_As_Master => Set_As_Master,
|
211 |
|
|
BitClock_Freq => BitClock_Freq,
|
212 |
|
|
Reset_Level => Reset_Level,
|
213 |
|
|
Sys_Freq => Sys_Freq
|
214 |
|
|
)
|
215 |
|
|
port map(
|
216 |
|
|
Clock => Clock,
|
217 |
|
|
Reset => Reset,
|
218 |
|
|
--
|
219 |
|
|
BClk_In => SDLC_SClk,
|
220 |
|
|
BClk_Out => SDLC_MClk,
|
221 |
|
|
BClk_FE => BClk_FE,
|
222 |
|
|
BClk_RE => BClk_RE,
|
223 |
|
|
BClk_Okay => BClk_Okay
|
224 |
|
|
);
|
225 |
|
|
|
226 |
|
|
U_CTRL : entity work.sdlc_serial_ctrl
|
227 |
|
|
generic map(
|
228 |
|
|
Reset_Level => Reset_Level
|
229 |
|
|
)
|
230 |
|
|
port map(
|
231 |
|
|
Clock => Clock,
|
232 |
|
|
Reset => Reset,
|
233 |
|
|
--
|
234 |
|
|
BClk_Okay => BClk_Okay,
|
235 |
|
|
--
|
236 |
196 |
jshamlet |
Reg_Clk_Sel => Reg_Clk_Sel,
|
237 |
|
|
Reg_TxS_Sel => Reg_TxS_Sel,
|
238 |
192 |
jshamlet |
--
|
239 |
|
|
DP_Addr => DP_Addr,
|
240 |
|
|
DP_Wr_Data => DP_Wr_Data,
|
241 |
|
|
DP_Wr_En => DP_Wr_En,
|
242 |
|
|
DP_Rd_Data => DP_Rd_Data,
|
243 |
|
|
--
|
244 |
|
|
TX_Wr_En => TX_Wr_En,
|
245 |
|
|
TX_Wr_Flag => TX_Wr_Flag,
|
246 |
|
|
TX_Wr_Data => TX_Wr_Data,
|
247 |
|
|
TX_Req_Next => TX_Req_Next,
|
248 |
|
|
--
|
249 |
|
|
TX_CRC_Clr => TX_CRC_Clr,
|
250 |
|
|
TX_CRC_En => TX_CRC_En,
|
251 |
|
|
TX_CRC_Data => TX_CRC_Data,
|
252 |
|
|
TX_CRC_Valid => TX_CRC_Valid,
|
253 |
|
|
--
|
254 |
|
|
RX_Valid => RX_Valid,
|
255 |
|
|
RX_Flag => RX_Flag,
|
256 |
|
|
RX_Data => RX_Data,
|
257 |
|
|
RX_Idle => RX_Idle,
|
258 |
|
|
--
|
259 |
|
|
RX_CRC_Clr => RX_CRC_Clr,
|
260 |
|
|
RX_CRC_En => RX_CRC_En,
|
261 |
|
|
RX_CRC_Data => RX_CRC_Data,
|
262 |
|
|
RX_CRC_Valid => RX_CRC_Valid,
|
263 |
|
|
--
|
264 |
|
|
Interrupt => Interrupt
|
265 |
|
|
);
|
266 |
|
|
|
267 |
|
|
U_TX_SER : entity work.sdlc_serial_tx
|
268 |
|
|
generic map(
|
269 |
|
|
Reset_Level => Reset_Level
|
270 |
|
|
)
|
271 |
|
|
port map(
|
272 |
|
|
Clock => Clock,
|
273 |
|
|
Reset => Reset,
|
274 |
|
|
--
|
275 |
|
|
BClk_FE => BClk_FE,
|
276 |
|
|
BClk_RE => BClk_RE,
|
277 |
|
|
BClk_Okay => BClk_Okay,
|
278 |
|
|
--
|
279 |
|
|
TX_En => TX_Wr_En,
|
280 |
|
|
TX_FSS_Flag => TX_Wr_Flag,
|
281 |
|
|
TX_Data => TX_Wr_Data,
|
282 |
|
|
TX_Req_Next => TX_Req_Next,
|
283 |
|
|
--
|
284 |
|
|
Serial_Out => SDLC_Out
|
285 |
|
|
);
|
286 |
|
|
|
287 |
|
|
U_TX_CRC : entity work.sdlc_crc16_ccitt
|
288 |
|
|
generic map(
|
289 |
|
|
Poly_Init => Poly_Init,
|
290 |
|
|
Reset_Level => Reset_Level
|
291 |
|
|
)
|
292 |
|
|
port map(
|
293 |
|
|
Clock => Clock,
|
294 |
|
|
Reset => Reset,
|
295 |
|
|
--
|
296 |
|
|
Clear => TX_CRC_Clr,
|
297 |
|
|
Wr_Data => TX_Wr_Data,
|
298 |
|
|
Wr_En => TX_CRC_En,
|
299 |
|
|
--
|
300 |
|
|
CRC16_Out => TX_CRC_Data,
|
301 |
|
|
CRC16_Valid => TX_CRC_Valid
|
302 |
|
|
);
|
303 |
|
|
|
304 |
|
|
U_RX_SER : entity work.sdlc_serial_rx
|
305 |
|
|
generic map(
|
306 |
|
|
Set_As_Master => Set_As_Master,
|
307 |
|
|
Clock_Offset => Clock_Offset,
|
308 |
|
|
Reset_Level => Reset_Level
|
309 |
|
|
)
|
310 |
|
|
port map(
|
311 |
|
|
Clock => Clock,
|
312 |
|
|
Reset => Reset,
|
313 |
|
|
--
|
314 |
|
|
BClk_RE => BClk_RE,
|
315 |
|
|
BClk_Okay => BClk_Okay,
|
316 |
|
|
--
|
317 |
|
|
Serial_In => SDLC_In,
|
318 |
|
|
--
|
319 |
|
|
RX_Valid => RX_Valid,
|
320 |
|
|
RX_Flag => RX_Flag,
|
321 |
|
|
RX_Data => RX_Data,
|
322 |
|
|
RX_Idle => RX_Idle
|
323 |
|
|
);
|
324 |
|
|
|
325 |
|
|
U_RX_CRC : entity work.sdlc_crc16_ccitt
|
326 |
|
|
generic map(
|
327 |
|
|
Poly_Init => Poly_Init,
|
328 |
|
|
Reset_Level => Reset_Level
|
329 |
|
|
)
|
330 |
|
|
port map(
|
331 |
|
|
Clock => Clock,
|
332 |
|
|
Reset => Reset,
|
333 |
|
|
--
|
334 |
|
|
Clear => RX_CRC_Clr,
|
335 |
|
|
Wr_Data => RX_Data,
|
336 |
|
|
Wr_En => RX_CRC_En,
|
337 |
|
|
--
|
338 |
|
|
CRC16_Out => RX_CRC_Data,
|
339 |
|
|
CRC16_Valid => RX_CRC_Valid
|
340 |
|
|
);
|
341 |
|
|
|
342 |
|
|
end architecture;
|