Line 1... |
Line 1... |
-- $Id: serport_uart_autobaud.vhd 314 2010-07-09 17:38:41Z mueller $
|
-- $Id: serport_uart_autobaud.vhd 417 2011-10-22 10:30:29Z mueller $
|
--
|
--
|
-- Copyright 2007-2010 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
--
|
--
|
-- This program is free software; you may redistribute and/or modify it under
|
-- This program is free software; you may redistribute and/or modify it under
|
-- the terms of the GNU General Public License as published by the Free
|
-- the terms of the GNU General Public License as published by the Free
|
-- Software Foundation, either version 2, or at your option any later version.
|
-- Software Foundation, either version 2, or at your option any later version.
|
--
|
--
|
Line 16... |
Line 16... |
-- Description: serial port UART - autobauder
|
-- Description: serial port UART - autobauder
|
--
|
--
|
-- Dependencies: -
|
-- Dependencies: -
|
-- Test bench: tb/tb_serport_autobaud
|
-- Test bench: tb/tb_serport_autobaud
|
-- Target Devices: generic
|
-- Target Devices: generic
|
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2, 11.4; ghdl 0.18-0.26
|
-- Tool versions: xst 8.2, 9.1, 9.2, 11.4, 13.1; ghdl 0.18-0.29
|
-- Revision History:
|
-- Revision History:
|
-- Date Rev Version Comment
|
-- Date Rev Version Comment
|
|
-- 2011-10-22 417 1.0.4 now numeric_std clean
|
-- 2010-04-18 279 1.0.3 change ccnt start value to -3, better rounding
|
-- 2010-04-18 279 1.0.3 change ccnt start value to -3, better rounding
|
-- 2007-10-14 89 1.0.2 all instantiation with CDINIT=0
|
-- 2007-10-14 89 1.0.2 all instantiation with CDINIT=0
|
-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned
|
-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned
|
-- 2007-06-30 62 1.0 Initial version
|
-- 2007-06-30 62 1.0 Initial version
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_arith.all;
|
use ieee.numeric_std.all;
|
|
|
use work.slvtypes.all;
|
use work.slvtypes.all;
|
|
|
entity serport_uart_autobaud is -- serial port uart: autobauder
|
entity serport_uart_autobaud is -- serial port uart: autobauder
|
generic (
|
generic (
|
Line 73... |
Line 74... |
-- gives the best rounded estimate of CLKDIV.
|
-- gives the best rounded estimate of CLKDIV.
|
-- - therefore ccnt is inititialized with 111111.101: 101 + 111 -> 1100
|
-- - therefore ccnt is inititialized with 111111.101: 101 + 111 -> 1100
|
-- --> ccntinit = -3
|
-- --> ccntinit = -3
|
|
|
constant ccntinit : slv(CDWIDTH-1+3 downto 0) :=
|
constant ccntinit : slv(CDWIDTH-1+3 downto 0) :=
|
conv_std_logic_vector(2**(CDWIDTH+3)-3, CDWIDTH+3);
|
slv(to_unsigned(2**(CDWIDTH+3)-3, CDWIDTH+3));
|
constant mcntzero : slv7 := (others=>'0');
|
constant mcntzero : slv7 := (others=>'0');
|
constant mcntlast : slv7 := (others=>'1');
|
constant mcntlast : slv7 := (others=>'1');
|
constant regs_init : regs_type := (
|
constant regs_init : regs_type := (
|
conv_std_logic_vector(CDINIT,CDWIDTH)&"000",
|
slv(to_unsigned(CDINIT,CDWIDTH))&"000",
|
(others=>'0'),
|
(others=>'0'),
|
'0',
|
'0',
|
s_idle
|
s_idle
|
);
|
);
|
|
|
Line 95... |
Line 96... |
severity FAILURE;
|
severity FAILURE;
|
|
|
proc_regs: process (CLK)
|
proc_regs: process (CLK)
|
begin
|
begin
|
|
|
if CLK'event and CLK='1' then
|
if rising_edge(CLK) then
|
if RESET = '1' then
|
if RESET = '1' then
|
R_REGS <= regs_init;
|
R_REGS <= regs_init;
|
else
|
else
|
R_REGS <= N_REGS;
|
R_REGS <= N_REGS;
|
end if;
|
end if;
|
Line 126... |
Line 127... |
case r.state is
|
case r.state is
|
when s_idle => -- s_idle: idle, detect break --------
|
when s_idle => -- s_idle: idle, detect break --------
|
iact := '0';
|
iact := '0';
|
if CE_MSEC = '1' then -- if end of msec
|
if CE_MSEC = '1' then -- if end of msec
|
if r.seen1 = '0' then -- if no '1' seen on RXD
|
if r.seen1 = '0' then -- if no '1' seen on RXD
|
n.mcnt := unsigned(r.mcnt) + 1; -- up break timer counter
|
n.mcnt := slv(unsigned(r.mcnt) + 1); -- up break timer counter
|
if r.mcnt = mcntlast then -- after 127 msec
|
if r.mcnt = mcntlast then -- after 127 msec
|
n.state := s_break; -- break detected !
|
n.state := s_break; -- break detected !
|
end if;
|
end if;
|
else -- otherwise if '1' seen
|
else -- otherwise if '1' seen
|
n.mcnt := mcntzero; -- clear break timer again
|
n.mcnt := mcntzero; -- clear break timer again
|
Line 154... |
Line 155... |
when s_sync => -- s_sync: wait for end of '0' bits --
|
when s_sync => -- s_sync: wait for end of '0' bits --
|
if RXSD = '1' then -- if end of '0' bits seen
|
if RXSD = '1' then -- if end of '0' bits seen
|
n.state := s_idle; -- to s_idle, autobauding done
|
n.state := s_idle; -- to s_idle, autobauding done
|
idone := '1'; -- emit done pulse
|
idone := '1'; -- emit done pulse
|
else -- otherwise still in '0' of sync
|
else -- otherwise still in '0' of sync
|
n.ccnt := unsigned(n.ccnt) + 1; -- increment ccnt
|
n.ccnt := slv(unsigned(n.ccnt) + 1); -- increment ccnt
|
end if;
|
end if;
|
|
|
when others => null; -- -----------------------------------
|
when others => null; -- -----------------------------------
|
end case;
|
end case;
|
|
|