-- $Id: serport_uart_tx.vhd 417 2011-10-22 10:30:29Z mueller $
|
-- $Id: serport_uart_tx.vhd 417 2011-10-22 10:30:29Z mueller $
|
--
|
--
|
-- Copyright 2007-2011 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.
|
--
|
--
|
-- This program is distributed in the hope that it will be useful, but
|
-- This program is distributed in the hope that it will be useful, but
|
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
-- for complete details.
|
-- for complete details.
|
--
|
--
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- Module Name: serport_uart_tx - syn
|
-- Module Name: serport_uart_tx - syn
|
-- Description: serial port UART - transmitter
|
-- Description: serial port UART - transmitter
|
--
|
--
|
-- Dependencies: -
|
-- Dependencies: -
|
-- Test bench: tb/tb_serport_uart_rxtx
|
-- Test bench: tb/tb_serport_uart_rxtx
|
-- Target Devices: generic
|
-- Target Devices: generic
|
-- Tool versions: xst 8.2, 9.1, 9.2, 13.1; ghdl 0.18-0.29
|
-- Tool versions: xst 8.2, 9.1, 9.2, 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
|
-- 2011-10-22 417 1.0.4 now numeric_std clean
|
-- 2007-10-21 91 1.0.3 use 1 stop bits (redesigned _rx allows this)
|
-- 2007-10-21 91 1.0.3 use 1 stop bits (redesigned _rx allows this)
|
-- 2007-10-19 90 1.0.2 use 2 stop bits (allow CLKDIV=0 operation in sim)
|
-- 2007-10-19 90 1.0.2 use 2 stop bits (allow CLKDIV=0 operation in sim)
|
-- 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.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
use work.slvtypes.all;
|
use work.slvtypes.all;
|
|
|
entity serport_uart_tx is -- serial port uart: transmit part
|
entity serport_uart_tx is -- serial port uart: transmit part
|
generic (
|
generic (
|
CDWIDTH : positive := 13); -- clk divider width
|
CDWIDTH : positive := 13); -- clk divider width
|
port (
|
port (
|
CLK : in slbit; -- clock
|
CLK : in slbit; -- clock
|
RESET : in slbit; -- reset
|
RESET : in slbit; -- reset
|
CLKDIV : in slv(CDWIDTH-1 downto 0); -- clock divider setting
|
CLKDIV : in slv(CDWIDTH-1 downto 0); -- clock divider setting
|
TXSD : out slbit; -- transmit serial data (uart view)
|
TXSD : out slbit; -- transmit serial data (uart view)
|
TXDATA : in slv8; -- transmit data in
|
TXDATA : in slv8; -- transmit data in
|
TXENA : in slbit; -- transmit data enable
|
TXENA : in slbit; -- transmit data enable
|
TXBUSY : out slbit -- transmit busy
|
TXBUSY : out slbit -- transmit busy
|
);
|
);
|
end serport_uart_tx;
|
end serport_uart_tx;
|
|
|
|
|
architecture syn of serport_uart_tx is
|
architecture syn of serport_uart_tx is
|
|
|
type regs_type is record
|
type regs_type is record
|
ccnt : slv(CDWIDTH-1 downto 0); -- clock divider counter
|
ccnt : slv(CDWIDTH-1 downto 0); -- clock divider counter
|
bcnt : slv4; -- bit counter
|
bcnt : slv4; -- bit counter
|
sreg : slv9; -- output shift register
|
sreg : slv9; -- output shift register
|
busy : slbit;
|
busy : slbit;
|
end record regs_type;
|
end record regs_type;
|
|
|
constant cntzero : slv(CDWIDTH-1 downto 0) := (others=>'0');
|
constant cntzero : slv(CDWIDTH-1 downto 0) := (others=>'0');
|
constant regs_init : regs_type := (
|
constant regs_init : regs_type := (
|
cntzero,
|
cntzero,
|
(others=>'0'),
|
(others=>'0'),
|
(others=>'1'), -- sreg to all 1 !!
|
(others=>'1'), -- sreg to all 1 !!
|
'0'
|
'0'
|
);
|
);
|
|
|
signal R_REGS : regs_type := regs_init; -- state registers
|
signal R_REGS : regs_type := regs_init; -- state registers
|
signal N_REGS : regs_type := regs_init; -- next value state regs
|
signal N_REGS : regs_type := regs_init; -- next value state regs
|
|
|
begin
|
begin
|
|
|
proc_regs: process (CLK)
|
proc_regs: process (CLK)
|
begin
|
begin
|
|
|
if rising_edge(CLK) then
|
if rising_edge(CLK) then
|
R_REGS <= N_REGS;
|
R_REGS <= N_REGS;
|
end if;
|
end if;
|
|
|
end process proc_regs;
|
end process proc_regs;
|
|
|
proc_next: process (R_REGS, RESET, CLKDIV, TXDATA, TXENA)
|
proc_next: process (R_REGS, RESET, CLKDIV, TXDATA, TXENA)
|
|
|
variable r : regs_type := regs_init;
|
variable r : regs_type := regs_init;
|
variable n : regs_type := regs_init;
|
variable n : regs_type := regs_init;
|
variable ld_ccnt : slbit := '0';
|
variable ld_ccnt : slbit := '0';
|
|
|
begin
|
begin
|
|
|
r := R_REGS;
|
r := R_REGS;
|
n := R_REGS;
|
n := R_REGS;
|
ld_ccnt := '0';
|
ld_ccnt := '0';
|
|
|
if r.busy = '0' then
|
if r.busy = '0' then
|
ld_ccnt := '1';
|
ld_ccnt := '1';
|
n.bcnt := (others=>'0');
|
n.bcnt := (others=>'0');
|
if TXENA = '1' then
|
if TXENA = '1' then
|
n.sreg := TXDATA & '0'; -- add start (0) bit
|
n.sreg := TXDATA & '0'; -- add start (0) bit
|
n.busy := '1';
|
n.busy := '1';
|
end if;
|
end if;
|
|
|
else
|
else
|
|
|
if unsigned(r.ccnt) = 0 then
|
if unsigned(r.ccnt) = 0 then
|
ld_ccnt := '1';
|
ld_ccnt := '1';
|
n.sreg := '1' & r.sreg(8 downto 1);
|
n.sreg := '1' & r.sreg(8 downto 1);
|
n.bcnt := slv(unsigned(r.bcnt) + 1);
|
n.bcnt := slv(unsigned(r.bcnt) + 1);
|
if unsigned(r.bcnt) = 9 then -- if 10 bits send
|
if unsigned(r.bcnt) = 9 then -- if 10 bits send
|
n.busy := '0'; -- declare all done
|
n.busy := '0'; -- declare all done
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if RESET = '1' then
|
if RESET = '1' then
|
ld_ccnt := '1';
|
ld_ccnt := '1';
|
n.busy := '0';
|
n.busy := '0';
|
end if;
|
end if;
|
|
|
if ld_ccnt = '1' then
|
if ld_ccnt = '1' then
|
n.ccnt := CLKDIV;
|
n.ccnt := CLKDIV;
|
else
|
else
|
n.ccnt := slv(unsigned(r.ccnt) - 1);
|
n.ccnt := slv(unsigned(r.ccnt) - 1);
|
end if;
|
end if;
|
|
|
N_REGS <= n;
|
N_REGS <= n;
|
|
|
TXBUSY <= r.busy;
|
TXBUSY <= r.busy;
|
TXSD <= r.sreg(0);
|
TXSD <= r.sreg(0);
|
|
|
end process proc_next;
|
end process proc_next;
|
|
|
end syn;
|
end syn;
|
|
|