Home    --    Hierarchy    --    Packages    --    Entities    --    Instantiations    --    Sources

Source file VHDL/ACIA_RX.vhd

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 
 41 
 42 
 43 
 44 
 45 
 46 
 47 
 48 
 49 
 50 
 51 
 52 
 53 
 54 
 55 
 56 
 57 
 58 
 59 
 60 
 61 
 62 
 63 
 64 
 65 
 66 
 67 
 68 
 69 
 70 
 71 
 72 
 73 
 74 
 75 
 76 
 77 
 78 
 79 
 80 
 81 
 82 
 83 
 84 
 85 
 86 
 87 
 88 
 89 
 90 
 91 
 92 
 93 
 94 
 95 
 96 
 97 
 98 
 99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312 
313 
314 
315 
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 
--===========================================================================--
--
-- S Y N T H E Z I A B L E ACIA 6850 C O R E
--
-- www.OpenCores.Org - January 2007
-- This core adheres to the GNU public license
--
-- Design units : 6850 ACIA core for the System68/09
--
-- File name : ACIA_RX.vhd
--
-- Purpose : Implements a 6850 ACIA device for communication purposes
-- between the cpu68/09 cpu and the Host computer through
-- an RS-232 communication protocol.
--
-- Dependencies : ieee.std_logic_1164.all;
-- ieee.numeric_std.all;
-- ieee.std_logic_unsigned.all;
-- unisim.vcomponents.all;
--
--===========================================================================--
-------------------------------------------------------------------------------
-- Revision list
-- Version Author Date Changes
--
-- 0.1 Ovidiu Lupas 15 January 2000 New model
-- 2.0 Ovidiu Lupas 17 April 2000 samples counter cleared for bit 0
-- olupas at the domain opencores.org
--
-- 3.0 John Kent 5 January 2003 Added 6850 word format control
-- 3.1 John Kent 12 January 2003 Significantly revamped receive code.
-- 3.2 John Kent 10 January 2004 Rewrite of code.
-- 4.0 John Kent 3 February 2007 Renamed to ACIA 6850
-- Removed input debounce
-- 4.1 John Kent 4 February 2007 Cleaned up Rx state machine
-- 4.2 John Kent 25 February 2007 Modified sensitivity lists
--
-- dilbert57 at the domain opencores.org
-------------------------------------------------------------------------------
--
-- Description : Implements the receive unit of the ACIA_6850 core.
-- Samples 16 times the RxD line and retain the value
-- in the middle of the time interval.
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
--library unisim;
-- use unisim.vcomponents.all;
-------------------------------------------------------------------------------
-- Entity for the ACIA Receiver
-------------------------------------------------------------------------------
entity ACIA_RX is
port (
Clk : in Std_Logic; -- Clock signal
RxRst : in Std_Logic; -- Reset input
RxRd : in Std_Logic; -- Read data strobe
WdFmt : in Std_Logic_Vector(2 downto 0); -- word format
BdFmt : in Std_Logic_Vector(1 downto 0); -- baud format
RxClk : in Std_Logic; -- RS-232 clock input
RxDat : in Std_Logic; -- RS-232 data input
RxFErr : out Std_Logic; -- Framing Error status
RxOErr : out Std_Logic; -- Over Run Error Status
RxPErr : out Std_logic; -- Parity Error Status
RxRdy : out Std_Logic; -- Data Ready Status
RxDout : out Std_Logic_Vector(7 downto 0)
);
end ACIA_RX; --================== End of entity ==============================--
-------------------------------------------------------------------------------
-- Architecture for ACIA receiver
-------------------------------------------------------------------------------
architecture rtl of ACIA_RX is
type RxStateType is ( RxStart_State, RxData_state,
RxParity_state, RxStop_state );
-----------------------------------------------------------------------------
-- Signals
-----------------------------------------------------------------------------
signal RxDatDel0 : Std_Logic := '0'; -- Delayed Rx Data
signal RxDatDel1 : Std_Logic := '0'; -- Delayed Rx Data
signal RxDatDel2 : Std_Logic := '0'; -- Delayed Rx Data
signal RxDatEdge : Std_Logic := '0'; -- Rx Data Edge pulse
signal RxClkDel : Std_Logic := '0'; -- Delayed Rx Input Clock
signal RxClkEdge : Std_Logic := '0'; -- Rx Input Clock Edge pulse
signal RxStart : Std_Logic := '0'; -- Rx Start request
signal RxEnable : Std_Logic := '0'; -- Rx Enabled
signal RxClkCnt : Std_Logic_Vector(5 downto 0) := (others => '0'); -- Rx Baud Clock Counter
signal RxBdClk : Std_Logic := '0'; -- Rx Baud Clock
signal RxBdDel : Std_Logic := '0'; -- Delayed Rx Baud Clock
signal RxBdEdge : Std_Logic := '0'; -- Rx Baud Clock Edge pulse
signal RxReady : Std_Logic := '0'; -- Data Ready flag
signal RxReq : Std_Logic := '0'; -- Rx Data Valid
signal RxAck : Std_Logic := '0'; -- Rx Data Valid
signal RxParity : Std_Logic := '0'; -- Calculated RX parity bit
signal RxState : RxStateType; -- receive bit state
signal RxBitCount : Std_Logic_Vector(2 downto 0) := (others => '0'); -- Rx Bit counter
signal RxShiftReg : Std_Logic_Vector(7 downto 0) := (others => '0'); -- Shift Register
begin
---------------------------------------------------------------------
-- Receiver Clock Edge Detection
---------------------------------------------------------------------
-- A rising edge will produce a one clock cycle pulse
--
-- acia_rx_clock_edge : process( Clk, RxRst, RxClk, RxClkDel )
acia_rx_clock_edge : process( RxRst, Clk )
begin
if RxRst = '1' then
RxClkDel <= '0';
RxClkEdge <= '0';
elsif Clk'event and Clk = '0' then
RxClkDel <= RxClk;
RxClkEdge <= (not RxClkDel) and RxClk;
end if;
end process;
---------------------------------------------------------------------
-- Receiver Data Edge Detection
---------------------------------------------------------------------
-- A falling edge will produce a pulse on RxClk wide
--
-- acia_rx_data_edge : process(Clk, RxRst, RxClkEdge, RxDat, RxDatDel0, RxDatDel1, RxDatDel2 )
acia_rx_data_edge : process( RxRst, Clk )
begin
if RxRst = '1' then
RxDatDel0 <= '0';
RxDatDel1 <= '0';
RxDatDel2 <= '0';
RxDatEdge <= '0';
elsif Clk'event and Clk = '0' then
-- if RxClkEdge = '1' then
RxDatDel0 <= RxDat;
RxDatDel1 <= RxDatDel0;
RxDatDel2 <= RxDatDel1;
RxDatEdge <= RxDatDel0 and (not RxDat);
-- end if;
end if;
end process;
---------------------------------------------------------------------
-- Receiver Start / Stop
---------------------------------------------------------------------
-- Enable the receive clock on detection of a start bit
-- Disable the receive clock after a byte is received.
--
-- acia_rx_start_stop : process( Clk, RxRst, RxDatEdge, RxAck, RxStart, RxEnable )
acia_rx_start_stop : process( RxRst, Clk )
begin
if RxRst = '1' then
RxEnable <= '0';
RxStart <= '0';
elsif Clk'event and Clk='0' then
if (RxEnable = '0') and (RxDatEdge = '1') then
-- Data Edge detected
-- Request Start and Enable Receive Clock.
RxEnable <= '1';
RxStart <= '1';
else
if (RxStart = '1') and (RxAck = '1') then
-- Data is being received
-- reset start request
RxStart <= '0';
else
-- Data has now been received
-- Disable Receiver until next start bit
if (RxStart = '0') and (RxAck = '0') then
RxEnable <= '0';
end if;
end if; -- RxStart
end if; -- RxDatEdge
end if; -- clk / RxRst
end process;
---------------------------------------------------------------------
-- Receiver Clock Divider
---------------------------------------------------------------------
-- Hold the Rx Clock divider in reset when the receiver is disabled
-- Advance the count only on a rising Rx clock edge
--
-- acia_rx_clock_divide : process( Clk, RxRst, RxEnable, RxClkEdge, RxClkCnt )
acia_rx_clock_divide : process( RxRst, Clk )
begin
if RxRst = '1' then
RxClkCnt <= (others => '0');
elsif Clk'event and Clk = '0' then
-- if RxEnable = '0' then
if RxDatEdge = '1' then
RxClkCnt <= (others => '0'); -- reset on falling data edge
else
if RxClkEdge = '1' then -- increment count on Clock edge
RxClkCnt <= RxClkCnt + "000001";
end if; -- RxClkEdge
end if; -- RxState
end if; -- clk / RxRst
end process;
---------------------------------------------------------------------
-- Receiver Baud Clock Selector
---------------------------------------------------------------------
-- BdFmt
-- 0 0 - Baud Clk divide by 1
-- 0 1 - Baud Clk divide by 16
-- 1 0 - Baud Clk divide by 64
-- 1 1 - Reset
--
acia_rx_baud_clock_select : process( BdFmt, RxClk, RxClkCnt )
begin
case BdFmt is
when "00" => -- Div by 1
RxBdClk <= RxClk;
when "01" => -- Div by 16
RxBdClk <= RxClkCnt(3);
when "10" => -- Div by 64
RxBdClk <= RxClkCnt(5);
when others => -- RxRst
RxBdClk <= '0';
end case;
end process;
---------------------------------------------------------------------
-- Receiver Baud Clock Edge Detect
---------------------------------------------------------------------
--
-- Generate one clock strobe on rising baud clock edge
--
-- acia_rx_baud_clock_edge : process( Clk, RxRst, RxBdClk, RxBdDel )
acia_rx_baud_clock_edge : process( RxRst, Clk )
begin
if RxRst = '1' then
RxBdDel <= '0';
RxBdEdge <= '0';
elsif Clk'event and Clk = '0' then
RxBdDel <= RxBdClk;
RxBdEdge <= RxBdClk and (not RxBdDel);
end if;
end process;
---------------------------------------------------------------------
-- Receiver process
---------------------------------------------------------------------
-- WdFmt - Bits[4..2]
-- 0 0 0 - 7 data, even parity, 2 stop
-- 0 0 1 - 7 data, odd parity, 2 stop
-- 0 1 0 - 7 data, even parity, 1 stop
-- 0 1 1 - 7 data, odd parity, 1 stop
-- 1 0 0 - 8 data, no parity, 2 stop
-- 1 0 1 - 8 data, no parity, 1 stop
-- 1 1 0 - 8 data, even parity, 1 stop
-- 1 1 1 - 8 data, odd parity, 1 stop
-- acia_rx_receive : process( Clk, RxRst, RxState, RxBdEdge, RxDatDel2, RxBitCount, RxReady, RxShiftReg )
acia_rx_receive : process( RxRst, Clk )
begin
if RxRst = '1' then
RxFErr <= '0';
RxOErr <= '0';
RxPErr <= '0';
RxShiftReg <= (others => '0'); -- Resert Shift register
RxDOut <= (others => '0');
RxParity <= '0'; -- reset Parity bit
RxAck <= '0'; -- Receiving data
RxBitCount <= (others => '0');
RxState <= RxStart_state;
elsif Clk'event and Clk='0' then
if RxBdEdge = '1' then
case RxState is
when RxStart_state =>
RxShiftReg <= (others => '0'); -- Reset Shift register
RxParity <= '0'; -- Parity bit
if WdFmt(2) = '0' then
-- WdFmt(2) = '0' => 7 data
RxBitCount <= "110";
else
-- WdFmt(2) = '1' => 8 data
RxBitCount <= "111";
end if;
if RxDatDel2 = '0' then -- look for start request
RxState <= RxData_state; -- yes, read data
end if;
when RxData_state => -- data bits 0 to 6
RxShiftReg <= RxDatDel2 & RxShiftReg(7 downto 1);
RxParity <= RxParity xor RxDatDel2;
RxAck <= '1'; -- Flag receive in progress
RxBitCount <= RxBitCount - "001";
if RxBitCount = "000" then
if WdFmt(2) = '0' then -- WdFmt(2) = '0' => 7 data
RxState <= RxParity_state; -- 7 bits always has parity
else -- WdFmt(2) = '1' => 8 data
if WdFmt(1) = '0' then
RxState <= RxStop_state; -- WdFmt(1) = '0' no parity
else
RxState <= RxParity_state; -- WdFmt(1) = '1' parity
end if; -- WdFmt(1)
end if; -- WdFmt(2)
end if; -- RxBitCount
when RxParity_state => -- parity bit
if WdFmt(2) = '0' then -- 7 data, shift right
RxShiftReg <= RxDatDel2 & RxShiftReg(7 downto 1); -- 7 data + parity
end if;
if WdFmt(0) = '0' then -- parity polarity ?
if RxParity = RxDatDel2 then -- check even parity
RxPErr <= '1';
else
RxPErr <= '0';
end if;
else
if RxParity = RxDatDel2 then -- check for odd parity
RxPErr <= '0';
else
RxPErr <= '1';
end if;
end if;
RxState <= RxStop_state;
when RxStop_state => -- stop bit (Only one required for RX)
RxAck <= '0'; -- Flag Receive Complete
RxDOut <= RxShiftReg;
if RxDatDel2 = '1' then -- stop bit expected
RxFErr <= '0'; -- yes, no framing error
else
RxFErr <= '1'; -- no, framing error
end if;
if RxReady = '1' then -- Has previous data been read ?
RxOErr <= '1'; -- no, overrun error
else
RxOErr <= '0'; -- yes, no over run error
end if;
RxState <= RxStart_state;
when others =>
RxAck <= '0'; -- Flag Receive Complete
RxState <= RxStart_state;
end case; -- RxState
end if; -- RxBdEdge
end if; -- clk / RxRst
end process;
---------------------------------------------------------------------
-- Receiver Read process
---------------------------------------------------------------------
-- acia_rx_read : process(Clk, RxRst, RxRd, RxReq, RxAck, RxReady )
acia_rx_read : process( RxRst, Clk, RxReady )
begin
if RxRst = '1' then
RxReady <= '0';
RxReq <= '0';
elsif Clk'event and Clk='0' then
if RxRd = '1' then
-- Data was read, Reset data ready
-- Request more data
RxReady <= '0';
RxReq <= '1';
else
if RxReq = '1' and RxAck = '1' then
-- Data is being received
-- reset receive request
RxReq <= '0';
else
-- Data now received
-- Flag RxReady and read Shift Register
if RxReq = '0' and RxAck = '0' then
RxReady <= '1';
end if;
end if; -- RxReq
end if; -- RxRd
end if; -- clk / RxRst
RxRdy <= RxReady;
end process;
end rtl; --==================== End of architecture ====================--

Generated on 1 Jan 2018 19:48:42 with VHDocL V0.2.6